Package net.minecraftforge.common
Class ForgeHooks
java.lang.Object
net.minecraftforge.common.ForgeHooks
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ThreadLocal<Player>private static final Stringprivate static final Map<EntityType<? extends LivingEntity>,AttributeSupplier> private static final Lazy<Map<String,StructuresBecomeConfiguredFix.Conversion>> private static final org.apache.logging.log4j.Markerprivate static final org.apache.logging.log4j.Loggerprivate static ThreadLocal<Deque<ForgeHooks.LootTableContext>>private static BannerPattern[]private static final Stringprivate static Map<EntityDataSerializer<?>,DataSerializerEntry> private static int(package private) static final Patternprivate static final Map<IRegistryDelegate<Item>,Integer> private static final org.apache.logging.log4j.Marker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanContinueUsing(ItemStack from, ItemStack to) static booleancanEntityDestroy(Level level, BlockPos pos, LivingEntity entity) static intcanEntitySpawn(Mob entity, LevelAccessor world, double x, double y, double z, BaseSpawner spawner, MobSpawnType spawnReason) static FluidAttributesstatic <T> voiddeserializeTagAdditions(List<Tag.Entry> list, com.google.gson.JsonObject json, List<Tag.BuilderEntry> allList) static StringencodeLifecycle(com.mojang.serialization.Lifecycle lifecycle) static BiomeenhanceBiome(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 voidfixNullStructureReferences(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 intgetActualPatternIndex(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 intgetBurnTime(ItemStack stack, RecipeType<?> recipeType) Gets the burn time of this itemstack.static ItemStackgetContainerItem(ItemStack stack) static Playerstatic CriticalHitEventgetCriticalHit(Player player, Entity target, boolean vanillaCritical, float damageModifier) static StringgetDefaultCreatorModId(ItemStack itemStack) Used as the default implementation ofIForgeItem.getCreatorModId(net.minecraft.world.item.ItemStack).static Stringstatic doublegetEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier) static intgetLootingLevel(Entity target, Entity killer, DamageSource cause) static intgetLootingLevel(LivingEntity target, DamageSource cause, int level) private static ForgeHooks.LootTableContextstatic intstatic ItemStackgetProjectile(LivingEntity entity, ItemStack projectileWeaponItem, ItemStack projectile) Hook to fireLivingGetProjectileEvent.static EntityDataSerializer<?>getSerializer(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) static intgetSerializerId(EntityDataSerializer<?> serializer, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) getTagFromVanillaTier(Tiers tier) static intstatic booleanhasNoElements(Ingredient ingredient) static booleanisCorrectToolForDrops(BlockState state, Player player) isLivingOnLadder(BlockState state, Level level, BlockPos pos, LivingEntity entity) static WorldGenSettingsCalled when dimension jsons are parsed.static LootTableloadLootTable(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) static MobEffectloadMobEffect(CompoundTag nbt, String key, MobEffect fallback) static voidDeprecated.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 ComponentnewChatWithLinks(String string) static ComponentnewChatWithLinks(String string, boolean allowMissingHeader) static voidonAdvancement(ServerPlayer player, Advancement advancement) static booleanonAnvilChange(AnvilMenu container, ItemStack left, ItemStack right, Container outputSlot, String name, int baseCost, Player player) static floatonAnvilRepair(Player player, ItemStack output, ItemStack left, ItemStack right) static intonBlockBreakEvent(Level level, GameType gameType, ServerPlayer entityPlayer, BlockPos pos) static booleanonChangeGameMode(Player player, GameType currentGameMode, GameType newGameMode) Deprecated, for removal: This API element is subject to removal in a future version.static GameTypeonChangeGameType(Player player, GameType currentGameType, GameType newGameType) static voidonCropsGrowPost(Level level, BlockPos pos, BlockState state) static booleanonCropsGrowPre(Level level, BlockPos pos, BlockState state, boolean def) static voidonDifficultyChange(Difficulty difficulty, Difficulty oldDifficulty) static voidonEmptyClick(Player player, InteractionHand hand) static voidonEmptyLeftClick(Player player) static voidonEntityEnterSection(Entity entity, long packedOldPos, long packedNewPos) static booleanonFarmlandTrample(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity) static intonGrindstoneChange(ItemStack top, ItemStack bottom, Container outputSlot, int xp) static booleanonGrindstoneTake(Container inputSlots, ContainerLevelAccess access, Function<Level, Integer> xpFunction) static InteractionResultonInteractEntity(Player player, Entity entity, InteractionHand hand) static InteractionResultonInteractEntityAt(Player player, Entity entity, HitResult ray, InteractionHand hand) static InteractionResultonInteractEntityAt(Player player, Entity entity, Vec3 vec3d, InteractionHand hand) static InteractionResultonItemRightClick(Player player, InteractionHand hand) onLeftClickBlock(Player player, BlockPos pos, Direction face) static booleanonLivingAttack(LivingEntity entity, DamageSource src, float amount) static LivingChangeTargetEventonLivingChangeTarget(LivingEntity entity, LivingEntity originalTarget, LivingChangeTargetEvent.ILivingTargetType targetType) static floatonLivingDamage(LivingEntity entity, DamageSource src, float amount) static booleanonLivingDeath(LivingEntity entity, DamageSource src) static booleanonLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) static float[]onLivingFall(LivingEntity entity, float distance, float damageMultiplier) static floatonLivingHurt(LivingEntity entity, DamageSource src, float amount) static voidonLivingJump(LivingEntity entity) static LivingKnockBackEventonLivingKnockBack(LivingEntity target, float strength, double ratioX, double ratioZ) static voidonLivingSetAttackTarget(LivingEntity entity, LivingEntity target) Deprecated, for removal: This API element is subject to removal in a future version.static voidonLivingSetAttackTarget(LivingEntity entity, LivingEntity target, LivingChangeTargetEvent.ILivingTargetType targetType) Deprecated, for removal: This API element is subject to removal in a future version.static booleanonLivingUpdate(LivingEntity entity) static intonNoteChange(Level level, BlockPos pos, BlockState state, int old, int _new) static booleanonPickBlock(HitResult target, Player player, Level level) Called when a player uses 'pick block', calls new Entity and Block hooks.static InteractionResultonPlaceItemIntoWorld(UseOnContext context) static booleanonPlayerAttack(LivingEntity entity, DamageSource src, float amount) static booleanonPlayerAttackTarget(Player player, Entity target) static ItemEntityonPlayerTossEvent(Player player, ItemStack item, boolean includeName) onRightClickBlock(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) static ComponentonServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp) Deprecated.static ServerChatEventonServerChatEvent(ServerGamePacketListenerImpl net, String raw, Component comp, String filtered, Component filteredComp) static ShieldBlockEventonShieldBlock(LivingEntity blocker, DamageSource source, float blocked) static booleanonTravelToDimension(Entity entity, ResourceKey<Level> dimension) static booleanonVanillaGameEvent(Level level, Entity cause, GameEvent vanillaEvent, BlockPos position) static com.mojang.serialization.LifecycleparseLifecycle(String lifecycle) static voidreadAdditionalLevelSaveData(CompoundTag rootTag) Deprecated, for removal: This API element is subject to removal in a future version.To be removed in 1.20.static voidreadAdditionalLevelSaveData(CompoundTag rootTag, Path levelPath) static StringreadLootEntryName(com.google.gson.JsonObject json, String type) static StringreadPoolName(com.google.gson.JsonObject json) readTypedPackFormats(com.google.gson.JsonObject json) static voidstatic voidsaveMobEffect(CompoundTag nbt, String key, MobEffect effect) static voidsetCraftingPlayer(Player player) static booleanshouldSuppressEnderManAnger(EnderMan enderMan, Player player, ItemStack mask) static voidstatic voidwriteAdditionalLevelSaveData(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.