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 Supplier<com.mojang.serialization.Codec<MappedRegistry<LevelStem>>>
private static ThreadLocal<Player>
private static String
private static Map<EntityType<? extends LivingEntity>,AttributeSupplier>
private static org.apache.logging.log4j.Marker
private static org.apache.logging.log4j.Logger
private static ThreadLocal<Deque<ForgeHooks.LootTableContext>>
private static String
private static Map<EntityDataSerializer<?>,DataSerializerEntry>
(package private) static Pattern
private static Map<IRegistryDelegate<Item>,Integer>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canContinueUsing(ItemStack from, ItemStack to)
static boolean
canEntityDestroy(Level world, BlockPos pos, LivingEntity entity)
static int
canEntitySpawn(Mob entity, LevelAccessor world, double x, double y, double z, BaseSpawner spawner, MobSpawnType spawnReason)
static FluidAttributes
createVanillaFluidAttributes(Fluid fluid)
static <T> void
deserializeTagAdditions(List<Tag.Entry> list, com.google.gson.JsonObject json, List<Tag.BuilderEntry> allList)
static Biome
enhanceBiome(ResourceLocation name, Biome.ClimateSettings climate, Biome.BiomeCategory category, Float depth, Float scale, BiomeSpecialEffects effects, BiomeGenerationSettings gen, MobSpawnSettings spawns, com.mojang.serialization.codecs.RecordCodecBuilder.Instance<Biome> codec, ForgeHooks.BiomeCallbackFunction callback)
static void
fixNullStructureReferences(ChunkAccess chunk, Map<StructureFeature<?>,it.unimi.dsi.fastutil.longs.LongSet> structureReferences)
Fixes MC-194811 When a structure mod is removed, this map may contain null keys.static <T> com.mojang.serialization.Dynamic<T>
fixUpDimensionsData(com.mojang.serialization.Dynamic<T> data)
Restores previously "deleted" dimensions to the world.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 EntityDataSerializer<?>
getSerializer(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla)
static int
getSerializerId(EntityDataSerializer<?> serializer, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla)
getTagFromVanillaTier(Tiers tier)
static boolean
isCorrectToolForDrops(BlockState state, Player player)
static boolean
isLivingOnLadder(BlockState state, Level world, BlockPos pos, LivingEntity entity)
static LootTable
loadLootTable(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager)
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 world, GameType gameType, ServerPlayer entityPlayer, BlockPos pos)
static boolean
onChangeGameMode(Player player, GameType currentGameMode, GameType newGameMode)
static void
onCropsGrowPost(Level worldIn, BlockPos pos, BlockState state)
static boolean
onCropsGrowPre(Level worldIn, 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 world, BlockPos pos, BlockState state, float fallDistance, Entity entity)
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 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)
static boolean
onLivingUpdate(LivingEntity entity)
static int
onNoteChange(Level world, BlockPos pos, BlockState state, int old, int _new)
static boolean
onPickBlock(HitResult target, Player player, Level world)
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)
static boolean
onTravelToDimension(Entity entity, ResourceKey<Level> dimension)
static String
readLootEntryName(com.google.gson.JsonObject json, String type)
static String
readPoolName(com.google.gson.JsonObject json)
static void
setCraftingPlayer(Player player)
static void
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
FORGEHOOKS
private static final org.apache.logging.log4j.Marker FORGEHOOKS -
URL_PATTERN
-
craftingPlayer
-
lootContext
-
serializerEntries
-
VANILLA_BURNS
-
VANILLA_DIMS
-
DIMENSIONS_KEY
- See Also:
- Constant Field Values
-
SEED_KEY
- See Also:
- Constant Field Values
-
CODEC
-
FORGE_ATTRIBUTES
-
-
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
-
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
-
getLootingLevel
-
getEntityVisibilityMultiplier
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier) -
isLivingOnLadder
public static boolean isLivingOnLadder(@Nonnull BlockState state, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull LivingEntity entity) -
onLivingJump
-
onPlayerTossEvent
@Nullable public static ItemEntity onPlayerTossEvent(@Nonnull Player player, @Nonnull ItemStack item, boolean includeName) -
onServerChatEvent
@Nullable public static Component onServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp) -
newChatWithLinks
-
newChatWithLinks
-
onBlockBreakEvent
public static int onBlockBreakEvent(Level world, GameType gameType, ServerPlayer entityPlayer, BlockPos pos) -
onPlaceItemIntoWorld
-
onAnvilChange
-
onAnvilRepair
-
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
-
getLootTableContext
-
loadLootTable
@Nullable public static LootTable loadLootTable(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) -
createVanillaFluidAttributes
-
getDefaultWorldType
-
getTagFromVanillaTier
-
enhanceBiome
public static Biome enhanceBiome(@Nullable ResourceLocation name, Biome.ClimateSettings climate, Biome.BiomeCategory category, Float depth, Float scale, 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. -
getDefaultCreatorModId
Used as the default implementation ofIForgeItem.getCreatorModId(net.minecraft.world.item.ItemStack)
. Call that method instead. -
onFarmlandTrample
public static boolean onFarmlandTrample(Level world, 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) -
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<StructureFeature<?>,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 -
fixUpDimensionsData
public static <T> com.mojang.serialization.Dynamic<T> fixUpDimensionsData(com.mojang.serialization.Dynamic<T> data)Restores previously "deleted" dimensions to the world. TheLenientUnboundedMapCodec
prevents this from happening, this is to fix any world from before the fix. TODO: Remove in 1.18 -
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
-
modifyLoot(ResourceLocation, List, LootContext)
instead.