mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -10,12 +10,11 @@ import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* AnvilUpdateEvent is fired when the inputs (either input stack, or the name) to an anvil are changed. <br>
|
||||
*
|
||||
* AnvilUpdateEvent is fired when the inputs (either input stack, or the name) to an anvil are changed. <br>
|
||||
* It is called from {@link AnvilMenu#createResult()}. <br>
|
||||
* If the event is canceled, vanilla behavior will not run, and the output will be set to {@link ItemStack#EMPTY}. <br>
|
||||
* If the event is not canceled, but the output is not empty, it will set the output and not run vanilla behavior. <br>
|
||||
@@ -78,7 +77,7 @@ public class AnvilUpdateEvent extends Event
|
||||
* If this event is cancelled, this output stack is discarded.
|
||||
* @return The item to set in the output (rightmost) anvil slot.
|
||||
*/
|
||||
public ItemStack getOutput()
|
||||
public ItemStack getOutput()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
@@ -93,7 +92,7 @@ public class AnvilUpdateEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the level cost of this anvil operation. <br>
|
||||
* This is the level cost of this anvil operation. <br>
|
||||
* When unchanged, it is guaranteed to be left.getRepairCost() + right.getRepairCost().
|
||||
* @return The level cost of this anvil operation.
|
||||
*/
|
||||
|
||||
@@ -10,17 +10,14 @@ import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.network.chat.ChatSender;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
@@ -35,15 +32,12 @@ import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.monster.Zombie;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.Player.BedSleepingProblem;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@@ -71,16 +65,12 @@ import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
import net.minecraft.world.level.storage.PlayerDataStorage;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
||||
import net.minecraftforge.client.event.RenderBlockOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
|
||||
@@ -93,7 +83,6 @@ import net.minecraftforge.event.entity.EntityMobGriefingEvent;
|
||||
import net.minecraftforge.event.entity.EntityMountEvent;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.event.entity.EntityTeleportEvent;
|
||||
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
||||
import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemExpireEvent;
|
||||
import net.minecraftforge.event.entity.living.AnimalTameEvent;
|
||||
@@ -121,10 +110,8 @@ import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent;
|
||||
import net.minecraftforge.event.entity.player.UseHoeEvent;
|
||||
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.BlockToolInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.BlockToolModificationEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent;
|
||||
@@ -139,6 +126,8 @@ import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForgeEventFactory
|
||||
{
|
||||
@@ -151,7 +140,7 @@ public class ForgeEventFactory
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onBlockPlace(@Nullable Entity entity, @Nonnull BlockSnapshot blockSnapshot, @Nonnull Direction direction)
|
||||
public static boolean onBlockPlace(@Nullable Entity entity, @NotNull BlockSnapshot blockSnapshot, @NotNull Direction direction)
|
||||
{
|
||||
BlockState placedAgainst = blockSnapshot.getLevel().getBlockState(blockSnapshot.getPos().relative(direction.getOpposite()));
|
||||
EntityPlaceEvent event = new BlockEvent.EntityPlaceEvent(blockSnapshot, placedAgainst, entity);
|
||||
@@ -178,7 +167,7 @@ public class ForgeEventFactory
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getNewSpeed());
|
||||
}
|
||||
|
||||
public static void onPlayerDestroyItem(Player player, @Nonnull ItemStack stack, @Nullable InteractionHand hand)
|
||||
public static void onPlayerDestroyItem(Player player, @NotNull ItemStack stack, @Nullable InteractionHand hand)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand));
|
||||
}
|
||||
@@ -192,21 +181,6 @@ public class ForgeEventFactory
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static boolean canEntitySpawnSpawner(Mob entity, Level level, float x, float y, float z, BaseSpawner spawner)
|
||||
{
|
||||
Result result = canEntitySpawn(entity, level, x, y, z, spawner, MobSpawnType.SPAWNER);
|
||||
if (result == Result.DEFAULT)
|
||||
return entity.checkSpawnRules(level, MobSpawnType.SPAWNER) && entity.checkSpawnObstruction(level); // vanilla logic (inverted)
|
||||
else
|
||||
return result == Result.ALLOW;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static boolean doSpecialSpawn(Mob entity, Level level, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
return doSpecialSpawn(entity, (LevelAccessor)level, x, y, z, spawner, spawnReason);
|
||||
}
|
||||
public static boolean doSpecialSpawn(Mob entity, LevelAccessor level, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, level, x, y, z, spawner, spawnReason));
|
||||
@@ -219,7 +193,7 @@ public class ForgeEventFactory
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
public static int getItemBurnTime(@Nonnull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType)
|
||||
public static int getItemBurnTime(@NotNull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType)
|
||||
{
|
||||
FurnaceFuelBurnTimeEvent event = new FurnaceFuelBurnTimeEvent(itemStack, burnTime, recipeType);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
@@ -333,56 +307,27 @@ public class ForgeEventFactory
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onClientChat(ChatType type, Component message, @Nullable UUID senderUUID)
|
||||
public static Component onClientChat(ChatType type, Component message, ChatSender chatSender)
|
||||
{
|
||||
ClientChatReceivedEvent event = new ClientChatReceivedEvent(type, message, senderUUID);
|
||||
ClientChatReceivedEvent event = new ClientChatReceivedEvent(type, message, chatSender);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public static String onClientSendMessage(String message)
|
||||
{
|
||||
ClientChatEvent event = new ClientChatEvent(message);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? "" : event.getMessage();
|
||||
}
|
||||
|
||||
//TODO 1.19: Remove
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static int onHoeUse(UseOnContext context)
|
||||
{
|
||||
UseHoeEvent event = new UseHoeEvent(context);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
|
||||
if (event.getResult() == Result.ALLOW)
|
||||
{
|
||||
context.getItemInHand().hurtAndBreak(1, context.getPlayer(), player -> player.broadcastBreakEvent(context.getHand()));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BlockState onToolUse(BlockState originalState, UseOnContext context, ToolAction toolAction, boolean simulate)
|
||||
{
|
||||
// TODO 1.19: Remove ternary and just use BlockToolModificationEvent constructor with simulate parameter passed in
|
||||
BlockToolModificationEvent event = simulate
|
||||
? new BlockToolModificationEvent(originalState, context, toolAction, true)
|
||||
: new BlockToolInteractEvent(originalState, context, toolAction);
|
||||
BlockToolModificationEvent event = new BlockToolModificationEvent(originalState, context, toolAction, simulate);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getFinalState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onToolUse(BlockState, UseOnContext, ToolAction, boolean)} instead.
|
||||
*/
|
||||
@Nullable
|
||||
// TODO 1.19: Remove
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static BlockState onToolUse(BlockState originalState, Level level, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
BlockToolInteractEvent event = new BlockToolInteractEvent(level, pos, originalState, player, stack, toolAction);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getFinalState();
|
||||
}
|
||||
|
||||
public static int onApplyBonemeal(@Nonnull Player player, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull ItemStack stack)
|
||||
public static int onApplyBonemeal(@NotNull Player player, @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ItemStack stack)
|
||||
{
|
||||
BonemealEvent event = new BonemealEvent(player, level, pos, state, stack);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
|
||||
@@ -396,7 +341,7 @@ public class ForgeEventFactory
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InteractionResultHolder<ItemStack> onBucketUse(@Nonnull Player player, @Nonnull Level level, @Nonnull ItemStack stack, @Nullable HitResult target)
|
||||
public static InteractionResultHolder<ItemStack> onBucketUse(@NotNull Player player, @NotNull Level level, @NotNull ItemStack stack, @Nullable HitResult target)
|
||||
{
|
||||
FillBucketEvent event = new FillBucketEvent(player, stack, level, target);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return new InteractionResultHolder<ItemStack>(InteractionResult.FAIL, stack);
|
||||
@@ -418,21 +363,22 @@ public class ForgeEventFactory
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canEntityUpdate(Entity entity)
|
||||
public static PlayLevelSoundEvent.AtEntity onPlaySoundAtEntity(Entity entity, SoundEvent name, SoundSource category, float volume, float pitch)
|
||||
{
|
||||
EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(entity);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getCanUpdate();
|
||||
}
|
||||
|
||||
public static PlaySoundAtEntityEvent onPlaySoundAtEntity(Entity entity, SoundEvent name, SoundSource category, float volume, float pitch)
|
||||
{
|
||||
PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(entity, name, category, volume, pitch);
|
||||
PlayLevelSoundEvent.AtEntity event = new PlayLevelSoundEvent.AtEntity(entity, name, category, volume, pitch);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static int onItemExpire(ItemEntity entity, @Nonnull ItemStack item)
|
||||
|
||||
public static PlayLevelSoundEvent.AtPosition onPlaySoundAtPosition(Level level, double x, double y, double z, SoundEvent name, SoundSource category, float volume, float pitch)
|
||||
{
|
||||
PlayLevelSoundEvent.AtPosition event = new PlayLevelSoundEvent.AtPosition(level, new Vec3(x, y, z), name, category, volume, pitch);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static int onItemExpire(ItemEntity entity, @NotNull ItemStack item)
|
||||
{
|
||||
if (item.isEmpty()) return -1;
|
||||
ItemExpireEvent event = new ItemExpireEvent(entity, (item.isEmpty() ? 6000 : item.getItem().getEntityLifespan(item, entity.level)));
|
||||
@@ -465,7 +411,7 @@ public class ForgeEventFactory
|
||||
return MinecraftForge.EVENT_BUS.post(new AnimalTameEvent(animal, tamer));
|
||||
}
|
||||
|
||||
public static BedSleepingProblem onPlayerSleepInBed(Player player, Optional<BlockPos> pos)
|
||||
public static Player.BedSleepingProblem onPlayerSleepInBed(Player player, Optional<BlockPos> pos)
|
||||
{
|
||||
PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, pos);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
@@ -556,24 +502,6 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerBrewedPotionEvent(player, stack));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static boolean renderFireOverlay(Player player, PoseStack mat)
|
||||
{
|
||||
return renderBlockOverlay(player, mat, OverlayType.FIRE, Blocks.FIRE.defaultBlockState(), player.blockPosition());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static boolean renderWaterOverlay(Player player, PoseStack mat)
|
||||
{
|
||||
return renderBlockOverlay(player, mat, OverlayType.WATER, Blocks.WATER.defaultBlockState(), player.blockPosition());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static boolean renderBlockOverlay(Player player, PoseStack mat, OverlayType type, BlockState block, BlockPos pos)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderBlockOverlayEvent(player, mat, type, block, pos));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends ICapabilityProvider> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider)
|
||||
{
|
||||
@@ -688,7 +616,7 @@ public class ForgeEventFactory
|
||||
return result == Result.DEFAULT ? level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) : result == Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean saplingGrowTree(LevelAccessor level, Random rand, BlockPos pos)
|
||||
public static boolean saplingGrowTree(LevelAccessor level, RandomSource rand, BlockPos pos)
|
||||
{
|
||||
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, rand, pos);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
@@ -865,33 +793,11 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.PlayerTickEvent(TickEvent.Phase.END, player));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link #onPreWorldTick(Level, BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static void onPreWorldTick(Level level)
|
||||
{
|
||||
onPreWorldTick(level, () -> false);
|
||||
}
|
||||
|
||||
public static void onPreWorldTick(Level level, BooleanSupplier haveTime)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.WorldTickEvent(LogicalSide.SERVER, TickEvent.Phase.START, level, haveTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link #onPostWorldTick(Level, BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static void onPostWorldTick(Level level)
|
||||
{
|
||||
onPostWorldTick(level, () -> false);
|
||||
}
|
||||
|
||||
public static void onPostWorldTick(Level level, BooleanSupplier haveTime)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.WorldTickEvent(LogicalSide.SERVER, TickEvent.Phase.END, level, haveTime));
|
||||
@@ -907,33 +813,11 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.ClientTickEvent(TickEvent.Phase.END));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link #onPreServerTick(BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static void onPreServerTick()
|
||||
{
|
||||
onPreServerTick(() -> false);
|
||||
}
|
||||
|
||||
public static void onPreServerTick(BooleanSupplier haveTime)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.ServerTickEvent(TickEvent.Phase.START, haveTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link #onPostServerTick(BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public static void onPostServerTick()
|
||||
{
|
||||
onPostServerTick(() -> false);
|
||||
}
|
||||
|
||||
public static void onPostServerTick(BooleanSupplier haveTime)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TickEvent.ServerTickEvent(TickEvent.Phase.END, haveTime));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* A simple marker event that notifies when the game is about to close.
|
||||
* Fires once on the physical client and physical server.
|
||||
* Does not fire for the Integrated Server on a physical Client.
|
||||
*
|
||||
* On the client, the GL Context is still valid when the event is fired.
|
||||
* Fired on the FORGE event bus.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
public class GameShuttingDownEvent extends Event
|
||||
{
|
||||
public GameShuttingDownEvent() {}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Fires when a player joins the server or when the reload command is ran,
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* PlayLevelSoundEvent is fired when a sound is played on a {@link Level}.
|
||||
* This event is fired from {@link Level#playSound}, {@link Level#playSeededSound}, and {@link LocalPlayer#playSound}.
|
||||
* <p>
|
||||
* {@link #getLevel()} contains the level the sound is being played in.
|
||||
* {@link #getSound()} contains the sound event to be played.
|
||||
* {@link #getOriginalVolume()} contains the original volume for the sound to be played at.
|
||||
* {@link #getOriginalPitch()} contains the original pitch for the sound to be played at.
|
||||
* {@link #getNewVolume()} contains the volume the sound will be played at.
|
||||
* {@link #getNewPitch()} contains the pitch the sound will be played at.
|
||||
* <p>
|
||||
* This event is {@link Cancelable cancelable}.
|
||||
* If this event is canceled, the sound is not played.
|
||||
* <p>
|
||||
* This event does not have a result.
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public class PlayLevelSoundEvent extends Event
|
||||
{
|
||||
private final Level level;
|
||||
private final float originalVolume;
|
||||
private final float originalPitch;
|
||||
private SoundEvent sound;
|
||||
private SoundSource source;
|
||||
private float newVolume;
|
||||
private float newPitch;
|
||||
|
||||
public PlayLevelSoundEvent(@NotNull Level level, @NotNull SoundEvent sound, @NotNull SoundSource source, float volume, float pitch)
|
||||
{
|
||||
this.level = level;
|
||||
this.sound = sound;
|
||||
this.source = source;
|
||||
this.originalVolume = volume;
|
||||
this.originalPitch = pitch;
|
||||
this.newVolume = volume;
|
||||
this.newPitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level the sound is being played in}
|
||||
*/
|
||||
@NotNull
|
||||
public Level getLevel()
|
||||
{
|
||||
return this.level;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sound event to be played}
|
||||
*/
|
||||
@Nullable
|
||||
public SoundEvent getSound()
|
||||
{
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sound event to be played.
|
||||
*/
|
||||
public void setSound(@Nullable SoundEvent sound)
|
||||
{
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sound source}
|
||||
*/
|
||||
@NotNull
|
||||
public SoundSource getSource()
|
||||
{
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sound source.
|
||||
*/
|
||||
public void setSource(@NotNull SoundSource source)
|
||||
{
|
||||
Objects.requireNonNull(source, "Sound source cannot be null");
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original volume for the sound to be played at}
|
||||
*/
|
||||
public float getOriginalVolume()
|
||||
{
|
||||
return this.originalVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original pitch for the sound to be played at}
|
||||
*/
|
||||
public float getOriginalPitch()
|
||||
{
|
||||
return this.originalPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the volume the sound will be played at}
|
||||
*/
|
||||
public float getNewVolume()
|
||||
{
|
||||
return this.newVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume the sound will be played at.
|
||||
*/
|
||||
public void setNewVolume(float newVolume)
|
||||
{
|
||||
this.newVolume = newVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pitch the sound will be played at}
|
||||
*/
|
||||
public float getNewPitch()
|
||||
{
|
||||
return this.newPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pitch the sound will be played at.
|
||||
*/
|
||||
public void setNewPitch(float newPitch)
|
||||
{
|
||||
this.newPitch = newPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayLevelSoundEvent.AtEntity is fired when a sound is played on the {@link Level} at an {@link Entity Entity}'s position.
|
||||
* This event is fired from {@link Level#playSound}, {@link Level#playSeededSound}, and {@link LocalPlayer#playSound}.
|
||||
* <p>
|
||||
* This event is {@link Cancelable cancelable}.
|
||||
* If this event is canceled, the sound is not played.
|
||||
* <p>
|
||||
* This event does not have a result.
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static class AtEntity extends PlayLevelSoundEvent
|
||||
{
|
||||
private final Entity entity;
|
||||
|
||||
public AtEntity(Entity entity, SoundEvent sound, SoundSource source, float volume, float pitch)
|
||||
{
|
||||
super(entity.level, sound, source, volume, pitch);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the entity the sound is being played on}
|
||||
*/
|
||||
public Entity getEntity()
|
||||
{
|
||||
return this.entity;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayLevelSoundEvent.AtPosition is fired when a sound is played on the {@link Level} at a specific position.
|
||||
* This event is fired from {@link Level#playSound} and {@link Level#playSeededSound}.
|
||||
* <p>
|
||||
* This event is {@link Cancelable cancelable}.
|
||||
* If this event is canceled, the sound is not played.
|
||||
* <p>
|
||||
* This event does not have a result.
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static class AtPosition extends PlayLevelSoundEvent
|
||||
{
|
||||
private final Vec3 position;
|
||||
|
||||
public AtPosition(Level level, Vec3 position, SoundEvent sound, SoundSource source, float volume, float pitch)
|
||||
{
|
||||
super(level, sound, source, volume, pitch);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the position the sound is being played at}
|
||||
*/
|
||||
public Vec3 getPosition()
|
||||
{
|
||||
return this.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.eventbus.api.GenericEvent;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
/**
|
||||
* RegistryEvent supertype.
|
||||
*/
|
||||
public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEvent<T> implements IModBusEvent
|
||||
{
|
||||
RegistryEvent(Class<T> clazz) {
|
||||
super(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register your objects for the appropriate registry type when you receive this event.
|
||||
*
|
||||
* <code>event.getRegistry().register(...)</code>
|
||||
*
|
||||
* The registries will be visited in alphabetic order of their name, except blocks and items,
|
||||
* which will be visited FIRST and SECOND respectively.
|
||||
*
|
||||
* ObjectHolders will reload between Blocks and Items, and after all registries have been visited.
|
||||
* @param <T> The registry top level type
|
||||
*/
|
||||
public static class Register<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
|
||||
{
|
||||
private final IForgeRegistry<T> registry;
|
||||
private final ResourceLocation name;
|
||||
|
||||
public Register(ResourceLocation name, IForgeRegistry<T> registry)
|
||||
{
|
||||
super(registry.getRegistrySuperType());
|
||||
this.name = name;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public IForgeRegistry<T> getRegistry()
|
||||
{
|
||||
return registry;
|
||||
}
|
||||
|
||||
public ResourceLocation getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RegistryEvent.Register<"+getName()+">";
|
||||
}
|
||||
}
|
||||
|
||||
public static class MissingMappings<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
|
||||
{
|
||||
private final IForgeRegistry<T> registry;
|
||||
private final ResourceLocation name;
|
||||
private final ImmutableList<Mapping<T>> mappings;
|
||||
private ModContainer activeMod;
|
||||
|
||||
public MissingMappings(ResourceLocation name, IForgeRegistry<T> registry, Collection<Mapping<T>> missed)
|
||||
{
|
||||
super(registry.getRegistrySuperType());
|
||||
this.registry = registry;
|
||||
this.name = name;
|
||||
this.mappings = ImmutableList.copyOf(missed);
|
||||
}
|
||||
|
||||
public void setModContainer(ModContainer mod)
|
||||
{
|
||||
this.activeMod = mod;
|
||||
}
|
||||
|
||||
public ResourceLocation getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public IForgeRegistry<T> getRegistry()
|
||||
{
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
/*
|
||||
* This used to be fired on the Mod specific bus, and we could tell which mod was asking for mappings.
|
||||
* It no longer is, so this method is useless and just returns getAllMappings.
|
||||
* TODO: Ask cpw how if he wants to re-enable the ModBus rethrow.
|
||||
*/
|
||||
@Deprecated
|
||||
public ImmutableList<Mapping<T>> getMappings()
|
||||
{
|
||||
return this.activeMod == null ? getAllMappings() : getMappings(this.activeMod.getModId());
|
||||
}
|
||||
|
||||
public ImmutableList<Mapping<T>> getMappings(String modid)
|
||||
{
|
||||
return ImmutableList.copyOf(this.mappings.stream().filter(e -> e.key.getNamespace().equals(modid)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public ImmutableList<Mapping<T>> getAllMappings()
|
||||
{
|
||||
return this.mappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions you can take with this missing mapping.
|
||||
* <ul>
|
||||
* <li>{@link #IGNORE} means this missing mapping will be ignored.
|
||||
* <li>{@link #WARN} means this missing mapping will generate a warning.
|
||||
* <li>{@link #FAIL} means this missing mapping will prevent the world from loading.
|
||||
* </ul>
|
||||
*/
|
||||
public enum Action
|
||||
{
|
||||
/**
|
||||
* Take the default action
|
||||
*/
|
||||
DEFAULT,
|
||||
/**
|
||||
* Ignore this missing mapping. This means the mapping will be abandoned
|
||||
*/
|
||||
IGNORE,
|
||||
/**
|
||||
* Generate a warning but allow loading to continue
|
||||
*/
|
||||
WARN,
|
||||
/**
|
||||
* Fail to load
|
||||
*/
|
||||
FAIL,
|
||||
/**
|
||||
* Remap this name to a new name (add a migration mapping)
|
||||
*/
|
||||
REMAP
|
||||
}
|
||||
|
||||
public static class Mapping<T extends IForgeRegistryEntry<T>> implements Comparable<Mapping<T>>
|
||||
{
|
||||
public final IForgeRegistry<T> registry;
|
||||
private final IForgeRegistry<T> pool;
|
||||
public final ResourceLocation key;
|
||||
public final int id;
|
||||
private Action action = Action.DEFAULT;
|
||||
private T target;
|
||||
|
||||
public Mapping(IForgeRegistry<T> registry, IForgeRegistry<T> pool, ResourceLocation key, int id)
|
||||
{
|
||||
this.registry = registry;
|
||||
this.pool = pool;
|
||||
this.key = key;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore the missing item.
|
||||
*/
|
||||
public void ignore()
|
||||
{
|
||||
action = Action.IGNORE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn the user about the missing item.
|
||||
*/
|
||||
public void warn()
|
||||
{
|
||||
action = Action.WARN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent the world from loading due to the missing item.
|
||||
*/
|
||||
public void fail()
|
||||
{
|
||||
action = Action.FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap the missing entry to the specified object.
|
||||
*
|
||||
* Use this if you have renamed an entry.
|
||||
* Existing references using the old name will point to the new one.
|
||||
*
|
||||
* @param target Entry to remap to.
|
||||
*/
|
||||
public void remap(T target)
|
||||
{
|
||||
Validate.notNull(target, "Remap target can not be null");
|
||||
Validate.isTrue(pool.getKey(target) != null, String.format(Locale.ENGLISH, "The specified entry %s hasn't been registered in registry yet.", target));
|
||||
action = Action.REMAP;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
// internal
|
||||
public Action getAction()
|
||||
{
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public T getTarget()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Mapping<T> o)
|
||||
{
|
||||
int ret = this.registry.getRegistryName().compareNamespaced(o.registry.getRegistryName());
|
||||
if (ret ==0) ret = this.key.compareNamespaced(o.key);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the ID mapping might have changed. If you register for this event, you
|
||||
* will be called back whenever the client or server loads an ID set. This includes both
|
||||
* when the ID maps are loaded from disk, as well as when the ID maps revert to the initial
|
||||
* state.
|
||||
*
|
||||
* Note: you cannot change the IDs that have been allocated, but you might want to use
|
||||
* this event to update caches or other in-mod artifacts that might be impacted by an ID
|
||||
* change.
|
||||
*
|
||||
* Fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
public static class IdMappingEvent extends Event
|
||||
{
|
||||
public static class ModRemapping
|
||||
{
|
||||
public final ResourceLocation registry;
|
||||
public final ResourceLocation key;
|
||||
public final int oldId;
|
||||
public final int newId;
|
||||
|
||||
private ModRemapping(ResourceLocation registry, ResourceLocation key, int oldId, int newId)
|
||||
{
|
||||
this.registry = registry;
|
||||
this.key = key;
|
||||
this.oldId = oldId;
|
||||
this.newId = newId;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<ResourceLocation, ImmutableList<ModRemapping>> remaps;
|
||||
private final ImmutableSet<ResourceLocation> keys;
|
||||
|
||||
public final boolean isFrozen;
|
||||
public IdMappingEvent(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, boolean isFrozen)
|
||||
{
|
||||
this.isFrozen = isFrozen;
|
||||
this.remaps = Maps.newHashMap();
|
||||
remaps.forEach((name, rm) ->
|
||||
{
|
||||
List<ModRemapping> tmp = Lists.newArrayList();
|
||||
rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value[0], value[1])));
|
||||
tmp.sort(Comparator.comparingInt(o -> o.newId));
|
||||
this.remaps.put(name, ImmutableList.copyOf(tmp));
|
||||
});
|
||||
this.keys = ImmutableSet.copyOf(this.remaps.keySet());
|
||||
}
|
||||
|
||||
public ImmutableSet<ResourceLocation> getRegistries()
|
||||
{
|
||||
return this.keys;
|
||||
}
|
||||
|
||||
public ImmutableList<ModRemapping> getRemaps(ResourceLocation registry)
|
||||
{
|
||||
return this.remaps.get(registry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.network.chat.MessageSignature;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -13,15 +14,17 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* ServerChatEvent is fired whenever a C01PacketChatMessage is processed. <br>
|
||||
* This event is fired via {@link ForgeHooks#onServerChatEvent(ServerGamePacketListenerImpl, String, Component)},
|
||||
* This event is fired via {@link ForgeHooks#onServerChatEvent(ServerPlayer, String, Component)},
|
||||
* which is executed by the {@link ServerGamePacketListenerImpl#handleChat(ServerboundChatPacket)}<br>
|
||||
* <br>
|
||||
* {@link #username} contains the username of the player sending the chat message.<br>
|
||||
* {@link #username} contains the username of the player sending the chat message, unless fired from the server, where it is null.<br>
|
||||
* {@link #message} contains the message being sent.<br>
|
||||
* {@link #player} the instance of EntityPlayerMP for the player sending the chat message.<br>
|
||||
* {@link #component} contains the instance of ChatComponentTranslation for the sent message.<br>
|
||||
* {@link #player} the instance of ServerPlayer for the player sending the chat message, or null when fired from the server.<br>
|
||||
* {@link #component} contains the instance of Component for the sent message.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}. <br>
|
||||
* If this event is canceled, the chat message is never distributed to all clients.<br>
|
||||
@@ -33,15 +36,16 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
@Cancelable
|
||||
public class ServerChatEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final String message, username;
|
||||
private final ServerPlayer player;
|
||||
private final String message;
|
||||
private final @Nullable String username;
|
||||
private final @Nullable ServerPlayer player;
|
||||
private Component component;
|
||||
public ServerChatEvent(ServerPlayer player, String message, Component component)
|
||||
public ServerChatEvent(@Nullable ServerPlayer player, String message, Component component)
|
||||
{
|
||||
super();
|
||||
this.message = message;
|
||||
this.player = player;
|
||||
this.username = player.getGameProfile().getName();
|
||||
this.username = player != null ? player.getGameProfile().getName() : null;
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
@@ -56,6 +60,6 @@ public class ServerChatEvent extends net.minecraftforge.eventbus.api.Event
|
||||
}
|
||||
|
||||
public String getMessage() { return this.message; }
|
||||
public String getUsername() { return this.username; }
|
||||
public ServerPlayer getPlayer() { return this.player; }
|
||||
public @Nullable String getUsername() { return this.username; }
|
||||
public @Nullable ServerPlayer getPlayer() { return this.player; }
|
||||
}
|
||||
@@ -34,20 +34,8 @@ public class TickEvent extends Event
|
||||
}
|
||||
|
||||
public static class ServerTickEvent extends TickEvent {
|
||||
|
||||
private final BooleanSupplier haveTime;
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link ServerTickEvent#ServerTickEvent(Phase, BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public ServerTickEvent(Phase phase)
|
||||
{
|
||||
this(phase, () -> false);
|
||||
}
|
||||
|
||||
public ServerTickEvent(Phase phase, BooleanSupplier haveTime)
|
||||
{
|
||||
super(Type.SERVER, LogicalSide.SERVER, phase);
|
||||
@@ -76,17 +64,6 @@ public class TickEvent extends Event
|
||||
public final Level world;
|
||||
private final BooleanSupplier haveTime;
|
||||
|
||||
/**
|
||||
* TODO: Remove in 1.19
|
||||
*
|
||||
* @deprecated Use {@link WorldTickEvent#WorldTickEvent(LogicalSide, Phase, Level, BooleanSupplier)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public WorldTickEvent(LogicalSide side, Phase phase, Level world)
|
||||
{
|
||||
this(side, phase, world, () -> false);
|
||||
}
|
||||
|
||||
public WorldTickEvent(LogicalSide side, Phase phase, Level world, BooleanSupplier haveTime)
|
||||
{
|
||||
super(Type.WORLD, side, phase);
|
||||
@@ -98,7 +75,7 @@ public class TickEvent extends Event
|
||||
* @return {@code true} whether the server has enough time to perform any
|
||||
* additional tasks (usually IO related) during the current tick,
|
||||
* otherwise {@code false}
|
||||
*
|
||||
*
|
||||
* @see ServerTickEvent#haveTime()
|
||||
*/
|
||||
public boolean haveTime()
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* VanillaGameEvent is fired on the server whenever one of Vanilla's {@link GameEvent GameEvents} fire. <br>
|
||||
@@ -27,17 +27,16 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
public class VanillaGameEvent extends Event
|
||||
{
|
||||
private final Level level;
|
||||
@Nullable
|
||||
private final Entity cause;
|
||||
private final GameEvent vanillaEvent;
|
||||
private final BlockPos position;
|
||||
private final Vec3 position;
|
||||
private final GameEvent.Context context;
|
||||
|
||||
public VanillaGameEvent(Level level, @Nullable Entity cause, GameEvent vanillaEvent, BlockPos position)
|
||||
public VanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 position, GameEvent.Context context)
|
||||
{
|
||||
this.level = level;
|
||||
this.cause = cause;
|
||||
this.vanillaEvent = vanillaEvent;
|
||||
this.position = position;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ public class VanillaGameEvent extends Event
|
||||
@Nullable
|
||||
public Entity getCause()
|
||||
{
|
||||
return cause;
|
||||
return context.sourceEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,10 +65,18 @@ public class VanillaGameEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position the event took place at. This may be a block or the block position of the entity targeted.
|
||||
* @return The position the event took place at.
|
||||
*/
|
||||
public BlockPos getEventPosition()
|
||||
public Vec3 getEventPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context of the vanilla event
|
||||
*/
|
||||
public GameEvent.Context getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,7 @@ package net.minecraftforge.event.brewing;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event is called when a player picks up a potion from a brewing stand.
|
||||
@@ -18,7 +17,7 @@ public class PlayerBrewedPotionEvent extends PlayerEvent
|
||||
{
|
||||
private final ItemStack stack;
|
||||
|
||||
public PlayerBrewedPotionEvent(Player player, @Nonnull ItemStack stack)
|
||||
public PlayerBrewedPotionEvent(Player player, @NotNull ItemStack stack)
|
||||
{
|
||||
super(player);
|
||||
this.stack = stack;
|
||||
@@ -27,7 +26,7 @@ public class PlayerBrewedPotionEvent extends PlayerEvent
|
||||
/**
|
||||
* The ItemStack of the potion.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return stack;
|
||||
|
||||
@@ -10,8 +10,7 @@ import net.minecraft.core.NonNullList;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PotionBrewEvent extends Event
|
||||
{
|
||||
@@ -22,14 +21,14 @@ public class PotionBrewEvent extends Event
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItem(int index)
|
||||
{
|
||||
if (index < 0 || index >= stacks.size()) return ItemStack.EMPTY;
|
||||
return stacks.get(index);
|
||||
}
|
||||
|
||||
public void setItem(int index, @Nonnull ItemStack stack)
|
||||
public void setItem(int index, @NotNull ItemStack stack)
|
||||
{
|
||||
if (index < stacks.size())
|
||||
{
|
||||
|
||||
@@ -8,8 +8,7 @@ package net.minecraftforge.event.enchanting;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Fired when the enchantment level is set for each of the three potential enchantments in the enchanting table.
|
||||
@@ -25,12 +24,12 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
private final BlockPos pos;
|
||||
private final int enchantRow;
|
||||
private final int power;
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack itemStack;
|
||||
private final int originalLevel;
|
||||
private int level;
|
||||
|
||||
public EnchantmentLevelSetEvent(Level world, BlockPos pos, int enchantRow, int power, @Nonnull ItemStack itemStack, int level)
|
||||
public EnchantmentLevelSetEvent(Level world, BlockPos pos, int enchantRow, int power, @NotNull ItemStack itemStack, int level)
|
||||
{
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
@@ -43,7 +42,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the world object
|
||||
*
|
||||
*
|
||||
* @return the world object
|
||||
*/
|
||||
public Level getWorld()
|
||||
@@ -53,7 +52,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the pos of the enchantment table
|
||||
*
|
||||
*
|
||||
* @return the pos of the enchantment table
|
||||
*/
|
||||
public BlockPos getPos()
|
||||
@@ -63,7 +62,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the row for which the enchantment level is being set
|
||||
*
|
||||
*
|
||||
* @return the row for which the enchantment level is being set
|
||||
*/
|
||||
public int getEnchantRow()
|
||||
@@ -73,7 +72,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the power (# of bookshelves) for the enchanting table
|
||||
*
|
||||
*
|
||||
* @return the power (# of bookshelves) for the enchanting table
|
||||
*/
|
||||
public int getPower()
|
||||
@@ -83,10 +82,10 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the item being enchanted
|
||||
*
|
||||
*
|
||||
* @return the item being enchanted
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItem()
|
||||
{
|
||||
return itemStack;
|
||||
@@ -94,7 +93,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the original level of the enchantment for this row (0-30)
|
||||
*
|
||||
*
|
||||
* @return the original level of the enchantment for this row (0-30)
|
||||
*/
|
||||
public int getOriginalLevel()
|
||||
@@ -104,7 +103,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Get the level of the enchantment for this row (0-30)
|
||||
*
|
||||
*
|
||||
* @return the level of the enchantment for this row (0-30)
|
||||
*/
|
||||
public int getLevel()
|
||||
@@ -114,7 +113,7 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
|
||||
|
||||
/**
|
||||
* Set the new level of the enchantment (0-30)
|
||||
*
|
||||
*
|
||||
* @param level the new level of the enchantment (0-30)
|
||||
*/
|
||||
public void setLevel(int level)
|
||||
|
||||
@@ -54,38 +54,6 @@ public class EntityEvent extends Event
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CanUpdate is fired when an Entity is being created. <br>
|
||||
* This event is fired whenever vanilla Minecraft determines that an entity<br>
|
||||
* cannot update in {@code World#updateEntityWithOptionalForce(net.minecraft.entity.Entity, boolean)} <br>
|
||||
* <br>
|
||||
* {@link CanUpdate#canUpdate} contains the boolean value of whether this entity can update.<br>
|
||||
* If the modder decides that this Entity can be updated, they may change canUpdate to true, <br>
|
||||
* and the entity with then be updated.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class CanUpdate extends EntityEvent
|
||||
{
|
||||
private boolean canUpdate = false;
|
||||
public CanUpdate(Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
|
||||
public boolean getCanUpdate()
|
||||
{
|
||||
return canUpdate;
|
||||
}
|
||||
|
||||
public void setCanUpdate(boolean canUpdate)
|
||||
{
|
||||
this.canUpdate = canUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired on server and client after an Entity has entered a different section. <br>
|
||||
* Sections are 16x16x16 block grids of the world.<br>
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
/**
|
||||
* EntityLeaveWorldEvent is fired when an Entity leaves the world. <br>
|
||||
* This event is fired whenever an Entity is removed from the world in
|
||||
* {@link ClientLevel#removeEntity(int, Entity.RemovalReason)}, {@link ServerLevel#removeEntityComplete(Entity, boolean)}. <br>
|
||||
* {@link ClientLevel#removeEntity(int, Entity.RemovalReason)}. <br>
|
||||
* <br>
|
||||
* {@link #world} contains the world from which the entity is removed. <br>
|
||||
* <br>
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* PlaySoundAtEntityEvent is fired a sound is to be played at an Entity<br>
|
||||
* This event is fired whenever a sound is set to be played at an Entity such as in
|
||||
* {@link LocalPlayer#playSound(SoundEvent, float, float)} and
|
||||
* {@link Level#playSound(Player, double, double, double, SoundEvent, SoundSource, float, float)}.<br>
|
||||
* <br>
|
||||
* {@link #name} contains the name of the sound to be played at the Entity.<br>
|
||||
* {@link #volume} contains the volume at which the sound is to be played originally.<br>
|
||||
* {@link #pitch} contains the pitch at which the sound is to be played originally.<br>
|
||||
* {@link #newVolume} contains the volume at which the sound is actually played.<br>
|
||||
* {@link #newPitch} contains the pitch at which the sound is actually played.<br>
|
||||
* Changing the {@link #name} field will cause the sound of this name to be played instead of the originally intended sound.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If this event is canceled, the sound is not played.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult} <br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public class PlaySoundAtEntityEvent extends EntityEvent
|
||||
{
|
||||
private SoundEvent name;
|
||||
private SoundSource category;
|
||||
private final float volume;
|
||||
private final float pitch;
|
||||
private float newVolume;
|
||||
private float newPitch;
|
||||
|
||||
public PlaySoundAtEntityEvent(Entity entity, SoundEvent name, SoundSource category, float volume, float pitch)
|
||||
{
|
||||
super(entity);
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
this.volume = volume;
|
||||
this.pitch = pitch;
|
||||
this.newVolume = volume;
|
||||
this.newPitch = pitch;
|
||||
}
|
||||
|
||||
public SoundEvent getSound() { return this.name; }
|
||||
public SoundSource getCategory() { return this.category; }
|
||||
public float getDefaultVolume() { return this.volume; }
|
||||
public float getDefaultPitch() { return this.pitch; }
|
||||
public float getVolume() { return this.newVolume; }
|
||||
public float getPitch() { return this.newPitch; }
|
||||
public void setSound(SoundEvent value) { this.name = value; }
|
||||
public void setCategory(SoundSource category) { this.category = category; }
|
||||
public void setVolume(float value) { this.newVolume = value; }
|
||||
public void setPitch(float value) { this.newPitch = value; }
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.world.entity.animal.Fox;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* BabyEntitySpawnEvent is fired just before a baby entity is about to be spawned. <br>
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.extensions.IForgeItem;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
|
||||
+10
-11
@@ -8,22 +8,21 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LivingEntityUseItemEvent extends LivingEvent
|
||||
{
|
||||
private final ItemStack item;
|
||||
private int duration;
|
||||
|
||||
private LivingEntityUseItemEvent(LivingEntity entity, @Nonnull ItemStack item, int duration)
|
||||
private LivingEntityUseItemEvent(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
super(entity);
|
||||
this.item = item;
|
||||
this.setDuration(duration);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItem()
|
||||
{
|
||||
return item;
|
||||
@@ -53,7 +52,7 @@ public class LivingEntityUseItemEvent extends LivingEvent
|
||||
@Cancelable
|
||||
public static class Start extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Start(LivingEntity entity, @Nonnull ItemStack item, int duration)
|
||||
public Start(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
super(entity, item, duration);
|
||||
}
|
||||
@@ -68,7 +67,7 @@ public class LivingEntityUseItemEvent extends LivingEvent
|
||||
@Cancelable
|
||||
public static class Tick extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Tick(LivingEntity entity, @Nonnull ItemStack item, int duration)
|
||||
public Tick(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
super(entity, item, duration);
|
||||
}
|
||||
@@ -89,7 +88,7 @@ public class LivingEntityUseItemEvent extends LivingEvent
|
||||
@Cancelable
|
||||
public static class Stop extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Stop(LivingEntity entity, @Nonnull ItemStack item, int duration)
|
||||
public Stop(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
super(entity, item, duration);
|
||||
}
|
||||
@@ -99,7 +98,7 @@ public class LivingEntityUseItemEvent extends LivingEvent
|
||||
* Fired after an item has fully finished being used.
|
||||
* The item has been notified that it was used, and the item/result stacks reflect after that state.
|
||||
* This means that when this is fired for a Potion, the potion effect has already been applied.
|
||||
*
|
||||
*
|
||||
* {@link LivingEntityUseItemEvent#item} is a copy of the item BEFORE it was used.
|
||||
*
|
||||
* If you wish to cancel those effects, you should cancel one of the above events.
|
||||
@@ -110,19 +109,19 @@ public class LivingEntityUseItemEvent extends LivingEvent
|
||||
public static class Finish extends LivingEntityUseItemEvent
|
||||
{
|
||||
private ItemStack result;
|
||||
public Finish(LivingEntity entity, @Nonnull ItemStack item, int duration, @Nonnull ItemStack result)
|
||||
public Finish(LivingEntity entity, @NotNull ItemStack item, int duration, @NotNull ItemStack result)
|
||||
{
|
||||
super(entity, item, duration);
|
||||
this.setResultStack(result);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getResultStack()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResultStack(@Nonnull ItemStack result)
|
||||
public void setResultStack(@NotNull ItemStack result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
+4
-5
@@ -10,8 +10,7 @@ import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* {@link LivingEquipmentChangeEvent} is fired when the Equipment of a Entity changes. <br>
|
||||
@@ -35,7 +34,7 @@ public class LivingEquipmentChangeEvent extends LivingEvent
|
||||
private final ItemStack from;
|
||||
private final ItemStack to;
|
||||
|
||||
public LivingEquipmentChangeEvent(LivingEntity entity, EquipmentSlot slot, @Nonnull ItemStack from, @Nonnull ItemStack to)
|
||||
public LivingEquipmentChangeEvent(LivingEntity entity, EquipmentSlot slot, @NotNull ItemStack from, @NotNull ItemStack to)
|
||||
{
|
||||
super(entity);
|
||||
this.slot = slot;
|
||||
@@ -44,8 +43,8 @@ public class LivingEquipmentChangeEvent extends LivingEvent
|
||||
}
|
||||
|
||||
public EquipmentSlot getSlot() { return this.slot; }
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getFrom() { return this.from; }
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getTo() { return this.to; }
|
||||
}
|
||||
@@ -12,8 +12,7 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* LivingEvent is fired whenever an event involving Living entities occurs.<br>
|
||||
|
||||
@@ -8,8 +8,7 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Event for when an entity drops experience on its death, can be used to change
|
||||
|
||||
@@ -5,18 +5,16 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.MobSpawnType;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* LivingSpawnEvent is fired for any events associated with Living Entities spawn status. <br>
|
||||
@@ -106,29 +104,20 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(Mob, LevelAccessor, float, float, float, BaseSpawner, MobSpawnType)}.<br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If this event is canceled, the Entity is not spawned.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
@Cancelable
|
||||
public static class SpecialSpawn extends LivingSpawnEvent
|
||||
{
|
||||
@Nullable
|
||||
private final BaseSpawner spawner;
|
||||
private final MobSpawnType spawnReason;
|
||||
|
||||
/**
|
||||
* @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.1")
|
||||
public SpecialSpawn(Mob entity, Level world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
this(entity, (LevelAccessor)world, x, y, z, spawner, spawnReason);
|
||||
}
|
||||
|
||||
public SpecialSpawn(Mob entity, LevelAccessor world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
|
||||
@@ -7,9 +7,8 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LootingLevelEvent extends LivingEvent {
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This Event and its subevents gets fired from {@link LivingEntity} on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
@@ -22,7 +21,7 @@ public class PotionEvent extends LivingEvent
|
||||
{
|
||||
@Nullable
|
||||
protected final MobEffectInstance effect;
|
||||
|
||||
|
||||
public PotionEvent(LivingEntity living, MobEffectInstance effect)
|
||||
{
|
||||
super(living);
|
||||
@@ -36,7 +35,7 @@ public class PotionEvent extends LivingEvent
|
||||
{
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This Event is fired when a Potion is about to get removed from an Entity.
|
||||
* This Event is {@link Cancelable}.
|
||||
@@ -46,19 +45,19 @@ public class PotionEvent extends LivingEvent
|
||||
public static class PotionRemoveEvent extends PotionEvent
|
||||
{
|
||||
private final MobEffect potion;
|
||||
|
||||
|
||||
public PotionRemoveEvent(LivingEntity living, MobEffect potion)
|
||||
{
|
||||
super(living, living.getEffect(potion));
|
||||
this.potion = potion;
|
||||
}
|
||||
|
||||
|
||||
public PotionRemoveEvent(LivingEntity living, MobEffectInstance effect)
|
||||
{
|
||||
super(living, effect);
|
||||
this.potion = effect.getEffect();
|
||||
this.potion = effect.getEffect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the Potion which is tried to remove from the Entity.
|
||||
*/
|
||||
@@ -66,7 +65,7 @@ public class PotionEvent extends LivingEvent
|
||||
{
|
||||
return this.potion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the PotionEffect. In the remove event this can be null if the Entity does not have a {@link MobEffect} of the right type active.
|
||||
*/
|
||||
@@ -77,7 +76,7 @@ public class PotionEvent extends LivingEvent
|
||||
return super.getPotionEffect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This Event is fired to check if a Potion can get applied to an Entity.
|
||||
* This Event is not {@link Cancelable}
|
||||
@@ -93,18 +92,18 @@ public class PotionEvent extends LivingEvent
|
||||
{
|
||||
super(living, effect);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the PotionEffect.
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public MobEffectInstance getPotionEffect()
|
||||
{
|
||||
return super.getPotionEffect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This Event is fired when a new Potion is added to the Entity. This is also fired if the Entity already has this effect but with different duration/level.
|
||||
* This Event is not {@link Cancelable}
|
||||
@@ -121,17 +120,17 @@ public class PotionEvent extends LivingEvent
|
||||
this.oldEffect = oldEffect;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the added PotionEffect. This is the umerged PotionEffect if the old PotionEffect is not null.
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public MobEffectInstance getPotionEffect()
|
||||
{
|
||||
return super.getPotionEffect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the old PotionEffect. THis can be null if the entity did not have an effect of this kind before.
|
||||
*/
|
||||
@@ -152,7 +151,7 @@ public class PotionEvent extends LivingEvent
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This Event is fired when a Potion effect expires on an Entity.
|
||||
* This Event is not {@link Cancelable}
|
||||
@@ -165,4 +164,4 @@ public class PotionEvent extends LivingEvent
|
||||
super(living, effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Fired when the player removes a "repaired" item from the Anvil's Output slot.
|
||||
@@ -19,15 +18,15 @@ import javax.annotation.Nonnull;
|
||||
*/
|
||||
public class AnvilRepairEvent extends PlayerEvent
|
||||
{
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack left; // The left side of the input
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack right; // The right side of the input
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack output; // Set this to set the output stack
|
||||
private float breakChance; // Anvil's chance to break (reduced by 1 durability) when this is complete. Default is 12% (0.12f)
|
||||
|
||||
public AnvilRepairEvent(Player player, @Nonnull ItemStack left, @Nonnull ItemStack right, @Nonnull ItemStack output)
|
||||
public AnvilRepairEvent(Player player, @NotNull ItemStack left, @NotNull ItemStack right, @NotNull ItemStack output)
|
||||
{
|
||||
super(player);
|
||||
this.output = output;
|
||||
@@ -40,21 +39,21 @@ public class AnvilRepairEvent extends PlayerEvent
|
||||
* Get the output result from the anvil
|
||||
* @return the output
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemResult() { return output; }
|
||||
|
||||
/**
|
||||
* Get the first item input into the anvil
|
||||
* @return the first input slot
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemInput() { return left; }
|
||||
|
||||
/**
|
||||
* Get the second item input into the anvil
|
||||
* @return the second input slot
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getIngredientInput() { return right; }
|
||||
|
||||
public float getBreakChance() { return breakChance; }
|
||||
|
||||
@@ -12,8 +12,7 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* ArrowLooseEvent is fired when a player stops using a bow.<br>
|
||||
@@ -38,7 +37,7 @@ public class ArrowLooseEvent extends PlayerEvent
|
||||
private final boolean hasAmmo;
|
||||
private int charge;
|
||||
|
||||
public ArrowLooseEvent(Player player, @Nonnull ItemStack bow, Level world, int charge, boolean hasAmmo)
|
||||
public ArrowLooseEvent(Player player, @NotNull ItemStack bow, Level world, int charge, boolean hasAmmo)
|
||||
{
|
||||
super(player);
|
||||
this.bow = bow;
|
||||
@@ -47,7 +46,7 @@ public class ArrowLooseEvent extends PlayerEvent
|
||||
this.hasAmmo = hasAmmo;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getBow() { return this.bow; }
|
||||
public Level getWorld() { return this.world; }
|
||||
public boolean hasAmmo() { return this.hasAmmo; }
|
||||
|
||||
@@ -12,8 +12,7 @@ import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* ArrowNockEvent is fired when a player begins using a bow.<br>
|
||||
@@ -30,7 +29,7 @@ public class ArrowNockEvent extends PlayerEvent
|
||||
private final boolean hasAmmo;
|
||||
private InteractionResultHolder<ItemStack> action;
|
||||
|
||||
public ArrowNockEvent(Player player, @Nonnull ItemStack item, InteractionHand hand, Level world, boolean hasAmmo)
|
||||
public ArrowNockEvent(Player player, @NotNull ItemStack item, InteractionHand hand, Level world, boolean hasAmmo)
|
||||
{
|
||||
super(player);
|
||||
this.bow = item;
|
||||
@@ -39,7 +38,7 @@ public class ArrowNockEvent extends PlayerEvent
|
||||
this.hasAmmo = hasAmmo;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getBow() { return this.bow; }
|
||||
public Level getWorld() { return this.world; }
|
||||
public InteractionHand getHand() { return this.hand; }
|
||||
|
||||
@@ -11,8 +11,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event is called when a player attempts to use Bonemeal on a block.
|
||||
@@ -33,7 +32,7 @@ public class BonemealEvent extends PlayerEvent
|
||||
private final BlockState block;
|
||||
private final ItemStack stack;
|
||||
|
||||
public BonemealEvent(@Nonnull Player player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ItemStack stack)
|
||||
public BonemealEvent(@NotNull Player player, @NotNull Level world, @NotNull BlockPos pos, @NotNull BlockState block, @NotNull ItemStack stack)
|
||||
{
|
||||
super(player);
|
||||
this.world = world;
|
||||
@@ -57,7 +56,7 @@ public class BonemealEvent extends PlayerEvent
|
||||
return block;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return stack;
|
||||
|
||||
@@ -11,9 +11,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This event is fired when a player attempts to use a Empty bucket, it
|
||||
@@ -36,7 +35,7 @@ public class FillBucketEvent extends PlayerEvent
|
||||
|
||||
private ItemStack result;
|
||||
|
||||
public FillBucketEvent(Player player, @Nonnull ItemStack current, Level world, @Nullable HitResult target)
|
||||
public FillBucketEvent(Player player, @NotNull ItemStack current, Level world, @Nullable HitResult target)
|
||||
{
|
||||
super(player);
|
||||
this.current = current;
|
||||
@@ -44,12 +43,12 @@ public class FillBucketEvent extends PlayerEvent
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getEmptyBucket() { return this.current; }
|
||||
public Level getWorld(){ return this.world; }
|
||||
@Nullable
|
||||
public HitResult getTarget() { return this.target; }
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getFilledBucket() { return this.result; }
|
||||
public void setFilledBucket(@Nonnull ItemStack bucket) { this.result = bucket; }
|
||||
public void setFilledBucket(@NotNull ItemStack bucket) { this.result = bucket; }
|
||||
}
|
||||
@@ -12,14 +12,13 @@ import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ItemTooltipEvent extends PlayerEvent
|
||||
{
|
||||
private final TooltipFlag flags;
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack itemStack;
|
||||
private final List<Component> toolTip;
|
||||
|
||||
@@ -27,7 +26,7 @@ public class ItemTooltipEvent extends PlayerEvent
|
||||
* This event is fired in {@link ItemStack#getTooltipLines(Player, TooltipFlag)}, which in turn is called from it's respective GUIContainer.
|
||||
* Tooltips are also gathered with a null entityPlayer during startup by {@link Minecraft#createSearchTrees()}.
|
||||
*/
|
||||
public ItemTooltipEvent(@Nonnull ItemStack itemStack, @Nullable Player entityPlayer, List<Component> list, TooltipFlag flags)
|
||||
public ItemTooltipEvent(@NotNull ItemStack itemStack, @Nullable Player entityPlayer, List<Component> list, TooltipFlag flags)
|
||||
{
|
||||
super(entityPlayer);
|
||||
this.itemStack = itemStack;
|
||||
@@ -46,7 +45,7 @@ public class ItemTooltipEvent extends PlayerEvent
|
||||
/**
|
||||
* The {@link ItemStack} with the tooltip.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack;
|
||||
|
||||
@@ -21,16 +21,15 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerDestroyItemEvent is fired when a player destroys an item.<br>
|
||||
* This event is fired whenever a player destroys an item in
|
||||
* {@link MultiPlayerGameMode#destroyBlock(BlockPos)},
|
||||
* {@link MultiPlayerGameMode#useItem(Player, Level, InteractionHand)},
|
||||
* {@link MultiPlayerGameMode#useItemOn(LocalPlayer, ClientLevel, InteractionHand, BlockHitResult)} ,
|
||||
* {@link MultiPlayerGameMode#useItem(Player, InteractionHand)},
|
||||
* {@link MultiPlayerGameMode#useItemOn(LocalPlayer, InteractionHand, BlockHitResult)} ,
|
||||
* {@link Player#attack(Entity)},
|
||||
* {@code Player#hurtCurrentlyUsedShield(float)},
|
||||
* {@link Player#interactOn(Entity, InteractionHand)},
|
||||
@@ -51,18 +50,18 @@ import javax.annotation.Nullable;
|
||||
**/
|
||||
public class PlayerDestroyItemEvent extends PlayerEvent
|
||||
{
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack original;
|
||||
@Nullable
|
||||
private final InteractionHand hand; // May be null if this player destroys the item by any use besides holding it.
|
||||
public PlayerDestroyItemEvent(Player player, @Nonnull ItemStack original, @Nullable InteractionHand hand)
|
||||
public PlayerDestroyItemEvent(Player player, @NotNull ItemStack original, @Nullable InteractionHand hand)
|
||||
{
|
||||
super(player);
|
||||
this.original = original;
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getOriginal() { return this.original; }
|
||||
@Nullable
|
||||
public InteractionHand getHand() { return this.hand; }
|
||||
|
||||
@@ -23,9 +23,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerEvent is fired whenever an event involving Living entities occurs. <br>
|
||||
@@ -144,7 +143,7 @@ public class PlayerEvent extends LivingEvent
|
||||
private final Component username;
|
||||
private Component displayname;
|
||||
|
||||
public NameFormat(Player player, Component username)
|
||||
public NameFormat(Player player, Component username)
|
||||
{
|
||||
super(player);
|
||||
this.username = username;
|
||||
@@ -191,7 +190,7 @@ public class PlayerEvent extends LivingEvent
|
||||
{
|
||||
super(player);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Component getDisplayName()
|
||||
{
|
||||
@@ -408,17 +407,17 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
|
||||
public static class ItemCraftedEvent extends PlayerEvent {
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack crafting;
|
||||
private final Container craftMatrix;
|
||||
public ItemCraftedEvent(Player player, @Nonnull ItemStack crafting, Container craftMatrix)
|
||||
public ItemCraftedEvent(Player player, @NotNull ItemStack crafting, Container craftMatrix)
|
||||
{
|
||||
super(player);
|
||||
this.crafting = crafting;
|
||||
this.craftMatrix = craftMatrix;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getCrafting()
|
||||
{
|
||||
return this.crafting;
|
||||
@@ -431,15 +430,15 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
|
||||
public static class ItemSmeltedEvent extends PlayerEvent {
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack smelting;
|
||||
public ItemSmeltedEvent(Player player, @Nonnull ItemStack crafting)
|
||||
public ItemSmeltedEvent(Player player, @NotNull ItemStack crafting)
|
||||
{
|
||||
super(player);
|
||||
this.smelting = crafting;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getSmelting()
|
||||
{
|
||||
return this.smelting;
|
||||
|
||||
@@ -25,13 +25,12 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static net.minecraftforge.eventbus.api.Event.Result.DEFAULT;
|
||||
import static net.minecraftforge.eventbus.api.Event.Result.DENY;
|
||||
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerInteractEvent is fired when a player interacts in some way.
|
||||
@@ -134,7 +133,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* If result equals {@link InteractionResult#PASS}, we proceed to {@link RightClickItem}. <br>
|
||||
* <br>
|
||||
* There are various results to this event, see the getters below. <br>
|
||||
* Note that handling things differently on the client vs server may cause desynchronizations!
|
||||
* Note that handling things differently on the client vs server may cause desynchronizations!
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RightClickBlock extends PlayerInteractEvent
|
||||
@@ -311,7 +310,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
/**
|
||||
* @return The hand involved in this interaction. Will never be null.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public InteractionHand getHand()
|
||||
{
|
||||
return hand;
|
||||
@@ -320,7 +319,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
/**
|
||||
* @return The itemstack involved in this interaction, {@code ItemStack.EMPTY} if the hand was empty.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return getPlayer().getItemInHand(hand);
|
||||
@@ -333,7 +332,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* Will never be null.
|
||||
* @return The position involved in this interaction.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public BlockPos getPos()
|
||||
{
|
||||
return pos;
|
||||
|
||||
@@ -10,8 +10,7 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This event is fired when a player's spawn point is set or reset.<br>
|
||||
@@ -24,7 +23,7 @@ public class PlayerSetSpawnEvent extends PlayerEvent
|
||||
private final boolean forced;
|
||||
@Nullable
|
||||
private final BlockPos newSpawn;
|
||||
|
||||
|
||||
public PlayerSetSpawnEvent(Player player, ResourceKey<Level> spawnWorld, @Nullable BlockPos newSpawn, boolean forced)
|
||||
{
|
||||
super(player);
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This event is fired when a player attempts to use a Hoe on a block, it
|
||||
* can be canceled to completely prevent any further processing.
|
||||
*
|
||||
* You can also set the result to ALLOW to mark the event as processed
|
||||
* and damage the hoe.
|
||||
*
|
||||
* setResult(ALLOW) is the same as the old setHandled();
|
||||
*/
|
||||
@Cancelable
|
||||
@HasResult
|
||||
// TODO 1.19: Remove
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public class UseHoeEvent extends PlayerEvent
|
||||
{
|
||||
private final UseOnContext context;;
|
||||
|
||||
public UseHoeEvent(UseOnContext context)
|
||||
{
|
||||
super(context.getPlayer());
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public UseOnContext getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
package net.minecraftforge.event.furnace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@@ -15,6 +12,8 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* {@link FurnaceFuelBurnTimeEvent} is fired when determining the fuel value for an ItemStack. <br>
|
||||
@@ -32,13 +31,13 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
@Cancelable
|
||||
public class FurnaceFuelBurnTimeEvent extends Event
|
||||
{
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final ItemStack itemStack;
|
||||
@Nullable
|
||||
private final RecipeType<?> recipeType;
|
||||
private int burnTime;
|
||||
|
||||
public FurnaceFuelBurnTimeEvent(@Nonnull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType)
|
||||
public FurnaceFuelBurnTimeEvent(@NotNull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType)
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.burnTime = burnTime;
|
||||
@@ -48,7 +47,7 @@ public class FurnaceFuelBurnTimeEvent extends Event
|
||||
/**
|
||||
* Get the ItemStack "fuel" in question.
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack;
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.world;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
|
||||
import net.minecraftforge.common.world.MobSpawnSettingsBuilder;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This event fires when a Biome is created from json or when a registered biome is re-created for worldgen.
|
||||
* It allows mods to edit a biome (like add a mob spawn) before it gets used for worldgen.
|
||||
*
|
||||
* In order to maintain the most compatibility possible with other mods' modifications to a biome,
|
||||
* the event should be assigned a {@link net.minecraftforge.eventbus.api.EventPriority} as follows:
|
||||
*
|
||||
* - Additions to any list/map contained in a biome : {@link EventPriority#HIGH}
|
||||
* - Removals to any list/map contained in a biome : {@link EventPriority#NORMAL}
|
||||
* - Any other modification : {@link EventPriority#LOW}
|
||||
*
|
||||
* Be aware that another mod could have done an operation beforehand, so an expected value out of a vanilla biome might not
|
||||
* always be the same, depending on other mods.
|
||||
*/
|
||||
public class BiomeLoadingEvent extends Event
|
||||
{
|
||||
private final ResourceLocation name;
|
||||
private Biome.ClimateSettings climate;
|
||||
private Biome.BiomeCategory category;
|
||||
private BiomeSpecialEffects effects;
|
||||
private final BiomeGenerationSettingsBuilder gen;
|
||||
private final MobSpawnSettingsBuilder spawns;
|
||||
|
||||
public BiomeLoadingEvent(@Nullable final ResourceLocation name, final Biome.ClimateSettings climate, final Biome.BiomeCategory category, final BiomeSpecialEffects effects, final BiomeGenerationSettingsBuilder gen, final MobSpawnSettingsBuilder spawns)
|
||||
{
|
||||
this.name = name;
|
||||
this.climate = climate;
|
||||
this.category = category;
|
||||
this.effects = effects;
|
||||
this.gen = gen;
|
||||
this.spawns = spawns;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get the registry name of the biome.
|
||||
* It generally SHOULD NOT be null, but due to vanilla's biome handling and codec weirdness, there may be cases where it is.
|
||||
* Do check for this possibility!
|
||||
*/
|
||||
@Nullable
|
||||
public ResourceLocation getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Biome.ClimateSettings getClimate()
|
||||
{
|
||||
return climate;
|
||||
}
|
||||
|
||||
public void setClimate(final Biome.ClimateSettings value)
|
||||
{
|
||||
this.climate = value;
|
||||
}
|
||||
|
||||
public Biome.BiomeCategory getCategory()
|
||||
{
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(final Biome.BiomeCategory value)
|
||||
{
|
||||
this.category = value;
|
||||
}
|
||||
|
||||
public BiomeSpecialEffects getEffects()
|
||||
{
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void setEffects(final BiomeSpecialEffects value)
|
||||
{
|
||||
this.effects = value;
|
||||
}
|
||||
|
||||
public BiomeGenerationSettingsBuilder getGeneration()
|
||||
{
|
||||
return gen;
|
||||
}
|
||||
|
||||
public MobSpawnSettingsBuilder getSpawns()
|
||||
{
|
||||
return spawns;
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockEvent extends Event
|
||||
{
|
||||
@@ -86,7 +85,7 @@ public class BlockEvent extends Event
|
||||
{
|
||||
int fortuneLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, player.getMainHandItem());
|
||||
int silkTouchLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, player.getMainHandItem());
|
||||
this.exp = state.getExpDrop(world, pos, fortuneLevel, silkTouchLevel);
|
||||
this.exp = state.getExpDrop(world, world.random, pos, fortuneLevel, silkTouchLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +128,7 @@ public class BlockEvent extends Event
|
||||
private final BlockState placedBlock;
|
||||
private final BlockState placedAgainst;
|
||||
|
||||
public EntityPlaceEvent(@Nonnull BlockSnapshot blockSnapshot, @Nonnull BlockState placedAgainst, @Nullable Entity entity)
|
||||
public EntityPlaceEvent(@NotNull BlockSnapshot blockSnapshot, @NotNull BlockState placedAgainst, @Nullable Entity entity)
|
||||
{
|
||||
super(blockSnapshot.getLevel(), blockSnapshot.getPos(), !(entity instanceof Player) ? blockSnapshot.getReplacedBlock() : blockSnapshot.getCurrentBlock());
|
||||
this.entity = entity;
|
||||
@@ -162,7 +161,7 @@ public class BlockEvent extends Event
|
||||
{
|
||||
private final List<BlockSnapshot> blockSnapshots;
|
||||
|
||||
public EntityMultiPlaceEvent(@Nonnull List<BlockSnapshot> blockSnapshots, @Nonnull BlockState placedAgainst, @Nullable Entity entity) {
|
||||
public EntityMultiPlaceEvent(@NotNull List<BlockSnapshot> blockSnapshots, @NotNull BlockState placedAgainst, @Nullable Entity entity) {
|
||||
super(blockSnapshots.get(0), placedAgainst, entity);
|
||||
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
|
||||
if (DEBUG)
|
||||
@@ -421,56 +420,7 @@ public class BlockEvent extends Event
|
||||
* For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip},
|
||||
* {@link ToolActions#SHOVEL_FLATTEN a shovel can path}, or {@link ToolActions#HOE_TILL a hoe can till}.
|
||||
* <p>
|
||||
* This deprecated subclass event is <i>only</i> fired when {@link #isSimulated()} is false.
|
||||
* To receive simulated events, use {@link BlockToolModificationEvent}.
|
||||
* <p>
|
||||
* This event is {@link Cancelable}. If canceled, this will prevent the tool
|
||||
* from changing the block's state.
|
||||
*
|
||||
* @deprecated Use {@link BlockToolModificationEvent} and put world-modifying actions behind <code>if (!event.isSimulated())</code>.
|
||||
*/
|
||||
@Cancelable
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static class BlockToolInteractEvent extends BlockToolModificationEvent
|
||||
{
|
||||
private final Player player;
|
||||
private final ItemStack stack;
|
||||
|
||||
public BlockToolInteractEvent(BlockState originalState, @Nonnull UseOnContext context, ToolAction toolAction)
|
||||
{
|
||||
super(originalState, context, toolAction, false);
|
||||
this.player = context.getPlayer();
|
||||
this.stack = context.getItemInHand();
|
||||
}
|
||||
|
||||
public BlockToolInteractEvent(LevelAccessor world, BlockPos pos, BlockState originalState, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
super(world, pos, originalState, toolAction);
|
||||
this.player = player;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player using the tool, never null
|
||||
*/
|
||||
@Nonnull
|
||||
public Player getPlayer()
|
||||
{
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public ItemStack getHeldItemStack()
|
||||
{
|
||||
return this.stack;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a block is right-clicked by a tool to change its state.
|
||||
* For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip},
|
||||
* {@link ToolActions#SHOVEL_FLATTEN a shovel can path}, or {@link ToolActions#HOE_TILL a hoe can till}.
|
||||
* <p>
|
||||
* Care must be taken to ensure world-modifying events are only performed if {@link #isSimulated()} returns {@code true}.
|
||||
* Care must be taken to ensure world-modifying events are only performed if {@link #isSimulated()} returns {@code false}.
|
||||
* <p>
|
||||
* This event is {@link Cancelable}. If canceled, this will prevent the tool
|
||||
* from changing the block's state.
|
||||
@@ -482,7 +432,7 @@ public class BlockEvent extends Event
|
||||
private final boolean simulate;
|
||||
private BlockState state;
|
||||
|
||||
public BlockToolModificationEvent(BlockState originalState, @Nonnull UseOnContext context, ToolAction toolAction, boolean simulate)
|
||||
public BlockToolModificationEvent(BlockState originalState, @NotNull UseOnContext context, ToolAction toolAction, boolean simulate)
|
||||
{
|
||||
super(context.getLevel(), context.getClickedPos(), originalState);
|
||||
this.context = context;
|
||||
@@ -491,16 +441,6 @@ public class BlockEvent extends Event
|
||||
this.simulate = simulate;
|
||||
}
|
||||
|
||||
// TODO 1.19: Remove
|
||||
BlockToolModificationEvent(LevelAccessor level, BlockPos pos, BlockState originalState, ToolAction toolAction)
|
||||
{
|
||||
super(level, pos, originalState);
|
||||
this.context = null;
|
||||
this.state = originalState;
|
||||
this.toolAction = toolAction;
|
||||
this.simulate = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player using the tool.
|
||||
* May be null based on what was provided by {@link #getContext() the use on context}.
|
||||
@@ -540,13 +480,11 @@ public class BlockEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nullable use on context that this event was performed in.
|
||||
* Starting in 1.19, this will never be null.
|
||||
* Returns the nonnull use on context that this event was performed in.
|
||||
*
|
||||
* @return the nullable use on context that this event was performed in
|
||||
* @return the nonnull use on context that this event was performed in
|
||||
*/
|
||||
// TODO 1.19: Remove nullable annotation and add non-null annotation
|
||||
@Nullable
|
||||
@NotNull
|
||||
public UseOnContext getContext()
|
||||
{
|
||||
return context;
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
|
||||
package net.minecraftforge.event.world;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.level.block.piston.PistonStructureResolver;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Base piston event, use {@link PistonEvent.Post} and {@link PistonEvent.Pre}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Random;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.SaplingBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -19,7 +20,7 @@ import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
/**
|
||||
* SaplingGrowTreeEvent is fired when a sapling grows into a tree.<br>
|
||||
* This event is fired during sapling growth in
|
||||
* {@link SaplingBlock#advanceTree(ServerLevel, BlockPos, BlockState, Random)} .<br>
|
||||
* {@link SaplingBlock#advanceTree(ServerLevel, BlockPos, BlockState, RandomSource)} .<br>
|
||||
* <br>
|
||||
* {@link #pos} contains the coordinates of the growing sapling. <br>
|
||||
* {@link #rand} contains an instance of Random for use. <br>
|
||||
@@ -35,9 +36,9 @@ import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
public class SaplingGrowTreeEvent extends WorldEvent
|
||||
{
|
||||
private final BlockPos pos;
|
||||
private final Random rand;
|
||||
private final RandomSource rand;
|
||||
|
||||
public SaplingGrowTreeEvent(LevelAccessor world, Random rand, BlockPos pos)
|
||||
public SaplingGrowTreeEvent(LevelAccessor world, RandomSource rand, BlockPos pos)
|
||||
{
|
||||
super(world);
|
||||
this.rand = rand;
|
||||
@@ -49,7 +50,7 @@ public class SaplingGrowTreeEvent extends WorldEvent
|
||||
return pos;
|
||||
}
|
||||
|
||||
public Random getRand()
|
||||
public RandomSource getRand()
|
||||
{
|
||||
return rand;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.SpawnData;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
||||
@@ -34,13 +32,13 @@ import net.minecraftforge.eventbus.api.EventPriority;
|
||||
public class StructureSpawnListGatherEvent extends Event
|
||||
{
|
||||
|
||||
private final StructureFeature<?> structure;
|
||||
private final Structure structure;
|
||||
private final Map<MobCategory, List<MobSpawnSettings.SpawnerData>> entitySpawns = new HashMap<>();
|
||||
private final Map<MobCategory, List<MobSpawnSettings.SpawnerData>> entitySpawnsUnmodifiableLists = new HashMap<>();
|
||||
private final Map<MobCategory, List<MobSpawnSettings.SpawnerData>> entitySpawnsUnmodifiable = Collections.unmodifiableMap(entitySpawnsUnmodifiableLists);
|
||||
private boolean insideOnly;
|
||||
|
||||
public StructureSpawnListGatherEvent(StructureFeature<?> structure)
|
||||
public StructureSpawnListGatherEvent(Structure structure)
|
||||
{
|
||||
this.structure = structure;
|
||||
this.insideOnly = false;
|
||||
@@ -57,7 +55,7 @@ public class StructureSpawnListGatherEvent extends Event
|
||||
/**
|
||||
* @return Structure to add or remove spawns to/from.
|
||||
*/
|
||||
public StructureFeature<?> getStructure()
|
||||
public Structure getStructure()
|
||||
{
|
||||
return structure;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class WorldEvent extends Event
|
||||
/**
|
||||
* WorldEvent.Load is fired when Minecraft loads a world.<br>
|
||||
* This event is fired when a world is loaded in
|
||||
* {@link ClientLevel#ClientLevel(ClientPacketListener, ClientLevel.ClientLevelData, ResourceKey, DimensionType, int, int, Supplier, LevelRenderer, boolean, long)},
|
||||
* {@code ClientLevel#ClientLevel(ClientPacketListener, ClientLevel.ClientLevelData, ResourceKey, DimensionType, int, int, Supplier, LevelRenderer, boolean, long)},
|
||||
* {@code MinecraftServer#createLevels(ChunkProgressListener)}. <br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
|
||||
Reference in new issue
Block a user