[1.19.x] Apply general renames, A SRG is provided for modders. (#8840)

See https://gist.github.com/SizableShrimp/882a671ff74256d150776da08c89ef72
This commit is contained in:
SizableShrimp authored and GitHub committed 2022-07-11 18:27:48 -07:00
1 parent 5e8c786406
commit b8b40e1f54
140 files changed
+1138 -1149

No files matched your search

@@ -109,18 +109,18 @@ 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.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.BlockToolModificationEvent;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.world.BlockEvent.EntityMultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.PistonEvent;
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.event.world.SleepFinishedTimeEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.event.level.BlockEvent.BlockToolModificationEvent;
import net.minecraftforge.event.level.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.level.BlockEvent.EntityMultiPlaceEvent;
import net.minecraftforge.event.level.BlockEvent.EntityPlaceEvent;
import net.minecraftforge.event.level.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.level.ChunkWatchEvent;
import net.minecraftforge.event.level.ExplosionEvent;
import net.minecraftforge.event.level.PistonEvent;
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
import net.minecraftforge.event.level.SleepFinishedTimeEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.fml.LogicalSide;
@@ -402,9 +402,9 @@ public class ForgeEventFactory
return event.getResultStatus();
}
public static void onPlayerWakeup(Player player, boolean wakeImmediately, boolean updateWorldFlag)
public static void onPlayerWakeup(Player player, boolean wakeImmediately, boolean updateLevel)
{
MinecraftForge.EVENT_BUS.post(new PlayerWakeUpEvent(player, wakeImmediately, updateWorldFlag));
MinecraftForge.EVENT_BUS.post(new PlayerWakeUpEvent(player, wakeImmediately, updateLevel));
}
public static void onPlayerFall(Player player, float distance, float multiplier)
@@ -445,7 +445,7 @@ public class ForgeEventFactory
public static boolean onCreateWorldSpawn(Level level, ServerLevelData settings)
{
return MinecraftForge.EVENT_BUS.post(new WorldEvent.CreateSpawnPosition(level, settings));
return MinecraftForge.EVENT_BUS.post(new LevelEvent.CreateSpawnPosition(level, settings));
}
public static float onLivingHeal(LivingEntity entity, float amount)
@@ -583,7 +583,7 @@ public class ForgeEventFactory
{
net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent e = new net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent(level, pos, enchantRow, power, itemStack, enchantmentLevel);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e);
return e.getLevel();
return e.getEnchantLevel();
}
public static boolean onEntityDestroyBlock(LivingEntity entity, BlockPos pos, BlockState state)
@@ -600,9 +600,9 @@ public class ForgeEventFactory
return result == Result.DEFAULT ? level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) : result == Result.ALLOW;
}
public static boolean saplingGrowTree(LevelAccessor level, RandomSource rand, BlockPos pos)
public static boolean saplingGrowTree(LevelAccessor level, RandomSource randomSource, BlockPos pos)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, rand, pos);
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, randomSource, pos);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult() != Result.DENY;
}
@@ -772,14 +772,14 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(new TickEvent.PlayerTickEvent(TickEvent.Phase.END, player));
}
public static void onPreWorldTick(Level level, BooleanSupplier haveTime)
public static void onPreLevelTick(Level level, BooleanSupplier haveTime)
{
MinecraftForge.EVENT_BUS.post(new TickEvent.WorldTickEvent(LogicalSide.SERVER, TickEvent.Phase.START, level, haveTime));
MinecraftForge.EVENT_BUS.post(new TickEvent.LevelTickEvent(LogicalSide.SERVER, TickEvent.Phase.START, level, haveTime));
}
public static void onPostWorldTick(Level level, BooleanSupplier haveTime)
public static void onPostLevelTick(Level level, BooleanSupplier haveTime)
{
MinecraftForge.EVENT_BUS.post(new TickEvent.WorldTickEvent(LogicalSide.SERVER, TickEvent.Phase.END, level, haveTime));
MinecraftForge.EVENT_BUS.post(new TickEvent.LevelTickEvent(LogicalSide.SERVER, TickEvent.Phase.END, level, haveTime));
}
public static void onPreClientTick()
@@ -45,7 +45,7 @@ public class RegisterCommandsEvent extends Event
/**
* {@return the environment the command is being registered for}
*/
public Commands.CommandSelection getEnvironment()
public Commands.CommandSelection getCommandSelection()
{
return environment;
}
@@ -15,22 +15,13 @@ import net.minecraftforge.server.ServerLifecycleHooks;
*/
public class TagsUpdatedEvent extends Event
{
private final RegistryAccess registries;
private final RegistryAccess registryAccess;
private final UpdateCause updateCause;
private final boolean integratedServer;
@Deprecated(forRemoval = true, since = "1.18.2")
public TagsUpdatedEvent(RegistryAccess registries)
public TagsUpdatedEvent(RegistryAccess registryAccess, boolean fromClientPacket, boolean isIntegratedServerConnection)
{
this.registries = registries;
this.updateCause = ClientGamePacketListener.class.isAssignableFrom(StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass()) ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
var currentServer = ServerLifecycleHooks.getCurrentServer();
this.integratedServer = currentServer != null && !currentServer.isDedicatedServer();
}
public TagsUpdatedEvent(RegistryAccess registries, boolean fromClientPacket, boolean isIntegratedServerConnection)
{
this.registries = registries;
this.registryAccess = registryAccess;
this.updateCause = fromClientPacket ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
this.integratedServer = isIntegratedServerConnection;
}
@@ -38,9 +29,9 @@ public class TagsUpdatedEvent extends Event
/**
* @return The dynamic registries that have had their tags rebound.
*/
public RegistryAccess getTagManager()
public RegistryAccess getRegistryAccess()
{
return registries;
return registryAccess;
}
/**
@@ -18,7 +18,7 @@ import net.minecraftforge.fml.LogicalSide;
public class TickEvent extends Event
{
public enum Type {
WORLD, PLAYER, CLIENT, SERVER, RENDER;
LEVEL, PLAYER, CLIENT, SERVER, RENDER;
}
public enum Phase {
@@ -71,14 +71,14 @@ public class TickEvent extends Event
}
}
public static class WorldTickEvent extends TickEvent {
public final Level world;
public static class LevelTickEvent extends TickEvent {
public final Level level;
private final BooleanSupplier haveTime;
public WorldTickEvent(LogicalSide side, Phase phase, Level world, BooleanSupplier haveTime)
public LevelTickEvent(LogicalSide side, Phase phase, Level level, BooleanSupplier haveTime)
{
super(Type.WORLD, side, phase);
this.world = world;
super(Type.LEVEL, side, phase);
this.level = level;
this.haveTime = haveTime;
}
@@ -20,24 +20,24 @@ import org.jetbrains.annotations.NotNull;
*/
public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Event
{
private final Level world;
private final Level level;
private final BlockPos pos;
private final int enchantRow;
private final int power;
@NotNull
private final ItemStack itemStack;
private final int originalLevel;
private int level;
private int enchantLevel;
public EnchantmentLevelSetEvent(Level world, BlockPos pos, int enchantRow, int power, @NotNull ItemStack itemStack, int level)
public EnchantmentLevelSetEvent(Level level, BlockPos pos, int enchantRow, int power, @NotNull ItemStack itemStack, int enchantLevel)
{
this.world = world;
this.level = level;
this.pos = pos;
this.enchantRow = enchantRow;
this.power = power;
this.itemStack = itemStack;
this.originalLevel = level;
this.level = level;
this.originalLevel = enchantLevel;
this.enchantLevel = enchantLevel;
}
/**
@@ -45,9 +45,9 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
*
* @return the world object
*/
public Level getWorld()
public Level getLevel()
{
return world;
return level;
}
/**
@@ -106,9 +106,9 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
*
* @return the level of the enchantment for this row (0-30)
*/
public int getLevel()
public int getEnchantLevel()
{
return level;
return enchantLevel;
}
/**
@@ -116,8 +116,8 @@ public class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Ev
*
* @param level the new level of the enchantment (0-30)
*/
public void setLevel(int level)
public void setEnchantLevel(int level)
{
this.level = level;
this.enchantLevel = level;
}
}
@@ -36,7 +36,7 @@ public class EntityAttributeModificationEvent extends Event implements IModBusEv
{
this.entityAttributes = mapIn;
this.entityTypes = ImmutableList.copyOf(
ForgeRegistries.ENTITIES.getValues().stream()
ForgeRegistries.ENTITY_TYPES.getValues().stream()
.filter(DefaultAttributes::hasSupplier)
.map(entityType -> (EntityType<? extends LivingEntity>) entityType)
.collect(Collectors.toList())
@@ -58,7 +58,7 @@ public class EntityEvent extends Event
* 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>
* This event does not fire when a new entity is spawned, only when an entity moves from one section to another one.
* Use {@link EntityJoinWorldEvent} to detect new entities joining the world.
* Use {@link EntityJoinLevelEvent} to detect new entities joining the world.
* <br>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* <br>
@@ -0,0 +1,64 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.entity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.fml.LogicalSide;
/**
* This event is fired whenever an {@link Entity} joins a {@link Level}.
* This event is fired whenever an entity is added to a level in {@link Level#addFreshEntity(Entity)}
* and {@code PersistentEntitySectionManager#addNewEntity(Entity, boolean)}.
* <p>
* <strong>Note:</strong> This event may be called before the underlying {@link LevelChunk} is promoted to {@link ChunkStatus#FULL}.
* You will cause chunk loading deadlocks if you do not delay your world interactions.
* <p>
* This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* If the event is canceled, the entity will not be added to the level.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
@Cancelable
public class EntityJoinLevelEvent extends EntityEvent
{
private final Level level;
private final boolean loadedFromDisk;
public EntityJoinLevelEvent(Entity entity, Level level)
{
this(entity, level, false);
}
public EntityJoinLevelEvent(Entity entity, Level level, boolean loadedFromDisk)
{
super(entity);
this.level = level;
this.loadedFromDisk = loadedFromDisk;
}
/**
* {@return the level that the entity is set to join}
*/
public Level getLevel()
{
return level;
}
/**
* @return {@code true} if the entity was loaded from disk, {@code false} otherwise.
* On the {@linkplain LogicalSide#CLIENT logical client}, this will always return {@code false}.
*/
public boolean loadedFromDisk()
{
return loadedFromDisk;
}
}
@@ -1,65 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.entity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* EntityJoinWorldEvent is fired when an Entity joins the world. <br>
* This event is fired whenever an Entity is added to the world in
* {@code Level#loadEntities(Collection)},
* {@code net.minecraft.world.ServerWorld#loadEntities(Collection)}
* {@code World#joinEntityInSurroundings(Entity)}, and
* {@code World#spawnEntity(Entity)}. <br>
* <strong>Note:</strong> This event may be called before the underlying {@link LevelChunk} is promoted to {@link ChunkStatus#FULL}.
* You will cause chunk loading deadlocks if you don't delay your world interactions.<br>
* <br>
* {@link #world} contains the world in which the entity is to join.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not added to the world.<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
public class EntityJoinWorldEvent extends EntityEvent
{
private final Level world;
private final boolean loadedFromDisk;
public EntityJoinWorldEvent(Entity entity, Level world)
{
this(entity, world, false);
}
public EntityJoinWorldEvent(Entity entity, Level world, boolean loadedFromDisk)
{
super(entity);
this.world = world;
this.loadedFromDisk = loadedFromDisk;
}
public Level getWorld()
{
return world;
}
/**
* @return {@code true} if the entity was loaded from disk. On client entities, the info isn't available and this will always return {@code false}.
*/
public boolean loadedFromDisk()
{
return loadedFromDisk;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.entity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.entity.LevelCallback;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* This event is fired whenever an {@link Entity} leaves a {@link Level}.
* This event is fired whenever an entity is removed from the level in {@link LevelCallback#onTrackingEnd(Object)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain net.minecraftforge.eventbus.api.Event.HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
public class EntityLeaveLevelEvent extends EntityEvent
{
private final Level level;
public EntityLeaveLevelEvent(Entity entity, Level level)
{
super(entity);
this.level = level;
}
/**
* {@return the level the entity is set to leave}
*/
public Level getLevel()
{
return level;
}
}
@@ -1,43 +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.multiplayer.ClientLevel;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge;
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)}. <br>
* <br>
* {@link #world} contains the world from which the entity is removed. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}
*/
public class EntityLeaveWorldEvent extends EntityEvent
{
private final Level world;
public EntityLeaveWorldEvent(Entity entity, Level world)
{
super(entity);
this.world = world;
}
public Level getWorld()
{
return world;
}
}
@@ -30,16 +30,16 @@ public class EntityMountEvent extends EntityEvent
private final Entity entityMounting;
private final Entity entityBeingMounted;
private final Level worldObj;
private final Level level;
private final boolean isMounting;
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, Level entityWorld, boolean isMounting)
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, Level level, boolean isMounting)
{
super(entityMounting);
this.entityMounting = entityMounting;
this.entityBeingMounted = entityBeingMounted;
this.worldObj = entityWorld;
this.level = level;
this.isMounting = isMounting;
}
@@ -63,8 +63,8 @@ public class EntityMountEvent extends EntityEvent
return entityBeingMounted;
}
public Level getWorldObj()
public Level getLevel()
{
return worldObj;
return level;
}
}
@@ -9,31 +9,32 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraftforge.event.entity.EntityEvent;
/**
* Base class for all EntityItem events. Contains a reference to the
* EntityItem of interest. For most EntityItem events, there's little to no
* Base class for all {@link ItemEntity} events. Contains a reference to the
* ItemEntity of interest. For most ItemEntity events, there's little to no
* additional useful data from the firing method that isn't already contained
* within the EntityItem instance.
* within the ItemEntity instance.
*/
public class ItemEvent extends EntityEvent
{
private final ItemEntity entityItem;
private final ItemEntity itemEntity;
/**
* Creates a new event for an EntityItem.
*
* @param itemEntity The EntityItem for this event
* Creates a new event for an {@link ItemEntity}.
*
* @param itemEntity The ItemEntity for this event
*/
public ItemEvent(ItemEntity itemEntity)
{
super(itemEntity);
this.entityItem = itemEntity;
this.itemEntity = itemEntity;
}
/**
* The relevant EntityItem for this event, already cast for you.
* The relevant {@link ItemEntity} for this event.
*/
public ItemEntity getEntityItem()
@Override
public ItemEntity getEntity()
{
return entityItem;
return itemEntity;
}
}
@@ -15,7 +15,7 @@ import net.minecraftforge.eventbus.api.Event;
import org.jetbrains.annotations.Nullable;
/**
* LivingEvent is fired whenever an event involving Living entities occurs.<br>
* LivingEvent is fired whenever an event involving a {@link LivingEntity} occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
@@ -23,24 +23,24 @@ import org.jetbrains.annotations.Nullable;
**/
public class LivingEvent extends EntityEvent
{
private final LivingEntity entityLiving;
private final LivingEntity livingEntity;
public LivingEvent(LivingEntity entity)
{
super(entity);
entityLiving = entity;
livingEntity = entity;
}
public LivingEntity getEntityLiving()
@Override
public LivingEntity getEntity()
{
return entityLiving;
return livingEntity;
}
/**
* LivingUpdateEvent is fired when an Entity is updated. <br>
* This event is fired whenever an Entity is updated in
* {@link LivingEntity#tick()}. <br>
* LivingUpdateEvent is fired when a LivingEntity is ticked in {@link LivingEntity#tick()}. <br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingUpdate(LivingEntity)}.<br>
* This event is fired via the {@link ForgeHooks#onLivingTick(LivingEntity)}.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not update.<br>
@@ -50,9 +50,9 @@ public class LivingEvent extends EntityEvent
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public static class LivingUpdateEvent extends LivingEvent
public static class LivingTickEvent extends LivingEvent
{
public LivingUpdateEvent(LivingEntity e){ super(e); }
public LivingTickEvent(LivingEntity e){ super(e); }
}
/**
@@ -6,56 +6,92 @@
package net.minecraftforge.event.entity.living;
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.BaseSpawner;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.Nullable;
/**
* LivingSpawnEvent is fired for any events associated with Living Entities spawn status. <br>
* If a method utilizes this event as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the world in which this living Entity is being spawned.<br>
* {@link #x} contains the x-coordinate this entity is being spawned at.<br>
* {@link #y} contains the y-coordinate this entity is being spawned at.<br>
* {@link #z} contains the z-coordinate this entity is being spawned at.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
* This event is fired whenever a {@link Mob} should do something spawn-related.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
*/
public class LivingSpawnEvent extends LivingEvent
{
private final LevelAccessor world;
private final LevelAccessor level;
private final Mob mob;
private final double x;
private final double y;
private final double z;
public LivingSpawnEvent(Mob entity, LevelAccessor world, double x, double y, double z)
public LivingSpawnEvent(Mob mob, LevelAccessor level, double x, double y, double z)
{
super(entity);
this.world = world;
super(mob);
this.mob = mob;
this.level = level;
this.x = x;
this.y = y;
this.z = z;
}
public LevelAccessor getWorld() { return world; }
public double getX() { return x; }
public double getY() { return y; }
public double getZ() { return z; }
/**
* Fires before mob spawn events.
*
* Result is significant:
* DEFAULT: use vanilla spawn rules
* ALLOW: allow the spawn
* DENY: deny the spawn
*
* {@return the mob that is causing a spawn action}
*/
@Override
public Mob getEntity()
{
return this.mob;
}
/**
* {@return the level relating to the mob spawn action}
*/
public LevelAccessor getLevel()
{
return this.level;
}
/**
* {@return the x-coordinate relating to the mob spawn action}
*/
public double getX()
{
return this.x;
}
/**
* {@return the y-coordinate relating to the mob spawn action}
*/
public double getY()
{
return this.y;
}
/**
* {@return the z-coordinate relating to the mob spawn action}
*/
public double getZ()
{
return this.z;
}
/**
* This event is fired before a {@link Mob} spawns.
* <p>
* This event is not {@linkplain Cancelable cancellable}, but does {@linkplain HasResult have a result}.
* {@linkplain Result#DEFAULT DEFAULT} indicates that default spawn rules should be used.
* {@linkplain Result#ALLOW ALLOW} indicates that the mob should spawn regardless of default spawn rules.
* {@linkplain Result#DENY DENY} indicates that the mob should not spawn.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
*/
@HasResult
public static class CheckSpawn extends LivingSpawnEvent
@@ -64,19 +100,9 @@ public class LivingSpawnEvent extends LivingEvent
private final BaseSpawner spawner;
private final MobSpawnType spawnReason;
/**
* CheckSpawn is fired when an Entity is about to be spawned.
* @param entity the spawning entity
* @param world the world to spawn in
* @param x x coordinate
* @param y y coordinate
* @param z z coordinate
* @param spawner position of the MobSpawner
* null if it this spawn is coming from a WorldSpawner
*/
public CheckSpawn(Mob entity, LevelAccessor world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
public CheckSpawn(Mob mob, LevelAccessor level, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
{
super(entity, world, x, y, z);
super(mob, level, x, y, z);
this.spawner = spawner;
this.spawnReason = spawnReason;
}
@@ -99,18 +125,14 @@ public class LivingSpawnEvent extends LivingEvent
}
/**
* SpecialSpawn is fired when an Entity is to be spawned.<br>
* This allows you to do special inializers in the new entity.<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(Mob, LevelAccessor, float, float, float, BaseSpawner, MobSpawnType)}.<br>
* <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}.
**/
* This event is fired whenever a {@link Mob} is set to be spawned, to allow for mod-specific initializers.
* <p>
* This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* If the event is canceled, the mob will not spawn.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
*/
@Cancelable
public static class SpecialSpawn extends LivingSpawnEvent
{
@@ -118,9 +140,9 @@ public class LivingSpawnEvent extends LivingEvent
private final BaseSpawner spawner;
private final MobSpawnType spawnReason;
public SpecialSpawn(Mob entity, LevelAccessor world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
public SpecialSpawn(Mob entity, LevelAccessor level, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason)
{
super(entity, world, x, y, z);
super(entity, level, x, y, z);
this.spawner = spawner;
this.spawnReason = spawnReason;
}
@@ -138,25 +160,27 @@ public class LivingSpawnEvent extends LivingEvent
}
/**
* Fired each tick for despawnable mobs to allow control over despawning.
* {@link Result#DEFAULT} will pass the mob on to vanilla despawn mechanics.
* {@link Result#ALLOW} will force the mob to despawn.
* {@link Result#DENY} will force the mob to remain.
* This is fired every tick for every despawnable entity. Be efficient in your handlers.
*
* Note: this is not fired <em>if</em> the mob is definitely going to otherwise despawn. It is fired to check if
* the mob can be allowed to despawn. See {@link LivingEntity#checkDespawn()}
* This event is fired for a {@link Mob} that can despawn <i>each mob tick</i>.
* This event only fires if a mob can be allowed to despawn and will not
* otherwise fire if a despawn is certain.
* <p>
* This event is not {@linkplain Cancelable cancellable}, but does {@linkplain HasResult have a result}.
* {@link Result#DEFAULT} indicates that default despawn mechanics should be used.
* {@link Result#ALLOW} indicates that the mob should forcefully despawn.
* {@link Result#DENY} indicates that the mob should forcefully stay spawned.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
*
* @see LivingEntity#checkDespawn()
* @author cpw
*
*/
@HasResult
public static class AllowDespawn extends LivingSpawnEvent
{
public AllowDespawn(Mob entity)
public AllowDespawn(Mob mob)
{
super(entity, entity.level, entity.getX(), entity.getY(), entity.getZ());
super(mob, mob.level, mob.getX(), mob.getY(), mob.getZ());
}
}
}
@@ -0,0 +1,164 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* This event is fired when an interaction between a {@link LivingEntity} and {@link MobEffectInstance} happens.
* <p>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class MobEffectEvent extends LivingEvent
{
@Nullable
protected final MobEffectInstance effectInstance;
public MobEffectEvent(LivingEntity living, MobEffectInstance effectInstance)
{
super(living);
this.effectInstance = effectInstance;
}
@Nullable
public MobEffectInstance getEffectInstance()
{
return effectInstance;
}
/**
* This Event is fired when a {@link MobEffect} is about to get removed from an Entity.
* This Event is {@link Cancelable}. If canceled, the effect will not be removed.
* This Event does not have a result.
*/
@Cancelable
public static class Remove extends MobEffectEvent
{
private final MobEffect effect;
public Remove(LivingEntity living, MobEffect effect)
{
super(living, living.getEffect(effect));
this.effect = effect;
}
public Remove(LivingEntity living, MobEffectInstance effectInstance)
{
super(living, effectInstance);
this.effect = effectInstance.getEffect();
}
/**
* @return the {@link MobEffectEvent} which is being removed from the entity
*/
public MobEffect getEffect()
{
return this.effect;
}
/**
* @return the {@link MobEffectInstance}. In the remove event, this can be null if the entity does not have a {@link MobEffect} of the right type active.
*/
@Override
@Nullable
public MobEffectInstance getEffectInstance()
{
return super.getEffectInstance();
}
}
/**
* This event is fired to check if a {@link MobEffectInstance} can be applied to an entity.
* This event is not {@link Cancelable}.
* This event {@link HasResult has a result}.
* <p>
* {@link Result#ALLOW ALLOW} will apply this mob effect.
* {@link Result#DENY DENY} will not apply this mob effect.
* {@link Result#DEFAULT DEFAULT} will run vanilla logic to determine if this mob effect is applicable in {@link LivingEntity#canBeAffected}.
*/
@HasResult
public static class Applicable extends MobEffectEvent
{
public Applicable(LivingEntity living, @NotNull MobEffectInstance effectInstance)
{
super(living, effectInstance);
}
@Override
@NotNull
public MobEffectInstance getEffectInstance()
{
return super.getEffectInstance();
}
}
/**
* This event is fired when a new {@link MobEffectInstance} is added to an entity.
* This event is also fired if an entity already has the effect but with a different duration or amplifier.
* This event is not {@link Cancelable}.
* This event does not have a result.
*/
public static class Added extends MobEffectEvent
{
private final MobEffectInstance oldEffectInstance;
private final Entity source;
public Added(LivingEntity living, MobEffectInstance oldEffectInstance, MobEffectInstance newEffectInstance, Entity source)
{
super(living, newEffectInstance);
this.oldEffectInstance = oldEffectInstance;
this.source = source;
}
/**
* @return the added {@link MobEffectInstance}. This is the unmerged MobEffectInstance if the old MobEffectInstance is not null.
*/
@Override
@NotNull
public MobEffectInstance getEffectInstance()
{
return super.getEffectInstance();
}
/**
* @return the old {@link MobEffectInstance}. This can be null if the entity did not have an effect of this kind before.
*/
@Nullable
public MobEffectInstance getOldEffectInstance()
{
return oldEffectInstance;
}
/**
* @return the entity source of the effect, or {@code null} if none exists
*/
@Nullable
public Entity getEffectSource()
{
return source;
}
}
/**
* This event is fired when a {@link MobEffectInstance} expires on an entity.
* This event is not {@link Cancelable}.
* This event does not have a result.
*/
public static class Expired extends MobEffectEvent
{
public Expired(LivingEntity living, MobEffectInstance effectInstance)
{
super(living, effectInstance);
}
}
}
@@ -1,167 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
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>
*/
public class PotionEvent extends LivingEvent
{
@Nullable
protected final MobEffectInstance effect;
public PotionEvent(LivingEntity living, MobEffectInstance effect)
{
super(living);
this.effect = effect;
}
/**
* Retuns the PotionEffect.
*/
@Nullable
public MobEffectInstance getPotionEffect()
{
return effect;
}
/**
* This Event is fired when a Potion is about to get removed from an Entity.
* This Event is {@link Cancelable}.
* This Event does not have a result.
*/
@Cancelable
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();
}
/**
* @return the Potion which is tried to remove from the Entity.
*/
public MobEffect getPotion()
{
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.
*/
@Override
@Nullable
public MobEffectInstance getPotionEffect()
{
return super.getPotionEffect();
}
}
/**
* This Event is fired to check if a Potion can get applied to an Entity.
* This Event is not {@link Cancelable}
* This Event has a result {@link HasResult}.
* ALLOW will apply this potion effect.
* DENY will not apply this potion effect.
* DEFAULT will run vanilla logic to determine if this potion isApplicable.
*/
@HasResult
public static class PotionApplicableEvent extends PotionEvent
{
public PotionApplicableEvent(LivingEntity living, MobEffectInstance effect)
{
super(living, effect);
}
/**
* @return the PotionEffect.
*/
@Override
@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}
* This Event does not have a Result.
*/
public static class PotionAddedEvent extends PotionEvent
{
private final MobEffectInstance oldEffect;
private final Entity source;
public PotionAddedEvent(LivingEntity living, MobEffectInstance oldEffect, MobEffectInstance newEffect, Entity source)
{
super(living, newEffect);
this.oldEffect = oldEffect;
this.source = source;
}
/**
* @return the added PotionEffect. This is the umerged PotionEffect if the old PotionEffect is not null.
*/
@Override
@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.
*/
@Nullable
public MobEffectInstance getOldPotionEffect()
{
return oldEffect;
}
/**
* Returns the entity source of the effect, or {@code null} if none exists.
*
* @return the entity source of the effect, or {@code null}
*/
@Nullable
public Entity getPotionSource()
{
return source;
}
}
/**
* This Event is fired when a Potion effect expires on an Entity.
* This Event is not {@link Cancelable}
* This Event does not have a Result.
*/
public static class PotionExpiryEvent extends PotionEvent
{
public PotionExpiryEvent(LivingEntity living, MobEffectInstance effect)
{
super(living, effect);
}
}
}
@@ -11,64 +11,68 @@ import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* ZombieEvent is fired whenever a zombie is spawned for aid.
* If a method utilizes this event as its parameter, the method will
* receive every child event of this class.
*
*
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class ZombieEvent extends EntityEvent {
private final Zombie zombie;
public ZombieEvent(Zombie entity)
public ZombieEvent(Zombie zombie)
{
super(entity);
super(zombie);
this.zombie = zombie;
}
public Zombie getSummoner()
@Override
public Zombie getEntity()
{
return (Zombie) getEntity();
return this.zombie;
}
/**
* SummonAidEvent is fired when a Zombie Entity is summoned.
* This event is fired whenever a Zombie Entity is summoned in
* This event is fired whenever a Zombie Entity is summoned in
* {@code Zombie#actuallyHurt(DamageSource, float)}.
*
*
* This event is fired via the {@link ForgeEventFactory#fireZombieSummonAid(Zombie, Level, int, int, int, LivingEntity, double)}.
*
* {@link #customSummonedAid} remains null, but can be populated with a custom EntityZombie which will be spawned.
* {@link #world} contains the world that this summoning is occurring in.
* {@link #x} contains the x-coordinate at which this summoning event is occurring.
* {@link #y} contains the y-coordinate at which this summoning event is occurring.
* {@link #z} contains the z-coordinate at which this summoning event is occurring.
* {@link #attacker} contains the living Entity that attacked and caused this event to fire.
* {@link #summonChance} contains the likelihood that a Zombie would successfully be summoned.
*
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.
*
*
* {@link #getCustomSummonedAid()} remains null, but can be populated with a custom EntityZombie which will be spawned.
* {@link #getLevel()} contains the world that this summoning is occurring in.
* {@link #getX()} contains the x-coordinate at which this summoning event is occurring.
* {@link #getY()} contains the y-coordinate at which this summoning event is occurring.
* {@link #getZ()} contains the z-coordinate at which this summoning event is occurring.
* {@link #getAttacker()} contains the living Entity that attacked and caused this event to fire.
* {@link #getSummonChance()} contains the likelihood that a Zombie would successfully be summoned.
*
* This event is not {@link Cancelable}.
*
* This event has a result. {@link HasResult}
* {@link Result#ALLOW} Zombie is summoned.
* {@link Result#DENY} Zombie is not summoned.
*
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@HasResult
public static class SummonAidEvent extends ZombieEvent {
private Zombie customSummonedAid;
private final Level world;
private final Level level;
private final int x;
private final int y;
private final int z;
private final LivingEntity attacker;
private final double summonChance;
public SummonAidEvent(Zombie entity, Level world, int x, int y, int z, LivingEntity attacker, double summonChance)
public SummonAidEvent(Zombie zombie, Level level, int x, int y, int z, LivingEntity attacker, double summonChance)
{
super(entity);
this.world = world;
super(zombie);
this.level = level;
this.x = x;
this.y = y;
this.z = z;
@@ -81,7 +85,7 @@ public class ZombieEvent extends EntityEvent {
*/
public Zombie getCustomSummonedAid() { return customSummonedAid; }
public void setCustomSummonedAid(Zombie customSummonedAid) { this.customSummonedAid = customSummonedAid; }
public Level getWorld() { return world; }
public Level getLevel() { return level; }
public int getX() { return x; }
public int getY() { return y; }
public int getZ() { return z; }
@@ -40,21 +40,21 @@ public class AnvilRepairEvent extends PlayerEvent
* @return the output
*/
@NotNull
public ItemStack getItemResult() { return output; }
public ItemStack getOutput() { return output; }
/**
* Get the first item input into the anvil
* @return the first input slot
*/
@NotNull
public ItemStack getItemInput() { return left; }
public ItemStack getLeft() { return left; }
/**
* Get the second item input into the anvil
* @return the second input slot
*/
@NotNull
public ItemStack getIngredientInput() { return right; }
public ItemStack getRight() { return right; }
public float getBreakChance() { return breakChance; }
public void setBreakChance(float breakChance) { this.breakChance = breakChance; }
@@ -33,22 +33,22 @@ import org.jetbrains.annotations.NotNull;
public class ArrowLooseEvent extends PlayerEvent
{
private final ItemStack bow;
private final Level world;
private final Level level;
private final boolean hasAmmo;
private int charge;
public ArrowLooseEvent(Player player, @NotNull ItemStack bow, Level world, int charge, boolean hasAmmo)
public ArrowLooseEvent(Player player, @NotNull ItemStack bow, Level level, int charge, boolean hasAmmo)
{
super(player);
this.bow = bow;
this.world = world;
this.level = level;
this.charge = charge;
this.hasAmmo = hasAmmo;
}
@NotNull
public ItemStack getBow() { return this.bow; }
public Level getWorld() { return this.world; }
public Level getLevel() { return this.level; }
public boolean hasAmmo() { return this.hasAmmo; }
public int getCharge() { return this.charge; }
public void setCharge(int charge) { this.charge = charge; }
@@ -25,22 +25,22 @@ public class ArrowNockEvent extends PlayerEvent
{
private final ItemStack bow;
private final InteractionHand hand;
private final Level world;
private final Level level;
private final boolean hasAmmo;
private InteractionResultHolder<ItemStack> action;
public ArrowNockEvent(Player player, @NotNull ItemStack item, InteractionHand hand, Level world, boolean hasAmmo)
public ArrowNockEvent(Player player, @NotNull ItemStack item, InteractionHand hand, Level level, boolean hasAmmo)
{
super(player);
this.bow = item;
this.hand = hand;
this.world = world;
this.level = level;
this.hasAmmo = hasAmmo;
}
@NotNull
public ItemStack getBow() { return this.bow; }
public Level getWorld() { return this.world; }
public Level getLevel() { return this.level; }
public InteractionHand getHand() { return this.hand; }
public boolean hasAmmo() { return this.hasAmmo; }
public InteractionResultHolder<ItemStack> getAction()
@@ -27,23 +27,23 @@ import org.jetbrains.annotations.NotNull;
public class BonemealEvent extends PlayerEvent
{
private final Level world;
private final Level level;
private final BlockPos pos;
private final BlockState block;
private final ItemStack stack;
public BonemealEvent(@NotNull Player player, @NotNull Level world, @NotNull BlockPos pos, @NotNull BlockState block, @NotNull ItemStack stack)
public BonemealEvent(@NotNull Player player, @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState block, @NotNull ItemStack stack)
{
super(player);
this.world = world;
this.level = level;
this.pos = pos;
this.block = block;
this.stack = stack;
}
public Level getWorld()
public Level getLevel()
{
return world;
return level;
}
public BlockPos getPos()
@@ -29,23 +29,23 @@ public class FillBucketEvent extends PlayerEvent
{
private final ItemStack current;
private final Level world;
private final Level level;
@Nullable
private final HitResult target;
private ItemStack result;
public FillBucketEvent(Player player, @NotNull ItemStack current, Level world, @Nullable HitResult target)
public FillBucketEvent(Player player, @NotNull ItemStack current, Level level, @Nullable HitResult target)
{
super(player);
this.current = current;
this.world = world;
this.level = level;
this.target = target;
}
@NotNull
public ItemStack getEmptyBucket() { return this.current; }
public Level getWorld(){ return this.world; }
public Level getLevel(){ return this.level; }
@Nullable
public HitResult getTarget() { return this.target; }
@NotNull
@@ -23,12 +23,12 @@ public class ItemTooltipEvent extends PlayerEvent
private final List<Component> toolTip;
/**
* 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()}.
* This event is fired in {@link ItemStack#getTooltipLines(Player, TooltipFlag)}, which in turn is called from its respective GUIContainer.
* Tooltips are also gathered with a null player during startup by {@link Minecraft#createSearchTrees()}.
*/
public ItemTooltipEvent(@NotNull ItemStack itemStack, @Nullable Player entityPlayer, List<Component> list, TooltipFlag flags)
public ItemTooltipEvent(@NotNull ItemStack itemStack, @Nullable Player player, List<Component> list, TooltipFlag flags)
{
super(entityPlayer);
super(player);
this.itemStack = itemStack;
this.toolTip = list;
this.flags = flags;
@@ -64,8 +64,8 @@ public class ItemTooltipEvent extends PlayerEvent
*/
@Override
@Nullable
public Player getPlayer()
public Player getEntity()
{
return super.getPlayer();
return super.getEntity();
}
}
@@ -5,7 +5,6 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
@@ -33,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
* {@link Player#attack(Entity)},
* {@code Player#hurtCurrentlyUsedShield(float)},
* {@link Player#interactOn(Entity, InteractionHand)},
* {@link ForgeHooks#getContainerItem(ItemStack)},
* {@link ForgeHooks#getCraftingRemainingItem(ItemStack)},
* {@link ServerPlayerGameMode#useItem(ServerPlayer, Level, ItemStack, InteractionHand)} ,
* {@link ServerPlayerGameMode#useItemOn(ServerPlayer, Level, ItemStack, InteractionHand, BlockHitResult)}
* and {@link ServerPlayerGameMode#destroyBlock(BlockPos)}.<br>
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* PlayerEvent is fired whenever an event involving Living entities occurs. <br>
* PlayerEvent is fired whenever an event involving a {@link Player} occurs. <br>
* If a method utilizes this {@link net.minecraftforge.eventbus.api.Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
@@ -35,17 +35,20 @@ import org.jetbrains.annotations.Nullable;
**/
public class PlayerEvent extends LivingEvent
{
private final Player entityPlayer;
private final Player player;
public PlayerEvent(Player player)
{
super(player);
entityPlayer = player;
this.player = player;
}
@Override
public Player getEntity()
{
return player;
}
/**
* @return Player
*/
public Player getPlayer() { return entityPlayer; }
/**
* HarvestCheck is fired when a player attempts to harvest a block.<br>
* This event is fired whenever a player attempts to harvest a block in
@@ -322,7 +322,7 @@ public class PlayerInteractEvent extends PlayerEvent
@NotNull
public ItemStack getItemStack()
{
return getPlayer().getItemInHand(hand);
return getEntity().getItemInHand(hand);
}
/**
@@ -348,11 +348,11 @@ public class PlayerInteractEvent extends PlayerEvent
}
/**
* @return Convenience method to get the world of this interaction.
* @return Convenience method to get the level of this interaction.
*/
public Level getWorld()
public Level getLevel()
{
return getPlayer().getCommandSenderWorld();
return getEntity().level;
}
/**
@@ -360,7 +360,7 @@ public class PlayerInteractEvent extends PlayerEvent
*/
public LogicalSide getSide()
{
return getWorld().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER;
return getLevel().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER;
}
/**
@@ -19,15 +19,15 @@ import org.jetbrains.annotations.Nullable;
@Cancelable
public class PlayerSetSpawnEvent extends PlayerEvent
{
private final ResourceKey<Level> spawnWorld;
private final ResourceKey<Level> spawnLevel;
private final boolean forced;
@Nullable
private final BlockPos newSpawn;
public PlayerSetSpawnEvent(Player player, ResourceKey<Level> spawnWorld, @Nullable BlockPos newSpawn, boolean forced)
public PlayerSetSpawnEvent(Player player, ResourceKey<Level> spawnLevel, @Nullable BlockPos newSpawn, boolean forced)
{
super(player);
this.spawnWorld = spawnWorld;
this.spawnLevel = spawnLevel;
this.newSpawn = newSpawn;
this.forced = forced;
}
@@ -46,8 +46,8 @@ public class PlayerSetSpawnEvent extends PlayerEvent
return newSpawn;
}
public ResourceKey<Level> getSpawnWorld()
public ResourceKey<Level> getSpawnLevel()
{
return spawnWorld;
return spawnLevel;
}
}
@@ -16,13 +16,13 @@ public class PlayerWakeUpEvent extends PlayerEvent
{
private final boolean wakeImmediately;
private final boolean updateWorld;
private final boolean updateLevel;
public PlayerWakeUpEvent(Player player, boolean wakeImmediately, boolean updateWorld)
public PlayerWakeUpEvent(Player player, boolean wakeImmediately, boolean updateLevel)
{
super(player);
this.wakeImmediately = wakeImmediately;
this.updateWorld = updateWorld;
this.updateLevel = updateLevel;
}
/**
@@ -35,5 +35,5 @@ public class PlayerWakeUpEvent extends PlayerEvent
* Indicates if the server should be notified of sleeping changes.
* This will only be false if the server is considered 'up to date' already, because, for example, it initiated the call.
*/
public boolean updateWorld() { return updateWorld; }
public boolean updateLevel() { return updateLevel; }
}
@@ -3,12 +3,13 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.portal.PortalShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@@ -36,19 +37,19 @@ public class BlockEvent extends Event
{
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
private final LevelAccessor world;
private final LevelAccessor level;
private final BlockPos pos;
private final BlockState state;
public BlockEvent(LevelAccessor world, BlockPos pos, BlockState state)
public BlockEvent(LevelAccessor level, BlockPos pos, BlockState state)
{
this.pos = pos;
this.world = world;
this.level = level;
this.state = state;
}
public LevelAccessor getWorld()
public LevelAccessor getLevel()
{
return world;
return level;
}
public BlockPos getPos()
@@ -72,9 +73,9 @@ public class BlockEvent extends Event
private final Player player;
private int exp;
public BreakEvent(Level world, BlockPos pos, BlockState state, Player player)
public BreakEvent(Level level, BlockPos pos, BlockState state, Player player)
{
super(world, pos, state);
super(level, pos, state);
this.player = player;
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) // Handle empty block or player unable to break block scenario
@@ -85,7 +86,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, world.random, pos, fortuneLevel, silkTouchLevel);
this.exp = state.getExpDrop(level, level.random, pos, fortuneLevel, silkTouchLevel);
}
}
@@ -193,9 +194,9 @@ public class BlockEvent extends Event
private final EnumSet<Direction> notifiedSides;
private final boolean forceRedstoneUpdate;
public NeighborNotifyEvent(Level world, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate)
public NeighborNotifyEvent(Level level, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate)
{
super(world, pos, state);
super(level, pos, state);
this.notifiedSides = notifiedSides;
this.forceRedstoneUpdate = forceRedstoneUpdate;
}
@@ -229,20 +230,20 @@ public class BlockEvent extends Event
@HasResult
public static class CreateFluidSourceEvent extends Event
{
private final LevelReader world;
private final LevelReader level;
private final BlockPos pos;
private final BlockState state;
public CreateFluidSourceEvent(LevelReader world, BlockPos pos, BlockState state)
public CreateFluidSourceEvent(LevelReader level, BlockPos pos, BlockState state)
{
this.world = world;
this.level = level;
this.pos = pos;
this.state = state;
}
public LevelReader getWorld()
public LevelReader getLevel()
{
return world;
return level;
}
public BlockPos getPos()
@@ -271,12 +272,12 @@ public class BlockEvent extends Event
private BlockState newState;
private BlockState origState;
public FluidPlaceBlockEvent(LevelAccessor world, BlockPos pos, BlockPos liquidPos, BlockState state)
public FluidPlaceBlockEvent(LevelAccessor level, BlockPos pos, BlockPos liquidPos, BlockState state)
{
super(world, pos, state);
super(level, pos, state);
this.liquidPos = liquidPos;
this.newState = state;
this.origState = world.getBlockState(pos);
this.origState = level.getBlockState(pos);
}
/**
@@ -315,9 +316,9 @@ public class BlockEvent extends Event
*/
public static class CropGrowEvent extends BlockEvent
{
public CropGrowEvent(Level world, BlockPos pos, BlockState state)
public CropGrowEvent(Level level, BlockPos pos, BlockState state)
{
super(world, pos, state);
super(level, pos, state);
}
/**
@@ -334,9 +335,9 @@ public class BlockEvent extends Event
@HasResult
public static class Pre extends CropGrowEvent
{
public Pre(Level world, BlockPos pos, BlockState state)
public Pre(Level level, BlockPos pos, BlockState state)
{
super(world, pos, state);
super(level, pos, state);
}
}
@@ -352,9 +353,9 @@ public class BlockEvent extends Event
public static class Post extends CropGrowEvent
{
private final BlockState originalState;
public Post(Level world, BlockPos pos, BlockState original, BlockState state)
public Post(Level level, BlockPos pos, BlockState original, BlockState state)
{
super(world, pos, state);
super(level, pos, state);
originalState = original;
}
@@ -376,9 +377,9 @@ public class BlockEvent extends Event
private final Entity entity;
private final float fallDistance;
public FarmlandTrampleEvent(Level world, BlockPos pos, BlockState state, float fallDistance, Entity entity)
public FarmlandTrampleEvent(Level level, BlockPos pos, BlockState state, float fallDistance, Entity entity)
{
super(world, pos, state);
super(level, pos, state);
this.entity = entity;
this.fallDistance = fallDistance;
}
@@ -393,8 +394,8 @@ public class BlockEvent extends Event
}
/* Fired when an attempt is made to spawn a nether portal from
* {@link net.minecraft.block.BlockPortal#trySpawnPortal(World, BlockPos)}.
/** Fired when an attempt is made to spawn a nether portal from
* {@link BaseFireBlock#onPlace(BlockState, Level, BlockPos, BlockState, boolean)}.
*
* If cancelled, the portal will not be spawned.
*/
@@ -403,9 +404,9 @@ public class BlockEvent extends Event
{
private final PortalShape size;
public PortalSpawnEvent(LevelAccessor world, BlockPos pos, BlockState state, PortalShape size)
public PortalSpawnEvent(LevelAccessor level, BlockPos pos, BlockState state, PortalShape size)
{
super(world, pos, state);
super(level, pos, state);
this.size = size;
}
@@ -420,7 +421,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>
* Care must be taken to ensure world-modifying events are only performed if {@link #isSimulated()} returns {@code false}.
* Care must be taken to ensure level-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.
@@ -469,11 +470,11 @@ public class BlockEvent extends Event
}
/**
* Returns {@code true} if this event should not perform any actions that modify the world.
* If {@code false}, then world-modifying actions can be performed.
* Returns {@code true} if this event should not perform any actions that modify the level.
* If {@code false}, then level-modifying actions can be performed.
*
* @return {@code true} if this event should not perform any actions that modify the world.
* If {@code false}, then world-modifying actions can be performed.
* @return {@code true} if this event should not perform any actions that modify the level.
* If {@code false}, then level-modifying actions can be performed.
*/
public boolean isSimulated()
{
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@@ -79,7 +79,7 @@ public class ChunkDataEvent extends ChunkEvent
* This event is fired during chunk saving in
* {@code ChunkMap#save(ChunkAccess)}. <br>
* <br>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
@@ -3,11 +3,8 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.client.multiplayer.ClientChunkCache;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
@@ -16,8 +13,6 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import java.util.BitSet;
/**
* ChunkEvent is fired when an event involving a chunk occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
@@ -27,7 +22,7 @@ import java.util.BitSet;
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkEvent extends WorldEvent
public class ChunkEvent extends LevelEvent
{
private final ChunkAccess chunk;
@@ -37,9 +32,9 @@ public class ChunkEvent extends WorldEvent
this.chunk = chunk;
}
public ChunkEvent(ChunkAccess chunk, LevelAccessor world)
public ChunkEvent(ChunkAccess chunk, LevelAccessor level)
{
super(world);
super(level);
this.chunk = chunk;
}
@@ -49,11 +44,11 @@ public class ChunkEvent extends WorldEvent
}
/**
* ChunkEvent.Load is fired when vanilla Minecraft attempts to load a Chunk into the world.<br>
* ChunkEvent.Load is fired when vanilla Minecraft attempts to load a Chunk into the level.<br>
* This event is fired during chunk loading in <br>
*
*
* Chunk.onChunkLoad(). <br>
* <strong>Note:</strong> This event may be called before the underlying {@link LevelChunk} is promoted to {@link ChunkStatus#FULL}. You will cause chunk loading deadlocks if you don't delay your world interactions.<br>
* <strong>Note:</strong> This event may be called before the underlying {@link LevelChunk} is promoted to {@link ChunkStatus#FULL}. You will cause chunk loading deadlocks if you don't delay your level interactions.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
@@ -70,7 +65,7 @@ public class ChunkEvent extends WorldEvent
}
/**
* ChunkEvent.Unload is fired when vanilla Minecraft attempts to unload a Chunk from the world.<br>
* ChunkEvent.Unload is fired when vanilla Minecraft attempts to unload a Chunk from the level.<br>
* This event is fired during chunk unloading in <br>
* Chunk.onChunkUnload(). <br>
* <br>
@@ -3,61 +3,67 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import org.apache.commons.lang3.mutable.MutableObject;
import net.minecraftforge.fml.LogicalSide;
/**
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.
* This event is fired whenever a chunk has a watch-related action.
* <p>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.
* <p>
* {@link #pos} contains the ChunkPos of the Chunk this event is affecting.<br>
* {@link #world} contains the World of the Chunk this event is affecting.<br>
* {@link #player} contains the {@link ServerPlayer} that is involved with this chunk being watched.
* <p>
* The {@link #player}'s world may not be the same as the world of the chunk
* The {@linkplain #getPlayer() player}'s level may not be the same as the {@linkplain #getLevel() level of the chunk}
* when the player is teleporting to another dimension.
* <p>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public class ChunkWatchEvent extends Event
{
private final ServerLevel world;
private final ServerLevel level;
private final ServerPlayer player;
private final ChunkPos pos;
public ChunkWatchEvent(ServerPlayer player, ChunkPos pos, ServerLevel world)
public ChunkWatchEvent(ServerPlayer player, ChunkPos pos, ServerLevel level)
{
this.player = player;
this.pos = pos;
this.world = world;
this.level = level;
}
/**
* {@return the server player involved with the watch action}
*/
public ServerPlayer getPlayer()
{
return this.player;
}
/**
* {@return the chunk position this watch event is affecting}
*/
public ChunkPos getPos()
{
return this.pos;
}
public ServerLevel getWorld()
/**
* {@return the server level containing the chunk}
*/
public ServerLevel getLevel()
{
return this.world;
return this.level;
}
/**
* ChunkWatchEvent.Watch is fired when a {@link ServerPlayer} begins watching a chunk.
* This event is fired whenever a {@link ServerPlayer} begins watching a chunk.
* <p>
* This event is fired when a chunk is added to the watched chunks of a {@link ServerPlayer}
* and the chunk's data is sent to the client (see
@@ -65,16 +71,18 @@ public class ChunkWatchEvent extends Event
* <p>
* This event may be used to send additional chunk-related data to the client.
* <p>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable} and
* {@link HasResult does not have a result}.
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public static class Watch extends ChunkWatchEvent
{
private final LevelChunk chunk;
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel world)
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel level)
{
super(player, chunk.getPos(), world);
super(player, chunk.getPos(), level);
this.chunk = chunk;
}
@@ -85,16 +93,18 @@ public class ChunkWatchEvent extends Event
}
/**
* ChunkWatchEvent.UnWatch is fired when a {@link ServerPlayer} stops watching a chunk.
* This event is fired whenever a {@link ServerPlayer} stops watching a chunk.
* <p>
* This event is fired when a chunk is removed from the watched chunks of an {@link ServerPlayer}
* in {@code net.minecraft.server.level.ChunkMap#updateChunkTracking(ServerPlayer, ChunkPos, Packet[], boolean, boolean)}.
* <p>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable} and
* {@link HasResult does not have a result}.
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public static class UnWatch extends ChunkWatchEvent
{
public UnWatch(ServerPlayer player, ChunkPos pos, ServerLevel world) {super(player, pos, world);}
public UnWatch(ServerPlayer player, ChunkPos pos, ServerLevel level) {super(player, pos, level);}
}
}
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import java.util.List;
@@ -15,7 +15,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
/** ExplosionEvent triggers when an explosion happens in the world.<br>
/** ExplosionEvent triggers when an explosion happens in the level.<br>
* <br>
* ExplosionEvent.Start is fired before the explosion actually occurs.<br>
* ExplosionEvent.Detonate is fired once the explosion has a list of affected blocks and entities.<br>
@@ -27,18 +27,18 @@ import net.minecraft.world.level.Level;
*/
public class ExplosionEvent extends Event
{
private final Level world;
private final Level level;
private final Explosion explosion;
public ExplosionEvent(Level world, Explosion explosion)
public ExplosionEvent(Level level, Explosion explosion)
{
this.world = world;
this.level = level;
this.explosion = explosion;
}
public Level getWorld()
public Level getLevel()
{
return world;
return level;
}
public Explosion getExplosion()
@@ -48,16 +48,16 @@ public class ExplosionEvent extends Event
/** ExplosionEvent.Start is fired before the explosion actually occurs. Canceling this event will stop the explosion.<br>
* <br>
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* This event is {@link Cancelable}.<br>
* This event does not use {@link HasResult}.<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
@Cancelable
public static class Start extends ExplosionEvent
{
public Start(Level world, Explosion explosion)
public Start(Level level, Explosion explosion)
{
super(world, explosion);
super(level, explosion);
}
}
@@ -71,9 +71,9 @@ public class ExplosionEvent extends Event
{
private final List<Entity> entityList;
public Detonate(Level world, Explosion explosion, List<Entity> entityList)
public Detonate(Level level, Explosion explosion, List<Entity> entityList)
{
super(world, explosion);
super(level, explosion);
this.entityList = entityList;
}
@@ -0,0 +1,120 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.level;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.ProgressListener;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraftforge.common.ForgeInternalHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
/**
* This event is fired whenever an event involving a {@link LevelAccessor} occurs.
* <p>
* All children of this event are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}.
*/
public class LevelEvent extends Event
{
private final LevelAccessor level;
public LevelEvent(LevelAccessor level)
{
this.level = level;
}
/**
* {@return the level this event is affecting}
*/
public LevelAccessor getLevel()
{
return level;
}
/**
* This event is fired whenever a level loads.
* This event is fired whenever a level loads in ClientLevel's constructor and
* {@literal MinecraftServer#createLevels(ChunkProgressListener)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
public static class Load extends LevelEvent
{
public Load(LevelAccessor level) { super(level); }
}
/**
* This event is fired whenever a level unloads.
* This event is fired whenever a level unloads in
* {@link Minecraft#setLevel(ClientLevel)},
* {@link MinecraftServer#stopServer()},
* {@link Minecraft#clearLevel(Screen)}, and
* {@link ForgeInternalHandler#onDimensionUnload(Unload)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
public static class Unload extends LevelEvent
{
public Unload(LevelAccessor level) { super(level); }
}
/**
* This event fires whenever a level is saved.
* This event is fired when a level is saved in
* {@link ServerLevel#save(ProgressListener, boolean, boolean)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public static class Save extends LevelEvent
{
public Save(LevelAccessor level) { super(level); }
}
/**
* This event fires whenever a {@link ServerLevel} is initialized for the first time
* and a spawn position needs to be chosen.
* <p>
* This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
* If the event is canceled, the vanilla logic to choose a spawn position will be skipped.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
*
* @see ServerLevelData#isInitialized()
*/
@Cancelable
public static class CreateSpawnPosition extends LevelEvent
{
private final ServerLevelData settings;
public CreateSpawnPosition(LevelAccessor level, ServerLevelData settings)
{
super(level);
this.settings = settings;
}
public ServerLevelData getSettings()
{
return settings;
}
}
}
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.world.level.block.piston.PistonStructureResolver;
import net.minecraft.core.Direction;
@@ -62,8 +62,8 @@ public abstract class PistonEvent extends BlockEvent
@Nullable
public PistonStructureResolver getStructureHelper()
{
if(this.getWorld() instanceof Level) {
return new PistonStructureResolver((Level) this.getWorld(), this.getPos(), this.getDirection(), this.getPistonMoveType().isExtend);
if(this.getLevel() instanceof Level) {
return new PistonStructureResolver((Level) this.getLevel(), this.getPos(), this.getDirection(), this.getPistonMoveType().isExtend);
} else {
return null;
}
@@ -0,0 +1,58 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.level;
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;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event.HasResult;
/**
* This event is fired whenever a sapling grows into a tree.
* This event is fired during sapling growth in
* {@link SaplingBlock#advanceTree(ServerLevel, BlockPos, BlockState, RandomSource)}.
* <p>
* This event is not {@linkplain Cancelable cancellable} but does {@linkplain HasResult have a result}.
* {@linkplain Result#ALLOW ALLOW} and {@linkplain Result#DEFAULT DEFAULT} will allow the sapling to grow.
* {@linkplain Result#DENY DENY} will prevent the sapling from growing.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain net.minecraftforge.fml.LogicalSide#SERVER logical server}.
*/
@HasResult
public class SaplingGrowTreeEvent extends LevelEvent
{
private final BlockPos pos;
private final RandomSource randomSource;
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos)
{
super(level);
this.randomSource = randomSource;
this.pos = pos;
}
/**
* {@return the coordinates of the sapling attempting to grow}
*/
public BlockPos getPos()
{
return pos;
}
/**
* {@return the random source which initiated the sapling growth}
*/
public RandomSource getRandomSource()
{
return this.randomSource;
}
}
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
package net.minecraftforge.event.level;
import net.minecraft.server.level.ServerLevel;
@@ -12,16 +12,16 @@ import net.minecraft.server.level.ServerLevel;
*
* setWakeUpTime(wakeUpTime) sets a new time that will be added to the dayTime.<br>
*/
public class SleepFinishedTimeEvent extends WorldEvent
public class SleepFinishedTimeEvent extends LevelEvent
{
private long newTime;
private final long minTime;
public SleepFinishedTimeEvent(ServerLevel worldIn, long newTimeIn, long minTimeIn)
public SleepFinishedTimeEvent(ServerLevel level, long newTime, long minTime)
{
super(worldIn);
this.newTime = newTimeIn;
this.minTime = minTimeIn;
super(level);
this.newTime = newTime;
this.minTime = minTime;
}
/**
@@ -27,14 +27,14 @@ import net.minecraftforge.eventbus.api.Event;
public class VillageSiegeEvent extends Event
{
private final VillageSiege siege;
private final Level world;
private final Level level;
private final Player player;
private final Vec3 attemptedSpawnPos;
public VillageSiegeEvent(VillageSiege siege, Level world, Player player, Vec3 attemptedSpawnPos)
public VillageSiegeEvent(VillageSiege siege, Level level, Player player, Vec3 attemptedSpawnPos)
{
this.siege = siege;
this.world = world;
this.level = level;
this.player = player;
this.attemptedSpawnPos = attemptedSpawnPos;
}
@@ -44,9 +44,9 @@ public class VillageSiegeEvent extends Event
return siege;
}
public Level getWorld()
public Level getLevel()
{
return world;
return level;
}
public Player getPlayer()
@@ -1,36 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
/*package net.minecraftforge.event.world;
/**
* Register all of your custom ModDimensons here, fired during server loading when
* dimension data is read from the world file.
*
* Contains a list of missing entries. Registering an entry with the DimensionManger
* will remove the matching entry from the missing list.
* /
public class RegisterDimensionsEvent extends Event
{
private final Map<ResourceLocation, SavedEntry> missing;
private final Set<ResourceLocation> keys;
public RegisterDimensionsEvent(Map<ResourceLocation, SavedEntry> missing)
{
this.missing = missing;
this.keys = Collections.unmodifiableSet(this.missing.keySet());
}
public Set<ResourceLocation> getMissingNames()
{
return keys;
}
@Nullable
public SavedEntry getEntry(ResourceLocation key)
{
return missing.get(key);
}
}*/
@@ -1,57 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
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;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
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, RandomSource)} .<br>
* <br>
* {@link #pos} contains the coordinates of the growing sapling. <br>
* {@link #rand} contains an instance of Random for use. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event has a result. {@link HasResult} <br>
* This result determines if the sapling is allowed to grow. <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@HasResult
public class SaplingGrowTreeEvent extends WorldEvent
{
private final BlockPos pos;
private final RandomSource rand;
public SaplingGrowTreeEvent(LevelAccessor world, RandomSource rand, BlockPos pos)
{
super(world);
this.rand = rand;
this.pos = pos;
}
public BlockPos getPos()
{
return pos;
}
public RandomSource getRand()
{
return rand;
}
}
@@ -1,121 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event.world;
import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.ProgressListener;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraftforge.common.ForgeInternalHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
/**
* WorldEvent is fired when an event involving the world occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the World this event is occurring in.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class WorldEvent extends Event
{
private final LevelAccessor world;
public WorldEvent(LevelAccessor world)
{
this.world = world;
}
public LevelAccessor getWorld()
{
return world;
}
/**
* WorldEvent.Load is fired when Minecraft loads a world.<br>
* This event is fired when a world is loaded in
* {@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>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends WorldEvent
{
public Load(LevelAccessor world) { super(world); }
}
/**
* WorldEvent.Unload is fired when Minecraft unloads a world.<br>
* This event is fired when a world is unloaded in
* {@link Minecraft#setLevel(ClientLevel)},
* {@link MinecraftServer#stopServer()},,
* {@link Minecraft#clearLevel(Screen)}
* {@link ForgeInternalHandler#onDimensionUnload(Unload)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Unload extends WorldEvent
{
public Unload(LevelAccessor world) { super(world); }
}
/**
* WorldEvent.Save is fired when Minecraft saves a world.<br>
* This event is fired when a world is saved in
* {@link ServerLevel#save(ProgressListener, boolean, boolean)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Save extends WorldEvent
{
public Save(LevelAccessor world) { super(world); }
}
/**
* Called by WorldServer when it attempts to create a spawnpoint for a dimension.
* Canceling the event will prevent the vanilla code from running.
*/
@net.minecraftforge.eventbus.api.Cancelable
public static class CreateSpawnPosition extends WorldEvent
{
private final ServerLevelData settings;
public CreateSpawnPosition(LevelAccessor world, ServerLevelData settings)
{
super(world);
this.settings = settings;
}
public ServerLevelData getSettings()
{
return settings;
}
}
}