Class CommonHooks
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ThreadLocal
<net.minecraft.world.entity.player.Player> private static final String
private static final Map
<net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.LivingEntity>, net.minecraft.world.entity.ai.attributes.AttributeSupplier> private static final Lazy
<Map<String, net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix.Conversion>> private static final org.apache.logging.log4j.Logger
private static final String
(package private) static final Pattern
static final int
private static final org.apache.logging.log4j.Marker
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Map
<net.minecraft.world.inventory.RecipeBookType, com.mojang.datafixers.util.Pair<String, String>> buildRecipeBookTypeTagFields
(Map<net.minecraft.world.inventory.RecipeBookType, com.mojang.datafixers.util.Pair<String, String>> vanillaMap) static boolean
canContinueUsing
(net.minecraft.world.item.ItemStack from, net.minecraft.world.item.ItemStack to) static boolean
canCropGrow
(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, boolean def) Checks if a crop can grow by firingCropGrowEvent.Pre
.static boolean
canEntityDestroy
(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.LivingEntity entity) static boolean
canMobEffectBeApplied
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Checks if a mob effect can be applied to an entity by firingMobEffectEvent.Applicable
.static boolean
canUseEntitySelectors
(net.minecraft.commands.SharedSuggestionProvider provider) static net.minecraft.world.item.component.ItemAttributeModifiers
computeModifiedAttributes
(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.component.ItemAttributeModifiers defaultModifiers) Hook to fireItemAttributeModifierEvent
.static net.minecraft.world.item.context.UseOnContext
dispenseUseOnContext
(net.minecraft.core.dispenser.BlockSource source, net.minecraft.world.item.ItemStack stack) Creates aUseOnContext
fordispense behavior
.static String
encodeLifecycle
(com.mojang.serialization.Lifecycle lifecycle) static net.minecraft.core.HolderLookup.Provider
extractLookupProvider
(net.minecraft.resources.RegistryOps<?> ops) Extracts aHolderLookup.Provider
from the givenops
, if possible.static BlockEvent.BreakEvent
fireBlockBreak
(net.minecraft.world.level.Level level, net.minecraft.world.level.GameType gameType, net.minecraft.server.level.ServerPlayer player, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) FiresBlockEvent.BreakEvent
, pre-emptively canceling the event based on the conditions that will cause the block to not be broken anyway.static CriticalHitEvent
fireCriticalHit
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean vanillaCritical, float damageModifier) Fires theCriticalHitEvent
and returns the resulting event.static void
fireCropGrowPost
(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) static SweepAttackEvent
fireSweepAttack
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean isVanillaSweep) Fires theSweepAttackEvent
and returns the resulting event.static Map
<net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.LivingEntity>, net.minecraft.world.entity.ai.attributes.AttributeSupplier> Deprecated.static net.minecraft.world.entity.player.Player
static net.minecraft.world.item.ItemStack
getCraftingRemainder
(net.minecraft.world.item.ItemStack stack) static @Nullable String
getDefaultCreatorModId
(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.world.item.ItemStack itemStack) Used as the default implementation ofIItemExtension.getCreatorModId(net.minecraft.core.HolderLookup.Provider, net.minecraft.world.item.ItemStack)
.static double
getEntityVisibilityMultiplier
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.entity.Entity lookingEntity, double originalMultiplier) static net.minecraft.world.item.ItemStack
getProjectile
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.item.ItemStack projectileWeaponItem, net.minecraft.world.item.ItemStack projectile) Hook to fireLivingGetProjectileEvent
.private static String
getRawText
(net.minecraft.network.chat.Component message) static @Nullable net.minecraft.network.syncher.EntityDataSerializer
<?> getSerializer
(int id, net.minecraft.util.CrudeIncrementalIntIdentityHashBiMap<net.minecraft.network.syncher.EntityDataSerializer<?>> vanilla) static int
getSerializerId
(net.minecraft.network.syncher.EntityDataSerializer<?> serializer, net.minecraft.util.CrudeIncrementalIntIdentityHashBiMap<net.minecraft.network.syncher.EntityDataSerializer<?>> vanilla) static net.minecraft.network.chat.ChatDecorator
static FluidType
getVanillaFluidType
(net.minecraft.world.level.material.Fluid fluid) Returns a vanilla fluid type for the given fluid.static void
handleBlockDrops
(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, List<net.minecraft.world.entity.item.ItemEntity> drops, @Nullable net.minecraft.world.entity.Entity breaker, net.minecraft.world.item.ItemStack tool) Fires theBlockDropsEvent
when block drops (items and experience) are determined.static boolean
isEntityInvulnerableTo
(net.minecraft.world.entity.Entity entity, net.minecraft.world.damagesource.DamageSource source, boolean isInvul) Creates and posts anEntityInvulnerabilityCheckEvent
.static Optional
<net.minecraft.core.BlockPos> isLivingOnLadder
(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.LivingEntity entity) private static boolean
isPotentialRegistryObject
(Object value) static @Nullable net.minecraft.world.effect.MobEffect
loadMobEffect
(net.minecraft.nbt.CompoundTag nbt, String key, @Nullable net.minecraft.world.effect.MobEffect fallback) static com.mojang.serialization.Codec
<List<net.minecraft.world.level.storage.loot.LootPool>> lootPoolsCodec
(BiConsumer<net.minecraft.world.level.storage.loot.LootPool, String> nameSetter) static void
markComponentClassAsValid
(Class<?> clazz) Marks a class as being safe to use as adata component
.static void
Deprecated.static List
<net.minecraft.world.item.ItemStack> modifyLoot
(List<net.minecraft.world.item.ItemStack> list, net.minecraft.world.level.storage.loot.LootContext context) Deprecated.static it.unimi.dsi.fastutil.objects.ObjectArrayList
<net.minecraft.world.item.ItemStack> modifyLoot
(net.minecraft.resources.ResourceLocation lootTableId, it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context) Handles the modification of loot table drops via the registered Global Loot Modifiers, so that custom effects can be processed.static net.minecraft.network.chat.Component
newChatWithLinks
(String string) static net.minecraft.network.chat.Component
newChatWithLinks
(String string, boolean allowMissingHeader) static boolean
onAnvilChange
(net.minecraft.world.inventory.AnvilMenu container, net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right, net.minecraft.world.Container outputSlot, String name, long baseCost, net.minecraft.world.entity.player.Player player) static float
onAnvilRepair
(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack output, net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right) static void
onArmorHurt
(net.minecraft.world.damagesource.DamageSource source, net.minecraft.world.entity.EquipmentSlot[] slots, float damage, net.minecraft.world.entity.LivingEntity armoredEntity) This is invoked inLivingEntity.doHurtEquipment(DamageSource, float, EquipmentSlot...)
and replaces the existing item hurt and break logic with an event-sensitive version.static @Nullable net.minecraft.world.level.GameType
onChangeGameType
(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.GameType currentGameType, net.minecraft.world.level.GameType newGameType) static Collection
<net.minecraft.world.item.CreativeModeTab> onCheckCreativeTabs
(net.minecraft.world.item.CreativeModeTab... vanillaTabs) static void
onChunkUnload
(net.minecraft.world.entity.ai.village.poi.PoiManager poiManager, net.minecraft.world.level.chunk.ChunkAccess chunkAccess) The goal here is to fix the POI memory leak that happens due toSectionStorage.storage
field never actually removing POIs long after they become irrelevant.onClientMineHold
(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction face) static LivingShieldBlockEvent
onDamageBlock
(net.minecraft.world.entity.LivingEntity blocker, DamageContainer container, float blockedDamage, boolean originalBlocked) Creates, posts, and returns aLivingShieldBlockEvent
.static void
onDifficultyChange
(net.minecraft.world.Difficulty difficulty, net.minecraft.world.Difficulty oldDifficulty) static void
onEmptyClick
(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) static void
onEmptyLeftClick
(net.minecraft.world.entity.player.Player player) static void
onEntityEnterSection
(net.minecraft.world.entity.Entity entity, long packedOldPos, long packedNewPos) static boolean
onEntityIncomingDamage
(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Called after invulnerability checks inEntity.hurt(DamageSource, float)
, this method creates and posts the first event in the LivingEntity damage sequence,LivingIncomingDamageEvent
.static boolean
onFarmlandTrample
(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, double fallDistance, net.minecraft.world.entity.Entity entity) static int
onGrindstoneChange
(net.minecraft.world.item.ItemStack top, net.minecraft.world.item.ItemStack bottom, net.minecraft.world.Container outputSlot, int xp) static boolean
onGrindstoneTake
(net.minecraft.world.Container inputSlots, net.minecraft.world.inventory.ContainerLevelAccess access, Function<net.minecraft.world.level.Level, Integer> xpFunction) static @Nullable net.minecraft.world.InteractionResult
onInteractEntity
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.InteractionHand hand) static @Nullable net.minecraft.world.InteractionResult
onInteractEntityAt
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.phys.HitResult ray, net.minecraft.world.InteractionHand hand) static @Nullable net.minecraft.world.InteractionResult
onInteractEntityAt
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.phys.Vec3 vec3d, net.minecraft.world.InteractionHand hand) static @Nullable net.minecraft.world.InteractionResult
onItemRightClick
(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) static boolean
onItemStackedOn
(net.minecraft.world.item.ItemStack carriedItem, net.minecraft.world.item.ItemStack stackedOnItem, net.minecraft.world.inventory.Slot slot, net.minecraft.world.inventory.ClickAction action, net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.SlotAccess carriedSlotAccess) Fires theItemStackedOnOtherEvent
, allowing items to handle custom behavior relating to being stacked together (i.e. how the bundle operates).onLeftClickBlock
(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction face, net.minecraft.network.protocol.game.ServerboundPlayerActionPacket.Action action) static void
onLivingBreathe
(net.minecraft.world.entity.LivingEntity entity, int consumeAirAmount, int refillAirAmount) Handles living entities being underwater.static LivingChangeTargetEvent
onLivingChangeTarget
(net.minecraft.world.entity.LivingEntity entity, @Nullable net.minecraft.world.entity.LivingEntity originalTarget, LivingChangeTargetEvent.ILivingTargetType targetType) static void
onLivingDamagePost
(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Creates and posts aLivingDamageEvent.Post
.static float
onLivingDamagePre
(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Creates and posts anLivingDamageEvent.Pre
.static boolean
onLivingDeath
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource src) static boolean
onLivingDrops
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource source, Collection<net.minecraft.world.entity.item.ItemEntity> drops, boolean recentlyHit) static LivingFallEvent
onLivingFall
(net.minecraft.world.entity.LivingEntity entity, double distance, float damageMultiplier) static void
onLivingJump
(net.minecraft.world.entity.LivingEntity entity) static LivingKnockBackEvent
onLivingKnockBack
(net.minecraft.world.entity.LivingEntity target, float strength, double ratioX, double ratioZ) static LivingSwapItemsEvent.Hands
onLivingSwapHandItems
(net.minecraft.world.entity.LivingEntity livingEntity) static boolean
onLivingUseTotem
(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource damageSource, net.minecraft.world.item.ItemStack totem, net.minecraft.world.InteractionHand hand) static int
onNoteChange
(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int old, int _new) static net.minecraft.world.InteractionResult
onPlaceItemIntoWorld
(net.minecraft.world.item.context.UseOnContext context) static boolean
onPlayerAttackTarget
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target) static void
onPlayerEnchantItem
(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.item.enchantment.EnchantmentInstance> instances) FiresPlayerEnchantItemEvent
inEnchantmentMenu.clickMenuButton(Player, int)
after the enchants are applied to the item.static @Nullable net.minecraft.world.entity.item.ItemEntity
onPlayerTossEvent
(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack item, boolean includeName) onRightClickBlock
(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos, net.minecraft.world.phys.BlockHitResult hitVec) static @Nullable net.minecraft.network.chat.Component
onServerChatSubmittedEvent
(net.minecraft.server.level.ServerPlayer player, String plain, net.minecraft.network.chat.Component decorated) static boolean
onTravelToDimension
(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension) static boolean
onVanillaGameEvent
(net.minecraft.world.level.Level level, net.minecraft.core.Holder<net.minecraft.world.level.gameevent.GameEvent> vanillaEvent, net.minecraft.world.phys.Vec3 pos, net.minecraft.world.level.gameevent.GameEvent.Context context) private static boolean
overridesEqualsAndHashCode
(Class<?> clazz) static com.mojang.serialization.Lifecycle
parseLifecycle
(String lifecycle) static String
prefixNamespace
(net.minecraft.resources.ResourceLocation registryKey) This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraftstatic void
readAdditionalLevelSaveData
(net.minecraft.nbt.CompoundTag rootTag, net.minecraft.world.level.storage.LevelStorageSource.LevelDirectory levelDirectory) static <T> @Nullable net.minecraft.core.HolderLookup.RegistryLookup
<T> resolveLookup
(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key) Attempts to resolve aHolderLookup.RegistryLookup
using the current global state.static void
saveMobEffect
(net.minecraft.nbt.CompoundTag nbt, String key, net.minecraft.world.effect.MobEffect effect) static void
sendRecipes
(net.minecraft.server.level.ServerPlayer player, Set<net.minecraft.world.item.crafting.RecipeType<?>> recipeTypesToSend, net.minecraft.world.item.crafting.RecipeMap recipeMap) Determines whether the given players should be sent full recipe content or not and handles the sending.static void
setCraftingPlayer
(net.minecraft.world.entity.player.Player player) static boolean
shouldSuppressEnderManAnger
(net.minecraft.world.entity.monster.EnderMan enderMan, net.minecraft.world.entity.player.Player player) static boolean
tryDispenseShearsHarvestBlock
(net.minecraft.core.dispenser.BlockSource source, net.minecraft.world.item.ItemStack stack, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Attempts to modify target block usingItemAbilities.SHEARS_HARVEST
inShearsDispenseItemBehavior
, consistent with vanilla beehive harvest behavior (also controlled byItemAbilities.SHEARS_HARVEST
).static void
validateComponent
(@Nullable Object dataComponent) Checks that all data components override equals and hashCode.static <T> net.minecraft.core.HolderLookup.RegistryLookup
<T> wrapRegistryLookup
(net.minecraft.core.HolderLookup.RegistryLookup<T> lookup) static void
writeAdditionalLevelSaveData
(net.minecraft.world.level.storage.WorldData worldData, net.minecraft.nbt.CompoundTag levelTag)
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
WORLDPERSISTENCE
private static final org.apache.logging.log4j.Marker WORLDPERSISTENCE -
URL_PATTERN
-
craftingPlayer
-
VANILLA_SERIALIZER_LIMIT
public static final int VANILLA_SERIALIZER_LIMIT- See Also:
-
VANILLA_DIMS
-
DIMENSIONS_KEY
- See Also:
-
SEED_KEY
- See Also:
-
FORGE_ATTRIBUTES
private static final Map<net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.LivingEntity>,net.minecraft.world.entity.ai.attributes.AttributeSupplier> FORGE_ATTRIBUTES -
FORGE_CONVERSION_MAP
-
checkedComponentClasses
-
-
Constructor Details
-
CommonHooks
public CommonHooks()
-
-
Method Details
-
canContinueUsing
public static boolean canContinueUsing(net.minecraft.world.item.ItemStack from, net.minecraft.world.item.ItemStack to) -
onItemStackedOn
public static boolean onItemStackedOn(net.minecraft.world.item.ItemStack carriedItem, net.minecraft.world.item.ItemStack stackedOnItem, net.minecraft.world.inventory.Slot slot, net.minecraft.world.inventory.ClickAction action, net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.SlotAccess carriedSlotAccess) Fires theItemStackedOnOtherEvent
, allowing items to handle custom behavior relating to being stacked together (i.e. how the bundle operates).Called from
AbstractContainerMenu.doClick(int, int, net.minecraft.world.inventory.ClickType, net.minecraft.world.entity.player.Player)
in the utility methodAbstractContainerMenu.tryItemClickBehaviourOverride(net.minecraft.world.entity.player.Player, net.minecraft.world.inventory.ClickAction, net.minecraft.world.inventory.Slot, net.minecraft.world.item.ItemStack, net.minecraft.world.item.ItemStack)
before eitherItemStack.overrideStackedOnOther(net.minecraft.world.inventory.Slot, net.minecraft.world.inventory.ClickAction, net.minecraft.world.entity.player.Player)
orItemStack.overrideOtherStackedOnMe(net.minecraft.world.item.ItemStack, net.minecraft.world.inventory.Slot, net.minecraft.world.inventory.ClickAction, net.minecraft.world.entity.player.Player, net.minecraft.world.entity.SlotAccess)
is called.- Parameters:
carriedItem
- The item currently held by the player, being clicked into the slotstackedOnItem
- The item currently present in the clicked slotslot
- TheSlot
being clickedaction
- The click action being performedplayer
- The player who clicked the slotcarriedSlotAccess
- A slot access permitting changing the carried item.- Returns:
- True if the event was cancelled, indicating that a mod has handled the click; false otherwise
-
onDifficultyChange
public static void onDifficultyChange(net.minecraft.world.Difficulty difficulty, net.minecraft.world.Difficulty oldDifficulty) -
onLivingChangeTarget
public static LivingChangeTargetEvent onLivingChangeTarget(net.minecraft.world.entity.LivingEntity entity, @Nullable @Nullable net.minecraft.world.entity.LivingEntity originalTarget, LivingChangeTargetEvent.ILivingTargetType targetType) -
isEntityInvulnerableTo
public static boolean isEntityInvulnerableTo(net.minecraft.world.entity.Entity entity, net.minecraft.world.damagesource.DamageSource source, boolean isInvul) Creates and posts anEntityInvulnerabilityCheckEvent
. This is invoked inEntity.isInvulnerableToBase(DamageSource)
and returns a post-listener result to the invulnerability status of the entity to the damage source.- Parameters:
entity
- the entity being checked for invulnerabilitysource
- the damage source being applied for this checkisInvul
- whether this entity is invulnerable according to preceding/vanilla logic- Returns:
- if this entity is invulnerable
-
onEntityIncomingDamage
public static boolean onEntityIncomingDamage(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Called after invulnerability checks inEntity.hurt(DamageSource, float)
, this method creates and posts the first event in the LivingEntity damage sequence,LivingIncomingDamageEvent
.- Parameters:
entity
- the entity to receive damagecontainer
- the newly instantiated container for damage to be dealt. Most properties of the container will be empty at this stage.- Returns:
- if the event is cancelled and no damage will be applied to the entity
-
onLivingKnockBack
public static LivingKnockBackEvent onLivingKnockBack(net.minecraft.world.entity.LivingEntity target, float strength, double ratioX, double ratioZ) -
onLivingUseTotem
public static boolean onLivingUseTotem(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource damageSource, net.minecraft.world.item.ItemStack totem, net.minecraft.world.InteractionHand hand) -
onLivingDamagePre
public static float onLivingDamagePre(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Creates and posts anLivingDamageEvent.Pre
. This is invoked ininvalid reference
LivingEntity#actuallyHurt(DamageSource, float)
invalid reference
Player#actuallyHurt(DamageSource, float)
LivingEntity.damageContainers
as a parameter.- Parameters:
entity
- the entity to receive damagecontainer
- the container object holding the final values of the damage pipeline while they are still mutable- Returns:
- the current damage value to be applied to the entity's health
-
onLivingDamagePost
public static void onLivingDamagePost(net.minecraft.world.entity.LivingEntity entity, DamageContainer container) Creates and posts aLivingDamageEvent.Post
. This is invoked ininvalid reference
LivingEntity#actuallyHurt(DamageSource, float)
invalid reference
Player#actuallyHurt(DamageSource, float)
LivingEntity.damageContainers
as a parameter.- Parameters:
entity
- the entity to receive damagecontainer
- the container object holding the truly final values of the damage pipeline. The values of this container and used to instantiate final fields in the event.
-
onArmorHurt
public static void onArmorHurt(net.minecraft.world.damagesource.DamageSource source, net.minecraft.world.entity.EquipmentSlot[] slots, float damage, net.minecraft.world.entity.LivingEntity armoredEntity) This is invoked inLivingEntity.doHurtEquipment(DamageSource, float, EquipmentSlot...)
and replaces the existing item hurt and break logic with an event-sensitive version.
Each armor slot is collected and passed into aArmorHurtEvent
and posted. If not cancelled, the final durability loss values for each equipment item from the event will be applied.- Parameters:
source
- the damage source applied to the entity and armorslots
- an array of applicable slots for damagedamage
- the durability damage individual items will receivearmoredEntity
- the entity wearing the armor
-
onLivingDeath
public static boolean onLivingDeath(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource src) -
onLivingDrops
public static boolean onLivingDrops(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.damagesource.DamageSource source, Collection<net.minecraft.world.entity.item.ItemEntity> drops, boolean recentlyHit) -
onLivingFall
public static LivingFallEvent onLivingFall(net.minecraft.world.entity.LivingEntity entity, double distance, float damageMultiplier) -
getEntityVisibilityMultiplier
public static double getEntityVisibilityMultiplier(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.entity.Entity lookingEntity, double originalMultiplier) -
isLivingOnLadder
public static Optional<net.minecraft.core.BlockPos> isLivingOnLadder(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.LivingEntity entity) -
onLivingJump
public static void onLivingJump(net.minecraft.world.entity.LivingEntity entity) -
onPlayerTossEvent
@Nullable public static @Nullable net.minecraft.world.entity.item.ItemEntity onPlayerTossEvent(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack item, boolean includeName) -
onVanillaGameEvent
public static boolean onVanillaGameEvent(net.minecraft.world.level.Level level, net.minecraft.core.Holder<net.minecraft.world.level.gameevent.GameEvent> vanillaEvent, net.minecraft.world.phys.Vec3 pos, net.minecraft.world.level.gameevent.GameEvent.Context context) -
getRawText
-
onServerChatSubmittedEvent
@Nullable public static @Nullable net.minecraft.network.chat.Component onServerChatSubmittedEvent(net.minecraft.server.level.ServerPlayer player, String plain, net.minecraft.network.chat.Component decorated) -
getServerChatSubmittedDecorator
public static net.minecraft.network.chat.ChatDecorator getServerChatSubmittedDecorator() -
newChatWithLinks
-
newChatWithLinks
public static net.minecraft.network.chat.Component newChatWithLinks(String string, boolean allowMissingHeader) -
handleBlockDrops
public static void handleBlockDrops(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, List<net.minecraft.world.entity.item.ItemEntity> drops, @Nullable @Nullable net.minecraft.world.entity.Entity breaker, net.minecraft.world.item.ItemStack tool) Fires theBlockDropsEvent
when block drops (items and experience) are determined. If the event is not cancelled, all drops will be added to the world, and thenBlockBehaviour.spawnAfterBreak(net.minecraft.world.level.block.state.BlockState, net.minecraft.server.level.ServerLevel, net.minecraft.core.BlockPos, net.minecraft.world.item.ItemStack, boolean)
will be called.- Parameters:
level
- The levelpos
- The broken block's positionstate
- The broken block's stateblockEntity
- The block entity from the given positiondrops
- The list of all items dropped by the block, captured fromBlock.getDrops(net.minecraft.world.level.block.state.BlockState, net.minecraft.server.level.ServerLevel, net.minecraft.core.BlockPos, net.minecraft.world.level.block.entity.BlockEntity)
breaker
- The entity who broke the block, or null if unknowntool
- The tool used when breaking the block; may be empty
-
fireBlockBreak
public static BlockEvent.BreakEvent fireBlockBreak(net.minecraft.world.level.Level level, net.minecraft.world.level.GameType gameType, net.minecraft.server.level.ServerPlayer player, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) FiresBlockEvent.BreakEvent
, pre-emptively canceling the event based on the conditions that will cause the block to not be broken anyway.Note that undoing the pre-cancel will not permit breaking the block, since the vanilla conditions will always be checked.
- Parameters:
level
- The levelgameType
- The game type of the breaking playerplayer
- The breaking playerpos
- The position of the block being brokenstate
- The state of the block being broken- Returns:
- The event
-
onPlaceItemIntoWorld
public static net.minecraft.world.InteractionResult onPlaceItemIntoWorld(net.minecraft.world.item.context.UseOnContext context) -
onPlayerEnchantItem
public static void onPlayerEnchantItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.item.enchantment.EnchantmentInstance> instances) FiresPlayerEnchantItemEvent
inEnchantmentMenu.clickMenuButton(Player, int)
after the enchants are applied to the item.- Parameters:
player
- the player who clicked the menu buttonstack
- the item enchantedinstances
- the specific enchantments that were applied to the item.
-
onAnvilChange
public static boolean onAnvilChange(net.minecraft.world.inventory.AnvilMenu container, net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right, net.minecraft.world.Container outputSlot, String name, long baseCost, net.minecraft.world.entity.player.Player player) -
onAnvilRepair
public static float onAnvilRepair(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack output, net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right) -
onGrindstoneChange
public static int onGrindstoneChange(net.minecraft.world.item.ItemStack top, net.minecraft.world.item.ItemStack bottom, net.minecraft.world.Container outputSlot, int xp) -
onGrindstoneTake
-
setCraftingPlayer
public static void setCraftingPlayer(net.minecraft.world.entity.player.Player player) -
getCraftingPlayer
public static net.minecraft.world.entity.player.Player getCraftingPlayer() -
getCraftingRemainder
public static net.minecraft.world.item.ItemStack getCraftingRemainder(net.minecraft.world.item.ItemStack stack) -
onPlayerAttackTarget
public static boolean onPlayerAttackTarget(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target) -
onTravelToDimension
public static boolean onTravelToDimension(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension) -
onInteractEntityAt
@Nullable public static @Nullable net.minecraft.world.InteractionResult onInteractEntityAt(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.phys.HitResult ray, net.minecraft.world.InteractionHand hand) -
onInteractEntityAt
@Nullable public static @Nullable net.minecraft.world.InteractionResult onInteractEntityAt(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.phys.Vec3 vec3d, net.minecraft.world.InteractionHand hand) -
onInteractEntity
@Nullable public static @Nullable net.minecraft.world.InteractionResult onInteractEntity(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity entity, net.minecraft.world.InteractionHand hand) -
onItemRightClick
@Nullable public static @Nullable net.minecraft.world.InteractionResult onItemRightClick(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) -
onLeftClickBlock
public static PlayerInteractEvent.LeftClickBlock onLeftClickBlock(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction face, net.minecraft.network.protocol.game.ServerboundPlayerActionPacket.Action action) -
onClientMineHold
public static PlayerInteractEvent.LeftClickBlock onClientMineHold(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction face) -
onRightClickBlock
public static PlayerInteractEvent.RightClickBlock onRightClickBlock(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos, net.minecraft.world.phys.BlockHitResult hitVec) -
onEmptyClick
public static void onEmptyClick(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) -
onEmptyLeftClick
public static void onEmptyLeftClick(net.minecraft.world.entity.player.Player player) -
onChangeGameType
@Nullable public static @Nullable net.minecraft.world.level.GameType onChangeGameType(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.GameType currentGameType, net.minecraft.world.level.GameType newGameType) - Returns:
- null if game type should not be changed, desired new GameType otherwise
-
lootPoolsCodec
@Internal public static com.mojang.serialization.Codec<List<net.minecraft.world.level.storage.loot.LootPool>> lootPoolsCodec(BiConsumer<net.minecraft.world.level.storage.loot.LootPool, String> nameSetter) -
getVanillaFluidType
Returns a vanilla fluid type for the given fluid.- Parameters:
fluid
- the fluid looking for its type- Returns:
- the type of the fluid if vanilla
- Throws:
RuntimeException
- if the fluid is not a vanilla one
-
onCheckCreativeTabs
public static Collection<net.minecraft.world.item.CreativeModeTab> onCheckCreativeTabs(net.minecraft.world.item.CreativeModeTab... vanillaTabs) -
canCropGrow
public static boolean canCropGrow(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, boolean def) Checks if a crop can grow by firingCropGrowEvent.Pre
.- Parameters:
level
- The level the crop is inpos
- The position of the cropstate
- The state of the cropdef
- The result of the default checks performed by the crop.- Returns:
- true if the crop can grow
-
fireCropGrowPost
public static void fireCropGrowPost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) -
fireCriticalHit
public static CriticalHitEvent fireCriticalHit(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean vanillaCritical, float damageModifier) Fires theCriticalHitEvent
and returns the resulting event.- Parameters:
player
- The attacking playertarget
- The attack targetvanillaCritical
- If the attack would have been a critical hit by vanilla's rules inPlayer.attack(Entity)
.damageModifier
- The base damage modifier. Vanilla critical hits have a damage modifier of 1.5.
-
fireSweepAttack
public static SweepAttackEvent fireSweepAttack(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean isVanillaSweep) Fires theSweepAttackEvent
and returns the resulting event.- Parameters:
player
- The attacking player.target
- The attack target.isVanillaSweep
- If the attack would have been a sweep attack by vanilla's rules inPlayer.attack(Entity)
.
-
computeModifiedAttributes
public static net.minecraft.world.item.component.ItemAttributeModifiers computeModifiedAttributes(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.component.ItemAttributeModifiers defaultModifiers) Hook to fireItemAttributeModifierEvent
. Modders should useItemStack.forEachModifier(EquipmentSlot, BiConsumer)
instead. -
getProjectile
public static net.minecraft.world.item.ItemStack getProjectile(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.item.ItemStack projectileWeaponItem, net.minecraft.world.item.ItemStack projectile) Hook to fireLivingGetProjectileEvent
. Returns the ammo to be used. -
getDefaultCreatorModId
@Nullable public static @Nullable String getDefaultCreatorModId(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.world.item.ItemStack itemStack) Used as the default implementation ofIItemExtension.getCreatorModId(net.minecraft.core.HolderLookup.Provider, net.minecraft.world.item.ItemStack)
. Call that method instead. -
onFarmlandTrample
public static boolean onFarmlandTrample(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, double fallDistance, net.minecraft.world.entity.Entity entity) -
onNoteChange
public static int onNoteChange(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int old, int _new) -
getSerializer
@Nullable public static @Nullable net.minecraft.network.syncher.EntityDataSerializer<?> getSerializer(int id, net.minecraft.util.CrudeIncrementalIntIdentityHashBiMap<net.minecraft.network.syncher.EntityDataSerializer<?>> vanilla) -
getSerializerId
public static int getSerializerId(net.minecraft.network.syncher.EntityDataSerializer<?> serializer, net.minecraft.util.CrudeIncrementalIntIdentityHashBiMap<net.minecraft.network.syncher.EntityDataSerializer<?>> vanilla) -
canEntityDestroy
public static boolean canEntityDestroy(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.LivingEntity entity) -
modifyLoot
@Deprecated public static List<net.minecraft.world.item.ItemStack> modifyLoot(List<net.minecraft.world.item.ItemStack> list, net.minecraft.world.level.storage.loot.LootContext context) Deprecated.All loot table drops should be passed to this function so that mod added effects (e.g. smelting enchantments) can be processed.- Parameters:
list
- The loot generatedcontext
- The loot context that generated that loot- Returns:
- The modified list
-
modifyLoot
public static it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> modifyLoot(net.minecraft.resources.ResourceLocation lootTableId, it.unimi.dsi.fastutil.objects.ObjectArrayList<net.minecraft.world.item.ItemStack> generatedLoot, net.minecraft.world.level.storage.loot.LootContext context) Handles the modification of loot table drops via the registered Global Loot Modifiers, so that custom effects can be processed.All loot-table generated loot should be passed to this function.
- Parameters:
lootTableId
- The ID of the loot table currently being queriedgeneratedLoot
- The loot generated by the loot tablecontext
- The loot context that generated the loot, unmodified- Returns:
- The modified list of drops
-
getModDataPacks
-
getModDataPacksWithVanilla
-
getAttributesView
@Deprecated public static Map<net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.LivingEntity>,net.minecraft.world.entity.ai.attributes.AttributeSupplier> getAttributesView()Deprecated.FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY -
modifyAttributes
Deprecated.FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY -
onEntityEnterSection
public static void onEntityEnterSection(net.minecraft.world.entity.Entity entity, long packedOldPos, long packedNewPos) -
onDamageBlock
public static LivingShieldBlockEvent onDamageBlock(net.minecraft.world.entity.LivingEntity blocker, DamageContainer container, float blockedDamage, boolean originalBlocked) Creates, posts, and returns aLivingShieldBlockEvent
. This method is invoked inEntity.hurt(DamageSource, float)
and requires internal access to the top entry in the protected fieldLivingEntity.damageContainers
as a parameter.- Parameters:
blocker
- the entity performing the blockcontainer
- the entity's internal damage container for accessing current values in the damage pipeline at the time of this invocation.blockedDamage
- the amount of damage that would be blockedoriginalBlocked
- whether this entity is blocking according to preceding/vanilla logic- Returns:
- the event object after event listeners have been invoked.
-
onLivingSwapHandItems
public static LivingSwapItemsEvent.Hands onLivingSwapHandItems(net.minecraft.world.entity.LivingEntity livingEntity) -
writeAdditionalLevelSaveData
@Internal public static void writeAdditionalLevelSaveData(net.minecraft.world.level.storage.WorldData worldData, net.minecraft.nbt.CompoundTag levelTag) -
readAdditionalLevelSaveData
@Internal public static void readAdditionalLevelSaveData(net.minecraft.nbt.CompoundTag rootTag, net.minecraft.world.level.storage.LevelStorageSource.LevelDirectory levelDirectory) - Parameters:
rootTag
- Level data file contents.levelDirectory
- Level currently being loaded.
-
encodeLifecycle
-
parseLifecycle
-
saveMobEffect
public static void saveMobEffect(net.minecraft.nbt.CompoundTag nbt, String key, net.minecraft.world.effect.MobEffect effect) -
loadMobEffect
@Nullable public static @Nullable net.minecraft.world.effect.MobEffect loadMobEffect(net.minecraft.nbt.CompoundTag nbt, String key, @Nullable @Nullable net.minecraft.world.effect.MobEffect fallback) -
shouldSuppressEnderManAnger
public static boolean shouldSuppressEnderManAnger(net.minecraft.world.entity.monster.EnderMan enderMan, net.minecraft.world.entity.player.Player player) -
prefixNamespace
This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraft
This rules conflicts with equal paths out. If for example the mod
fancy_cheese
adds a registry namedcheeses
, but the modawesome_cheese
also adds a registry calledcheeses
, they are going to have the same pathcheeses
, just with different namespaces. Ifadditional_cheese
wants to add additional cheese toawesome_cheese
, but notfancy_cheese
, it can not differentiate both. Both paths will look likedata/additional_cheese/cheeses
.The fix, which is applied here prefixes the path of the registry with the namespace, so
fancy_cheese
's registry stores its elements indata/<namespace>/fancy_cheese/cheeses
andawesome_cheese
's registry stores its elements indata/namespace/awesome_cheese/cheeses
- Parameters:
registryKey
- key of the registry- Returns:
- path of the registry key. Prefixed with the namespace if it is not "minecraft"
-
wrapRegistryLookup
@Internal public static <T> net.minecraft.core.HolderLookup.RegistryLookup<T> wrapRegistryLookup(net.minecraft.core.HolderLookup.RegistryLookup<T> lookup) -
onLivingBreathe
public static void onLivingBreathe(net.minecraft.world.entity.LivingEntity entity, int consumeAirAmount, int refillAirAmount) Handles living entities being underwater. This fires theLivingBreatheEvent
and if the entity's air supply is less than or equal to zero also theLivingDrownEvent
. Additionally, when the entity is underwater it will dismount ifIEntityExtension.canBeRiddenUnderFluidType(FluidType, Entity)
returns false.- Parameters:
entity
- The living entity which is currently updatedconsumeAirAmount
- The amount of air to consume when the entity is unable to breatherefillAirAmount
- The amount of air to refill when the entity is able to breathe
-
markComponentClassAsValid
Marks a class as being safe to use as adata component
. Keep in mind that data components are compared withObject.equals(Object)
and hashed withObject.hashCode()
. They must also be immutable.Only call this method if the default implementations of
Object.equals(Object)
andObject.hashCode()
are suitable for this class, and if instances of this class are immutable. Typically, this is only the case for singletons such asBlock
instances. -
validateComponent
Checks that all data components override equals and hashCode. -
isPotentialRegistryObject
-
overridesEqualsAndHashCode
-
onChunkUnload
public static void onChunkUnload(net.minecraft.world.entity.ai.village.poi.PoiManager poiManager, net.minecraft.world.level.chunk.ChunkAccess chunkAccess) The goal here is to fix the POI memory leak that happens due toSectionStorage.storage
field never actually removing POIs long after they become irrelevant. We do it here in chunk unload event so that chunk that are fully unloaded now gets the POI removed from the POI cached storage map. -
canMobEffectBeApplied
public static boolean canMobEffectBeApplied(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.effect.MobEffectInstance effect) Checks if a mob effect can be applied to an entity by firingMobEffectEvent.Applicable
.- Parameters:
entity
- The target entity the mob effect is being applied to.effect
- The mob effect being applied.- Returns:
- True if the mob effect can be applied, otherwise false.
-
resolveLookup
@Nullable public static <T> @Nullable net.minecraft.core.HolderLookup.RegistryLookup<T> resolveLookup(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key) Attempts to resolve aHolderLookup.RegistryLookup
using the current global state.Prioritizes the server's lookup, only attempting to retrieve it from the client if the server is unavailable.
- Type Parameters:
T
- The type of registry being looked up- Parameters:
key
- The resource key for the target registry- Returns:
- A registry access, if one was available.
-
extractLookupProvider
public static net.minecraft.core.HolderLookup.Provider extractLookupProvider(net.minecraft.resources.RegistryOps<?> ops) Extracts aHolderLookup.Provider
from the givenops
, if possible.- Throws:
IllegalArgumentException
- if the ops were not created using a HolderLookup.Provider
-
dispenseUseOnContext
public static net.minecraft.world.item.context.UseOnContext dispenseUseOnContext(net.minecraft.core.dispenser.BlockSource source, net.minecraft.world.item.ItemStack stack) Creates aUseOnContext
fordispense behavior
.- Parameters:
source
- theblock source
context of the dispense behaviorstack
- the dispensed item stack- Returns:
- a
UseOnContext
representing the dispense behavior
-
tryDispenseShearsHarvestBlock
public static boolean tryDispenseShearsHarvestBlock(net.minecraft.core.dispenser.BlockSource source, net.minecraft.world.item.ItemStack stack, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Attempts to modify target block usingItemAbilities.SHEARS_HARVEST
inShearsDispenseItemBehavior
, consistent with vanilla beehive harvest behavior (also controlled byItemAbilities.SHEARS_HARVEST
).The beehive harvest behavior is not implemented by
IBlockExtension.getToolModifiedState(BlockState, UseOnContext, ItemAbility, boolean)
and thus will still be controlled byShearsDispenseItemBehavior.tryShearBeehive(ServerLevel, BlockPos)
by default.Mods may subscribe to
BlockEvent.BlockToolModificationEvent
to override vanilla beehive harvest behavior by setting a non-nullBlockState
result. -
buildRecipeBookTypeTagFields
-
sendRecipes
public static void sendRecipes(net.minecraft.server.level.ServerPlayer player, Set<net.minecraft.world.item.crafting.RecipeType<?>> recipeTypesToSend, net.minecraft.world.item.crafting.RecipeMap recipeMap) Determines whether the given players should be sent full recipe content or not and handles the sending.
-
modifyLoot(ResourceLocation, ObjectArrayList, LootContext)
instead.