Package net.minecraftforge.common
Class ForgeHooks
java.lang.Object
net.minecraftforge.common.ForgeHooks
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
private static class
-
Field Summary
Modifier and TypeFieldDescriptionprivate static ThreadLocal<Player>
private static final String
private static final Map<EntityType<? extends LivingEntity>,
AttributeSupplier> private static final Lazy<Map<String,
StructuresBecomeConfiguredFix.Conversion>> private static final org.apache.logging.log4j.Marker
private static final org.apache.logging.log4j.Logger
private static ThreadLocal<Deque<ForgeHooks.LootTableContext>>
private static BannerPattern[]
private static final String
private static Map<EntityDataSerializer<?>,
DataSerializerEntry> private static int
(package private) static final Pattern
private static final Map<IRegistryDelegate<Item>,
Integer> private static final org.apache.logging.log4j.Marker
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canContinueUsing
(ItemStack from, ItemStack to) static boolean
canEntityDestroy
(Level level, BlockPos pos, LivingEntity entity) static int
canEntitySpawn
(Mob entity, LevelAccessor world, double x, double y, double z, BaseSpawner spawner, MobSpawnType spawnReason) static FluidAttributes
static <T> void
deserializeTagAdditions
(List<Tag.Entry> list, com.google.gson.JsonObject json, List<Tag.BuilderEntry> allList) static String
encodeLifecycle
(com.mojang.serialization.Lifecycle lifecycle) static Biome
enhanceBiome
(ResourceLocation name, Biome.ClimateSettings climate, Biome.BiomeCategory category, BiomeSpecialEffects effects, BiomeGenerationSettings gen, MobSpawnSettings spawns, com.mojang.serialization.codecs.RecordCodecBuilder.Instance<Biome> codec, ForgeHooks.BiomeCallbackFunction callback) static com.mojang.datafixers.kinds.App<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<LevelStem>,
LevelStem> expandLevelStemCodec
(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<LevelStem> builder, Supplier<com.mojang.datafixers.kinds.App<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<LevelStem>, LevelStem>> vanillaFieldsSupplier) Called in the LevelStem codec builder to add extra fields to dimension jsonsstatic void
fixNullStructureReferences
(ChunkAccess chunk, Map<ConfiguredStructureFeature<?, ?>, it.unimi.dsi.fastutil.longs.LongSet> structureReferences) Fixes MC-194811 When a structure mod is removed, this map may contain null keys.static int
getActualPatternIndex
(int index) static com.google.common.collect.Multimap<Attribute,
AttributeModifier> getAttributeModifiers
(ItemStack stack, EquipmentSlot equipmentSlot, com.google.common.collect.Multimap<Attribute, AttributeModifier> attributes) Hook to fireItemAttributeModifierEvent
.static Map<EntityType<? extends LivingEntity>,
AttributeSupplier> Deprecated.static int
getBurnTime
(ItemStack stack, RecipeType<?> recipeType) Gets the burn time of this itemstack.static ItemStack
getContainerItem
(ItemStack stack) static Player
static CriticalHitEvent
getCriticalHit
(Player player, Entity target, boolean vanillaCritical, float damageModifier) static String
getDefaultCreatorModId
(ItemStack itemStack) Used as the default implementation ofIForgeItem.getCreatorModId(net.minecraft.world.item.ItemStack)
.static String
static double
getEntityVisibilityMultiplier
(LivingEntity entity, Entity lookingEntity, double originalMultiplier) static int
getLootingLevel
(Entity target, Entity killer, DamageSource cause) static int
getLootingLevel
(LivingEntity target, DamageSource cause, int level) private static ForgeHooks.LootTableContext
static int
static ItemStack
getProjectile
(LivingEntity entity, ItemStack projectileWeaponItem, ItemStack projectile) Hook to fireLivingGetProjectileEvent
.static EntityDataSerializer<?>
getSerializer
(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) static int
getSerializerId
(EntityDataSerializer<?> serializer, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) getTagFromVanillaTier
(Tiers tier) static int
static boolean
hasNoElements
(Ingredient ingredient) static boolean
isCorrectToolForDrops
(BlockState state, Player player) isLivingOnLadder
(BlockState state, Level level, BlockPos pos, LivingEntity entity) static WorldGenSettings
Called when dimension jsons are parsed.static LootTable
loadLootTable
(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) static MobEffect
loadMobEffect
(CompoundTag nbt, String key, MobEffect fallback) static void
Deprecated.modifyLoot
(List<ItemStack> list, LootContext context) Deprecated.modifyLoot
(ResourceLocation lootTableId, List<ItemStack> generatedLoot, LootContext context) Handles the modification of loot table drops via the registered Global Loot Modifiers, so that custom effects can be processed.static Component
newChatWithLinks
(String string) static Component
newChatWithLinks
(String string, boolean allowMissingHeader) static void
onAdvancement
(ServerPlayer player, Advancement advancement) static boolean
onAnvilChange
(AnvilMenu container, ItemStack left, ItemStack right, Container outputSlot, String name, int baseCost, Player player) static float
onAnvilRepair
(Player player, ItemStack output, ItemStack left, ItemStack right) static int
onBlockBreakEvent
(Level level, GameType gameType, ServerPlayer entityPlayer, BlockPos pos) static boolean
onChangeGameMode
(Player player, GameType currentGameMode, GameType newGameMode) Deprecated, for removal: This API element is subject to removal in a future version.static GameType
onChangeGameType
(Player player, GameType currentGameType, GameType newGameType) static void
onCropsGrowPost
(Level level, BlockPos pos, BlockState state) static boolean
onCropsGrowPre
(Level level, BlockPos pos, BlockState state, boolean def) static void
onDifficultyChange
(Difficulty difficulty, Difficulty oldDifficulty) static void
onEmptyClick
(Player player, InteractionHand hand) static void
onEmptyLeftClick
(Player player) static void
onEntityEnterSection
(Entity entity, long packedOldPos, long packedNewPos) static boolean
onFarmlandTrample
(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity) static int
onGrindstoneChange
(ItemStack top, ItemStack bottom, Container outputSlot, int xp) static boolean
onGrindstoneTake
(Container inputSlots, ContainerLevelAccess access, Function<Level, Integer> xpFunction) static InteractionResult
onInteractEntity
(Player player, Entity entity, InteractionHand hand) static InteractionResult
onInteractEntityAt
(Player player, Entity entity, HitResult ray, InteractionHand hand) static InteractionResult
onInteractEntityAt
(Player player, Entity entity, Vec3 vec3d, InteractionHand hand) static InteractionResult
onItemRightClick
(Player player, InteractionHand hand) onLeftClickBlock
(Player player, BlockPos pos, Direction face) static boolean
onLivingAttack
(LivingEntity entity, DamageSource src, float amount) static LivingChangeTargetEvent
onLivingChangeTarget
(LivingEntity entity, LivingEntity originalTarget, LivingChangeTargetEvent.ILivingTargetType targetType) static float
onLivingDamage
(LivingEntity entity, DamageSource src, float amount) static boolean
onLivingDeath
(LivingEntity entity, DamageSource src) static boolean
onLivingDrops
(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) static float[]
onLivingFall
(LivingEntity entity, float distance, float damageMultiplier) static float
onLivingHurt
(LivingEntity entity, DamageSource src, float amount) static void
onLivingJump
(LivingEntity entity) static LivingKnockBackEvent
onLivingKnockBack
(LivingEntity target, float strength, double ratioX, double ratioZ) static void
onLivingSetAttackTarget
(LivingEntity entity, LivingEntity target) Deprecated, for removal: This API element is subject to removal in a future version.static void
onLivingSetAttackTarget
(LivingEntity entity, LivingEntity target, LivingChangeTargetEvent.ILivingTargetType targetType) Deprecated, for removal: This API element is subject to removal in a future version.static boolean
onLivingUpdate
(LivingEntity entity) static int
onNoteChange
(Level level, BlockPos pos, BlockState state, int old, int _new) static boolean
onPickBlock
(HitResult target, Player player, Level level) Called when a player uses 'pick block', calls new Entity and Block hooks.static InteractionResult
onPlaceItemIntoWorld
(UseOnContext context) static boolean
onPlayerAttack
(LivingEntity entity, DamageSource src, float amount) static boolean
onPlayerAttackTarget
(Player player, Entity target) static ItemEntity
onPlayerTossEvent
(Player player, ItemStack item, boolean includeName) onRightClickBlock
(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) static Component
onServerChatEvent
(ServerGamePacketListenerImpl net, String raw, Component comp) Deprecated.static ServerChatEvent
onServerChatEvent
(ServerGamePacketListenerImpl net, String raw, Component comp, String filtered, Component filteredComp) static ShieldBlockEvent
onShieldBlock
(LivingEntity blocker, DamageSource source, float blocked) static boolean
onTravelToDimension
(Entity entity, ResourceKey<Level> dimension) static boolean
onVanillaGameEvent
(Level level, Entity cause, GameEvent vanillaEvent, BlockPos position) static com.mojang.serialization.Lifecycle
parseLifecycle
(String lifecycle) static void
readAdditionalLevelSaveData
(CompoundTag rootTag) Deprecated, for removal: This API element is subject to removal in a future version.To be removed in 1.20.static void
readAdditionalLevelSaveData
(CompoundTag rootTag, Path levelPath) static String
readLootEntryName
(com.google.gson.JsonObject json, String type) static String
readPoolName
(com.google.gson.JsonObject json) readTypedPackFormats
(com.google.gson.JsonObject json) static void
static void
saveMobEffect
(CompoundTag nbt, String key, MobEffect effect) static void
setCraftingPlayer
(Player player) static boolean
shouldSuppressEnderManAnger
(EnderMan enderMan, Player player, ItemStack mask) static void
static void
writeAdditionalLevelSaveData
(WorldData worldData, CompoundTag levelTag)
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
FORGEHOOKS
private static final org.apache.logging.log4j.Marker FORGEHOOKS -
WORLDPERSISTENCE
private static final org.apache.logging.log4j.Marker WORLDPERSISTENCE -
URL_PATTERN
-
craftingPlayer
-
lootContext
-
serializerEntries
-
VANILLA_BURNS
-
VANILLA_DIMS
-
DIMENSIONS_KEY
- See Also:
-
SEED_KEY
- See Also:
-
CODEC
-
FORGE_ATTRIBUTES
-
nonPatternItems
-
totalPatternRows
private static int totalPatternRows -
FORGE_CONVERSION_MAP
private static final Lazy<Map<String,StructuresBecomeConfiguredFix.Conversion>> FORGE_CONVERSION_MAP
-
-
Constructor Details
-
ForgeHooks
public ForgeHooks()
-
-
Method Details
-
canContinueUsing
-
isCorrectToolForDrops
-
onPickBlock
Called when a player uses 'pick block', calls new Entity and Block hooks. -
onDifficultyChange
-
onLivingSetAttackTarget
@Deprecated(since="1.19.2", forRemoval=true) public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) Deprecated, for removal: This API element is subject to removal in a future version. -
onLivingSetAttackTarget
@Deprecated(since="1.19.2", forRemoval=true) public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target, LivingChangeTargetEvent.ILivingTargetType targetType) Deprecated, for removal: This API element is subject to removal in a future version. -
onLivingChangeTarget
public static LivingChangeTargetEvent onLivingChangeTarget(LivingEntity entity, LivingEntity originalTarget, LivingChangeTargetEvent.ILivingTargetType targetType) -
onLivingUpdate
-
onLivingAttack
-
onPlayerAttack
-
onLivingKnockBack
public static LivingKnockBackEvent onLivingKnockBack(LivingEntity target, float strength, double ratioX, double ratioZ) -
onLivingHurt
-
onLivingDamage
-
onLivingDeath
-
onLivingDrops
public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) -
onLivingFall
@Nullable public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) -
getLootingLevel
public static int getLootingLevel(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) -
getLootingLevel
-
getEntityVisibilityMultiplier
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier) -
isLivingOnLadder
public static Optional<BlockPos> isLivingOnLadder(@Nonnull BlockState state, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull LivingEntity entity) -
onLivingJump
-
onPlayerTossEvent
@Nullable public static ItemEntity onPlayerTossEvent(@Nonnull Player player, @Nonnull ItemStack item, boolean includeName) -
onVanillaGameEvent
-
onServerChatEvent
@Deprecated @Nullable public static Component onServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp) Deprecated. -
onServerChatEvent
@Nullable public static ServerChatEvent onServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp, @Nullable String filtered, @Nullable Component filteredComp) -
newChatWithLinks
-
newChatWithLinks
-
onBlockBreakEvent
public static int onBlockBreakEvent(Level level, GameType gameType, ServerPlayer entityPlayer, BlockPos pos) -
onPlaceItemIntoWorld
-
onAnvilChange
-
onAnvilRepair
-
onGrindstoneChange
-
onGrindstoneTake
public static boolean onGrindstoneTake(Container inputSlots, ContainerLevelAccess access, Function<Level, Integer> xpFunction) -
setCraftingPlayer
-
getCraftingPlayer
-
getContainerItem
-
onPlayerAttackTarget
-
onTravelToDimension
-
onInteractEntityAt
public static InteractionResult onInteractEntityAt(Player player, Entity entity, HitResult ray, InteractionHand hand) -
onInteractEntityAt
public static InteractionResult onInteractEntityAt(Player player, Entity entity, Vec3 vec3d, InteractionHand hand) -
onInteractEntity
public static InteractionResult onInteractEntity(Player player, Entity entity, InteractionHand hand) -
onItemRightClick
-
onLeftClickBlock
public static PlayerInteractEvent.LeftClickBlock onLeftClickBlock(Player player, BlockPos pos, Direction face) -
onRightClickBlock
public static PlayerInteractEvent.RightClickBlock onRightClickBlock(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) -
onEmptyClick
-
onEmptyLeftClick
-
onChangeGameMode
@Deprecated(forRemoval=true, since="1.18") public static boolean onChangeGameMode(Player player, GameType currentGameMode, GameType newGameMode) Deprecated, for removal: This API element is subject to removal in a future version. -
onChangeGameType
@Nullable public static GameType onChangeGameType(Player player, GameType currentGameType, GameType newGameType) - Returns:
- null if game type should not be changed, desired new GameType otherwise
-
getLootTableContext
-
loadLootTable
@Nullable public static LootTable loadLootTable(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) -
createVanillaFluidAttributes
-
getDefaultWorldPreset
-
getTagFromVanillaTier
-
enhanceBiome
public static Biome enhanceBiome(@Nullable ResourceLocation name, Biome.ClimateSettings climate, Biome.BiomeCategory category, BiomeSpecialEffects effects, BiomeGenerationSettings gen, MobSpawnSettings spawns, com.mojang.serialization.codecs.RecordCodecBuilder.Instance<Biome> codec, ForgeHooks.BiomeCallbackFunction callback) -
readPoolName
-
readLootEntryName
-
onCropsGrowPre
-
onCropsGrowPost
-
getCriticalHit
@Nullable public static CriticalHitEvent getCriticalHit(Player player, Entity target, boolean vanillaCritical, float damageModifier) -
onAdvancement
-
getAttributeModifiers
public static com.google.common.collect.Multimap<Attribute,AttributeModifier> getAttributeModifiers(ItemStack stack, EquipmentSlot equipmentSlot, com.google.common.collect.Multimap<Attribute, AttributeModifier> attributes) Hook to fireItemAttributeModifierEvent
. Modders should useItemStack.getAttributeModifiers(EquipmentSlot)
instead. -
getProjectile
public static ItemStack getProjectile(LivingEntity entity, ItemStack projectileWeaponItem, ItemStack projectile) Hook to fireLivingGetProjectileEvent
. Returns the ammo to be used. -
getDefaultCreatorModId
Used as the default implementation ofIForgeItem.getCreatorModId(net.minecraft.world.item.ItemStack)
. Call that method instead. -
onFarmlandTrample
public static boolean onFarmlandTrample(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity) -
onNoteChange
-
canEntitySpawn
public static int canEntitySpawn(Mob entity, LevelAccessor world, double x, double y, double z, BaseSpawner spawner, MobSpawnType spawnReason) -
hasNoElements
-
deserializeTagAdditions
public static <T> void deserializeTagAdditions(List<Tag.Entry> list, com.google.gson.JsonObject json, List<Tag.BuilderEntry> allList) -
getSerializer
@Nullable public static EntityDataSerializer<?> getSerializer(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) -
getSerializerId
public static int getSerializerId(EntityDataSerializer<?> serializer, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) -
canEntityDestroy
-
getBurnTime
Gets the burn time of this itemstack. -
updateBurns
public static void updateBurns() -
modifyLoot
Deprecated.UsemodifyLoot(ResourceLocation, List, LootContext)
instead.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 List<ItemStack> modifyLoot(ResourceLocation lootTableId, List<ItemStack> generatedLoot, 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
-
getModPacks
-
getModPacksWithVanilla
-
fixNullStructureReferences
public static void fixNullStructureReferences(ChunkAccess chunk, Map<ConfiguredStructureFeature<?, ?>, it.unimi.dsi.fastutil.longs.LongSet> structureReferences) Fixes MC-194811 When a structure mod is removed, this map may contain null keys. This will make the world unable to save if this persists. If we remove a structure from the save data in this way, we then mark the chunk for saving -
getAttributesView
@Deprecated public static Map<EntityType<? extends LivingEntity>,AttributeSupplier> getAttributesView()Deprecated.FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY -
modifyAttributes
Deprecated.FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY -
onEntityEnterSection
-
onShieldBlock
public static ShieldBlockEvent onShieldBlock(LivingEntity blocker, DamageSource source, float blocked) -
loadDimensionsWithServerSeed
Called when dimension jsons are parsed. Creates a copy of the worldgen settings and its dimension registry, where dimensions that specify that they should use the server seed will use the server seed instead of the seed that mojang requires be specified in the json. -
expandLevelStemCodec
public static com.mojang.datafixers.kinds.App<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<LevelStem>,LevelStem> expandLevelStemCodec(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<LevelStem> builder, Supplier<com.mojang.datafixers.kinds.App<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<LevelStem>, LevelStem>> vanillaFieldsSupplier) Called in the LevelStem codec builder to add extra fields to dimension jsons -
writeAdditionalLevelSaveData
-
readAdditionalLevelSaveData
@Deprecated(forRemoval=true, since="1.19.2") public static void readAdditionalLevelSaveData(CompoundTag rootTag) Deprecated, for removal: This API element is subject to removal in a future version.To be removed in 1.20. UsereadAdditionalLevelSaveData(CompoundTag, Path)
instead. -
readAdditionalLevelSaveData
@Internal public static void readAdditionalLevelSaveData(CompoundTag rootTag, @Nullable Path levelPath) - Parameters:
rootTag
- Level data file contents.levelPath
- Level currently being loaded. TODO 1.20 - Remove nullable annotation
-
encodeLifecycle
-
parseLifecycle
-
saveMobEffect
-
loadMobEffect
@Nullable public static MobEffect loadMobEffect(CompoundTag nbt, String key, @Nullable MobEffect fallback) -
refreshBannerPatternData
public static void refreshBannerPatternData() -
getTotalPatternRows
public static int getTotalPatternRows() -
getNonPatternItemCount
public static int getNonPatternItemCount() -
getActualPatternIndex
public static int getActualPatternIndex(int index) -
shouldSuppressEnderManAnger
-
readTypedPackFormats
-
modifyLoot(ResourceLocation, List, LootContext)
instead.