Class 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 final String
(package private) static final Pattern
private static final Map<Holder.Reference<Item>,
Integer> private static final org.apache.logging.log4j.Marker
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canContinueUsing
(@NotNull ItemStack from, @NotNull ItemStack to) static boolean
canEntityDestroy
(Level level, BlockPos pos, LivingEntity entity) static boolean
static <T> void
deserializeTagAdditions
(List<TagEntry> list, com.google.gson.JsonObject json, List<TagEntry> allList) static String
encodeLifecycle
(com.mojang.serialization.Lifecycle lifecycle) 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, @Nullable RecipeType<?> recipeType) Gets the burn time of this itemstack.static Player
static @NotNull ItemStack
getCraftingRemainingItem
(@NotNull ItemStack stack) static @Nullable CriticalHitEvent
getCriticalHit
(Player player, Entity target, boolean vanillaCritical, float damageModifier) static @Nullable String
getDefaultCreatorModId
(@NotNull ItemStack itemStack) Used as the default implementation ofIForgeItem.getCreatorModId(net.minecraft.world.item.ItemStack)
.static double
getEntityVisibilityMultiplier
(LivingEntity entity, Entity lookingEntity, double originalMultiplier) static int
getLootingLevel
(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) static int
getLootingLevel
(LivingEntity target, @Nullable DamageSource cause, int level) private static ForgeHooks.LootTableContext
static ItemStack
getProjectile
(LivingEntity entity, ItemStack projectileWeaponItem, ItemStack projectile) Hook to fireLivingGetProjectileEvent
.private static String
getRawText
(Component message) static @Nullable EntityDataSerializer<?>
getSerializer
(int id, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) static int
getSerializerId
(EntityDataSerializer<?> serializer, CrudeIncrementalIntIdentityHashBiMap<EntityDataSerializer<?>> vanilla) static @NotNull ChatDecorator
getTagFromVanillaTier
(Tiers tier) static FluidType
getVanillaFluidType
(Fluid fluid) Returns a vanilla fluid type for the given fluid.static boolean
hasNoElements
(Ingredient ingredient) static boolean
isCorrectToolForDrops
(@NotNull BlockState state, @NotNull Player player) isLivingOnLadder
(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull LivingEntity entity) static @Nullable LootTable
loadLootTable
(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) static @Nullable MobEffect
loadMobEffect
(CompoundTag nbt, String key, @Nullable MobEffect fallback) private static String
makePackFormatKey
(PackType packType) static void
Deprecated.modifyLoot
(List<ItemStack> list, LootContext context) Deprecated.static it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack>
modifyLoot
(ResourceLocation lootTableId, it.unimi.dsi.fastutil.objects.ObjectArrayList<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) Deprecated, for removal: This API element is subject to removal in a future version.SeeForgeEventFactory.onAdvancementEarnedEvent(net.minecraft.world.entity.player.Player, net.minecraft.advancements.Advancement)
andForgeEventFactory.onAdvancementProgressedEvent(net.minecraft.world.entity.player.Player, net.minecraft.advancements.Advancement, net.minecraft.advancements.AdvancementProgress, java.lang.String, net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementProgressEvent.ProgressType)
static boolean
onAnvilChange
(AnvilMenu container, @NotNull ItemStack left, @NotNull ItemStack right, Container outputSlot, String name, int baseCost, Player player) static float
onAnvilRepair
(Player player, @NotNull ItemStack output, @NotNull ItemStack left, @NotNull ItemStack right) static int
onBlockBreakEvent
(Level level, GameType gameType, ServerPlayer entityPlayer, BlockPos pos) static @Nullable GameType
onChangeGameType
(Player player, GameType currentGameType, GameType newGameType) static Collection<CreativeModeTab>
onCheckCreativeTabs
(CreativeModeTab... vanillaTabs) 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
(@NotNull ItemStack top, @NotNull 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) static boolean
onItemStackedOn
(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess) 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 @org.jetbrains.annotations.Nullable 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
onLivingTick
(LivingEntity entity) static boolean
onLivingUseTotem
(LivingEntity entity, DamageSource damageSource, ItemStack totem, InteractionHand hand) static int
onNoteChange
(Level level, BlockPos pos, BlockState state, int old, int _new) static InteractionResult
onPlaceItemIntoWorld
(@NotNull UseOnContext context) static boolean
onPlayerAttack
(LivingEntity entity, DamageSource src, float amount) static boolean
onPlayerAttackTarget
(Player player, Entity target) static @Nullable ItemEntity
onPlayerTossEvent
(@NotNull Player player, @NotNull ItemStack item, boolean includeName) onRightClickBlock
(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) static @Nullable Component
onServerChatSubmittedEvent
(ServerPlayer player, String plain, Component decorated) static ShieldBlockEvent
onShieldBlock
(LivingEntity blocker, DamageSource source, float blocked) static boolean
onTravelToDimension
(Entity entity, ResourceKey<Level> dimension) static boolean
onVanillaGameEvent
(Level level, GameEvent vanillaEvent, Vec3 pos, GameEvent.Context context) static com.mojang.serialization.Lifecycle
parseLifecycle
(String lifecycle) static String
prefixNamespace
(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
(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, LevelStorageSource.LevelDirectory levelDirectory) 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
saveMobEffect
(CompoundTag nbt, String key, MobEffect effect) static void
setCraftingPlayer
(Player player) static boolean
shouldSuppressEnderManAnger
(EnderMan enderMan, Player player, ItemStack mask) static void
static <T> HolderLookup.RegistryLookup<T>
wrapRegistryLookup
(HolderLookup.RegistryLookup<T> lookup) static void
writeAdditionalLevelSaveData
(WorldData worldData, CompoundTag levelTag) static void
writeTypedPackFormats
(com.google.gson.JsonObject json, PackMetadataSection section)
-
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
-
VANILLA_BURNS
-
VANILLA_DIMS
-
DIMENSIONS_KEY
- See Also:
-
SEED_KEY
- See Also:
-
FORGE_ATTRIBUTES
-
FORGE_CONVERSION_MAP
private static final Lazy<Map<String,StructuresBecomeConfiguredFix.Conversion>> FORGE_CONVERSION_MAP
-
-
Constructor Details
-
ForgeHooks
public ForgeHooks()
-
-
Method Details
-
canContinueUsing
-
isCorrectToolForDrops
public static boolean isCorrectToolForDrops(@NotNull @NotNull BlockState state, @NotNull @NotNull Player player) -
onItemStackedOn
public static boolean onItemStackedOn(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess) -
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) -
onLivingTick
-
onLivingAttack
-
onPlayerAttack
-
onLivingKnockBack
public static LivingKnockBackEvent onLivingKnockBack(LivingEntity target, float strength, double ratioX, double ratioZ) -
onLivingUseTotem
public static boolean onLivingUseTotem(LivingEntity entity, DamageSource damageSource, ItemStack totem, InteractionHand hand) -
onLivingHurt
-
onLivingDamage
-
onLivingDeath
-
onLivingDrops
public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) -
onLivingFall
@Nullable public static @org.jetbrains.annotations.Nullable float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) -
getLootingLevel
public static int getLootingLevel(Entity target, @Nullable @Nullable Entity killer, @Nullable @Nullable DamageSource cause) -
getLootingLevel
public static int getLootingLevel(LivingEntity target, @Nullable @Nullable DamageSource cause, int level) -
getEntityVisibilityMultiplier
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier) -
isLivingOnLadder
public static Optional<BlockPos> isLivingOnLadder(@NotNull @NotNull BlockState state, @NotNull @NotNull Level level, @NotNull @NotNull BlockPos pos, @NotNull @NotNull LivingEntity entity) -
onLivingJump
-
onPlayerTossEvent
@Nullable public static @Nullable ItemEntity onPlayerTossEvent(@NotNull @NotNull Player player, @NotNull @NotNull ItemStack item, boolean includeName) -
onVanillaGameEvent
public static boolean onVanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 pos, GameEvent.Context context) -
getRawText
-
onServerChatSubmittedEvent
@Nullable public static @Nullable Component onServerChatSubmittedEvent(ServerPlayer player, String plain, Component decorated) -
getServerChatSubmittedDecorator
-
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
-
getCraftingRemainingItem
-
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
-
onChangeGameType
@Nullable public static @Nullable 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 @Nullable LootTable loadLootTable(com.google.gson.Gson gson, ResourceLocation name, com.google.gson.JsonElement data, boolean custom, LootTables lootTableManager) -
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
-
getTagFromVanillaTier
-
onCheckCreativeTabs
-
readPoolName
-
readLootEntryName
-
onCropsGrowPre
-
onCropsGrowPost
-
getCriticalHit
@Nullable public static @Nullable CriticalHitEvent getCriticalHit(Player player, Entity target, boolean vanillaCritical, float damageModifier) -
onAdvancement
@Deprecated(forRemoval=true, since="1.19.2") public static void onAdvancement(ServerPlayer player, Advancement advancement) Deprecated, for removal: This API element is subject to removal in a future version.SeeForgeEventFactory.onAdvancementEarnedEvent(net.minecraft.world.entity.player.Player, net.minecraft.advancements.Advancement)
andForgeEventFactory.onAdvancementProgressedEvent(net.minecraft.world.entity.player.Player, net.minecraft.advancements.Advancement, net.minecraft.advancements.AdvancementProgress, java.lang.String, net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementProgressEvent.ProgressType)
-
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
@Nullable public static @Nullable String getDefaultCreatorModId(@NotNull @NotNull ItemStack itemStack) 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
-
hasNoElements
-
deserializeTagAdditions
-
getSerializer
@Nullable public static @Nullable 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.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<ItemStack> modifyLoot(ResourceLocation lootTableId, it.unimi.dsi.fastutil.objects.ObjectArrayList<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
-
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) -
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, LevelStorageSource.LevelDirectory)
instead. -
readAdditionalLevelSaveData
@Internal public static void readAdditionalLevelSaveData(CompoundTag rootTag, @Nullable LevelStorageSource.LevelDirectory levelDirectory) - Parameters:
rootTag
- Level data file contents.levelDirectory
- Level currently being loaded. TODO 1.20 - Remove nullable annotation
-
encodeLifecycle
-
parseLifecycle
-
saveMobEffect
-
loadMobEffect
@Nullable public static @Nullable MobEffect loadMobEffect(CompoundTag nbt, String key, @Nullable @Nullable MobEffect fallback) -
shouldSuppressEnderManAnger
-
readTypedPackFormats
-
writeTypedPackFormats
public static void writeTypedPackFormats(com.google.gson.JsonObject json, PackMetadataSection section) -
makePackFormatKey
-
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> HolderLookup.RegistryLookup<T> wrapRegistryLookup(HolderLookup.RegistryLookup<T> lookup)
-
modifyLoot(ResourceLocation, ObjectArrayList, LootContext)
instead.