mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 12:42:26 +00:00
1.21.6 - New EventBus 7
A full rewrite and redesign of the library that offers much better performance, new features and fixes all previous design flaws See the migration guide here: https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91 Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
642 files changed
+7258
-6187
No files matched your search
@@ -8,7 +8,8 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -16,7 +17,11 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* Fired on {@link PackRepository} creation to allow mods to add new pack finders.
|
||||
*/
|
||||
public final class AddPackFindersEvent extends Event implements IModBusEvent {
|
||||
public final class AddPackFindersEvent implements IModBusEvent {
|
||||
public static EventBus<AddPackFindersEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, AddPackFindersEvent.class);
|
||||
}
|
||||
|
||||
private final PackType packType;
|
||||
private final Consumer<RepositorySource> sources;
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -29,7 +30,9 @@ import java.util.concurrent.Executor;
|
||||
* The event is fired on each reload and lets modders add their own ReloadListeners, for server-side resources.
|
||||
* The event is fired on the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
public final class AddReloadListenerEvent extends Event {
|
||||
public final class AddReloadListenerEvent extends MutableEvent {
|
||||
public static final EventBus<AddReloadListenerEvent> BUS = EventBus.create(AddReloadListenerEvent.class);
|
||||
|
||||
private final List<PreparableReloadListener> listeners = new ArrayList<>();
|
||||
private final ReloadableServerResources serverResources;
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -20,8 +21,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
* If the event is not canceled, but the output is not empty, it will set the output and not run vanilla behavior. <br>
|
||||
* if the output is empty, and the event is not canceled, vanilla behavior will execute. <br>
|
||||
*/
|
||||
@Cancelable
|
||||
public final class AnvilUpdateEvent extends Event {
|
||||
public final class AnvilUpdateEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<AnvilUpdateEvent> BUS = CancellableEventBus.create(AnvilUpdateEvent.class);
|
||||
|
||||
private final ItemStack left;
|
||||
private final ItemStack right;
|
||||
private final String name;
|
||||
|
||||
@@ -5,14 +5,23 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.eventbus.api.GenericEvent;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Fired whenever an object with Capabilities support {currently TileEntity/Item/Entity)
|
||||
@@ -20,26 +29,69 @@ import net.minecraftforge.eventbus.api.GenericEvent;
|
||||
*
|
||||
* Please note that as this is fired for ALL object creations efficient code is recommended.
|
||||
* And if possible use one of the sub-classes to filter your intended objects.
|
||||
*
|
||||
* @see Entities
|
||||
* @see BlockEntities
|
||||
* @see ItemStacks
|
||||
* @see Levels
|
||||
* @see LevelChunks
|
||||
*/
|
||||
public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
{
|
||||
@NullMarked
|
||||
public abstract class AttachCapabilitiesEvent<T> extends MutableEvent implements InheritableEvent {
|
||||
private final T obj;
|
||||
private final Map<ResourceLocation, ICapabilityProvider> caps = Maps.newLinkedHashMap();
|
||||
private final Map<ResourceLocation, ICapabilityProvider> caps = new LinkedHashMap<>();
|
||||
private final Map<ResourceLocation, ICapabilityProvider> view = Collections.unmodifiableMap(caps);
|
||||
private final List<Runnable> listeners = Lists.newArrayList();
|
||||
private final List<Runnable> listeners = new ArrayList<>();
|
||||
private final List<Runnable> listenersView = Collections.unmodifiableList(listeners);
|
||||
|
||||
public AttachCapabilitiesEvent(Class<T> type, T obj)
|
||||
{
|
||||
super(type);
|
||||
public static class Entities extends AttachCapabilitiesEvent<Entity> {
|
||||
public static final EventBus<Entities> BUS = EventBus.create(Entities.class);
|
||||
|
||||
public Entities(Entity obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockEntities extends AttachCapabilitiesEvent<BlockEntity> {
|
||||
public static final EventBus<BlockEntities> BUS = EventBus.create(BlockEntities.class);
|
||||
|
||||
public BlockEntities(BlockEntity obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemStacks extends AttachCapabilitiesEvent<ItemStack> {
|
||||
public static final EventBus<ItemStacks> BUS = EventBus.create(ItemStacks.class);
|
||||
|
||||
public ItemStacks(ItemStack obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Levels extends AttachCapabilitiesEvent<Level> {
|
||||
public static final EventBus<Levels> BUS = EventBus.create(Levels.class);
|
||||
|
||||
public Levels(Level obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LevelChunks extends AttachCapabilitiesEvent<LevelChunk> {
|
||||
public static final EventBus<LevelChunks> BUS = EventBus.create(LevelChunks.class);
|
||||
|
||||
public LevelChunks(LevelChunk obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
protected AttachCapabilitiesEvent(T obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the object that is being created, Not much state is set.
|
||||
*/
|
||||
public T getObject()
|
||||
{
|
||||
public T getObject() {
|
||||
return this.obj;
|
||||
}
|
||||
|
||||
@@ -51,8 +103,7 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
* @param key The name of owner of this capability provider.
|
||||
* @param cap The capability provider
|
||||
*/
|
||||
public void addCapability(ResourceLocation key, ICapabilityProvider cap)
|
||||
{
|
||||
public void addCapability(ResourceLocation key, ICapabilityProvider cap) {
|
||||
if (caps.containsKey(key))
|
||||
throw new IllegalStateException("Duplicate Capability Key: " + key + " " + cap);
|
||||
this.caps.put(key, cap);
|
||||
@@ -61,8 +112,7 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
/**
|
||||
* A unmodifiable view of the capabilities that will be attached to this object.
|
||||
*/
|
||||
public Map<ResourceLocation, ICapabilityProvider> getCapabilities()
|
||||
{
|
||||
public Map<ResourceLocation, ICapabilityProvider> getCapabilities() {
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -71,13 +121,11 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
|
||||
* Such as a Entity/TileEntity being removed from world.
|
||||
* All attached providers should invalidate all of their held capability instances.
|
||||
*/
|
||||
public void addListener(Runnable listener)
|
||||
{
|
||||
public void addListener(Runnable listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public List<Runnable> getListeners()
|
||||
{
|
||||
public List<Runnable> getListeners() {
|
||||
return this.listenersView;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraftforge.common.util.MutableHashedLinkedMap;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
@@ -29,7 +29,11 @@ import java.util.function.Supplier;
|
||||
* This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.
|
||||
*/
|
||||
public final class BuildCreativeModeTabContentsEvent extends Event implements IModBusEvent, CreativeModeTab.Output {
|
||||
public final class BuildCreativeModeTabContentsEvent implements IModBusEvent, CreativeModeTab.Output {
|
||||
public static EventBus<BuildCreativeModeTabContentsEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, BuildCreativeModeTabContentsEvent.class);
|
||||
}
|
||||
|
||||
private final CreativeModeTab tab;
|
||||
private final CreativeModeTab.ItemDisplayParameters parameters;
|
||||
private final MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility> entries;
|
||||
|
||||
@@ -9,8 +9,9 @@ import com.mojang.brigadier.ParseResults;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,28 +25,25 @@ import org.jetbrains.annotations.Nullable;
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class CommandEvent extends Event
|
||||
{
|
||||
public final class CommandEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<CommandEvent> BUS = CancellableEventBus.create(CommandEvent.class);
|
||||
|
||||
private ParseResults<CommandSourceStack> parse;
|
||||
@Nullable
|
||||
private Throwable exception;
|
||||
|
||||
public CommandEvent(ParseResults<CommandSourceStack> parse)
|
||||
{
|
||||
public CommandEvent(ParseResults<CommandSourceStack> parse) {
|
||||
this.parse = parse;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the parsed command results}
|
||||
*/
|
||||
public ParseResults<CommandSourceStack> getParseResults()
|
||||
{
|
||||
public ParseResults<CommandSourceStack> getParseResults() {
|
||||
return this.parse;
|
||||
}
|
||||
|
||||
public void setParseResults(ParseResults<CommandSourceStack> parse)
|
||||
{
|
||||
public void setParseResults(ParseResults<CommandSourceStack> parse) {
|
||||
this.parse = parse;
|
||||
}
|
||||
|
||||
@@ -53,13 +51,11 @@ public final class CommandEvent extends Event
|
||||
* {@return an exception to be thrown when performing the command, starts null}
|
||||
*/
|
||||
@Nullable
|
||||
public Throwable getException()
|
||||
{
|
||||
public Throwable getException() {
|
||||
return this.exception;
|
||||
}
|
||||
|
||||
public void setException(@Nullable Throwable exception)
|
||||
{
|
||||
public void setException(@Nullable Throwable exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* DifficultyChangeEvent is fired when difficulty is changing. <br>
|
||||
@@ -19,20 +20,6 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class DifficultyChangeEvent extends Event {
|
||||
private final Difficulty difficulty;
|
||||
private final Difficulty oldDifficulty;
|
||||
|
||||
public DifficultyChangeEvent(Difficulty difficulty, Difficulty oldDifficulty) {
|
||||
this.difficulty = difficulty;
|
||||
this.oldDifficulty = oldDifficulty;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public Difficulty getOldDifficulty() {
|
||||
return oldDifficulty;
|
||||
}
|
||||
public record DifficultyChangeEvent(Difficulty getDifficulty, Difficulty getOldDifficulty) implements RecordEvent {
|
||||
public static final EventBus<DifficultyChangeEvent> BUS = EventBus.create(DifficultyChangeEvent.class);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,19 +5,22 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* <br>
|
||||
* On the client, the GL Context is still valid when the event is fired.
|
||||
* Fired on the FORGE event bus.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
public final class GameShuttingDownEvent extends Event
|
||||
{
|
||||
public GameShuttingDownEvent() {}
|
||||
@NullMarked
|
||||
public record GameShuttingDownEvent() implements SelfDestructing, RecordEvent {
|
||||
public static final EventBus<GameShuttingDownEvent> BUS = EventBus.create(GameShuttingDownEvent.class);
|
||||
}
|
||||
@@ -9,16 +9,17 @@ import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
Where all the events fore Gathering Components will exist.
|
||||
*/
|
||||
/** Where all the events for Gathering Components will exist */
|
||||
public abstract sealed class GatherComponentsEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<GatherComponentsEvent> BUS = EventBus.create(GatherComponentsEvent.class);
|
||||
|
||||
public abstract sealed class GatherComponentsEvent extends Event {
|
||||
private final DataComponentMap.Builder components = DataComponentMap.builder();
|
||||
private final DataComponentMap originalComponents;
|
||||
private final Object owner;
|
||||
@@ -55,6 +56,8 @@ public abstract sealed class GatherComponentsEvent extends Event {
|
||||
* References in {@link net.minecraft.world.item.Items} may not be valid at the current time.
|
||||
*/
|
||||
public static final class Item extends GatherComponentsEvent {
|
||||
public static final EventBus<Item> BUS = EventBus.create(Item.class);
|
||||
|
||||
public Item(net.minecraft.world.item.Item item, DataComponentMap dataComponents) {
|
||||
super(item, dataComponents);
|
||||
}
|
||||
|
||||
@@ -8,17 +8,20 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.GrindstoneMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
public abstract sealed class GrindstoneEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<GrindstoneEvent> BUS = EventBus.create(GrindstoneEvent.class);
|
||||
|
||||
public abstract sealed class GrindstoneEvent extends Event
|
||||
{
|
||||
private final ItemStack top;
|
||||
private final ItemStack bottom;
|
||||
private int xp;
|
||||
|
||||
protected GrindstoneEvent(ItemStack top, ItemStack bottom, int xp)
|
||||
{
|
||||
protected GrindstoneEvent(ItemStack top, ItemStack bottom, int xp) {
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.xp = xp;
|
||||
@@ -27,16 +30,14 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
/**
|
||||
* @return The item in the top input grindstone slot. <br>
|
||||
*/
|
||||
public ItemStack getTopItem()
|
||||
{
|
||||
public ItemStack getTopItem() {
|
||||
return top;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item in the bottom input grindstone slot. <br>
|
||||
*/
|
||||
public ItemStack getBottomItem()
|
||||
{
|
||||
public ItemStack getBottomItem() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
@@ -44,8 +45,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* This is the experience amount determined by the event. It will be {@code -1} unless {@link #setXp(int)} is called. <br>
|
||||
* @return The experience amount given to the player. <br>
|
||||
*/
|
||||
public int getXp()
|
||||
{
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* Sets the experience amount. <br>
|
||||
* @param xp The experience amount given to the player. <br>
|
||||
*/
|
||||
public void setXp(int xp)
|
||||
{
|
||||
public void setXp(int xp) {
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@@ -78,13 +77,12 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* </ul>
|
||||
* </ul>
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class OnPlaceItem extends GrindstoneEvent
|
||||
{
|
||||
public static final class OnPlaceItem extends GrindstoneEvent implements Cancellable {
|
||||
public static final CancellableEventBus<OnPlaceItem> BUS = CancellableEventBus.create(OnPlaceItem.class);
|
||||
|
||||
private ItemStack output;
|
||||
|
||||
public OnPlaceItem(ItemStack top, ItemStack bottom, int xp)
|
||||
{
|
||||
public OnPlaceItem(ItemStack top, ItemStack bottom, int xp) {
|
||||
super(top, bottom, xp);
|
||||
this.output = ItemStack.EMPTY;
|
||||
}
|
||||
@@ -96,8 +94,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* If this event is cancelled, this output stack is discarded. <br>
|
||||
* @return The item to set in the output grindstone slot. <br>
|
||||
*/
|
||||
public ItemStack getOutput()
|
||||
{
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -105,8 +102,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* Sets the output slot to a specific itemstack.
|
||||
* @param output The stack to change the output to.
|
||||
*/
|
||||
public void setOutput(ItemStack output)
|
||||
{
|
||||
public void setOutput(ItemStack output) {
|
||||
this.output = output;
|
||||
}
|
||||
}
|
||||
@@ -118,30 +114,27 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* If the event is canceled, vanilla behavior will not run, and no inputs will be consumed. <br>
|
||||
* if the amount of experience is larger than or equal 0, the vanilla behavior for calculating experience will not run. <br>
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class OnTakeItem extends GrindstoneEvent
|
||||
{
|
||||
public static final class OnTakeItem extends GrindstoneEvent implements Cancellable {
|
||||
public static final CancellableEventBus<OnTakeItem> BUS = CancellableEventBus.create(OnTakeItem.class);
|
||||
|
||||
private ItemStack newTop = ItemStack.EMPTY;
|
||||
private ItemStack newBottom = ItemStack.EMPTY;
|
||||
|
||||
public OnTakeItem(ItemStack top, ItemStack bottom, int xp)
|
||||
{
|
||||
public OnTakeItem(ItemStack top, ItemStack bottom, int xp) {
|
||||
super(top, bottom, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item in that will be in the top input grindstone slot after the event. <br>
|
||||
*/
|
||||
public ItemStack getNewTopItem()
|
||||
{
|
||||
public ItemStack getNewTopItem() {
|
||||
return newTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item in that will be in the bottom input grindstone slot after the event. <br>
|
||||
*/
|
||||
public ItemStack getNewBottomItem()
|
||||
{
|
||||
public ItemStack getNewBottomItem() {
|
||||
return newBottom;
|
||||
}
|
||||
|
||||
@@ -149,8 +142,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* Sets the itemstack in the top slot. <br>
|
||||
* @param newTop
|
||||
*/
|
||||
public void setNewTopItem(ItemStack newTop)
|
||||
{
|
||||
public void setNewTopItem(ItemStack newTop) {
|
||||
this.newTop = newTop;
|
||||
}
|
||||
|
||||
@@ -158,8 +150,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* Sets the itemstack in the bottom slot. <br>
|
||||
* @param newBottom
|
||||
*/
|
||||
public void setNewBottomItem(ItemStack newBottom)
|
||||
{
|
||||
public void setNewBottomItem(ItemStack newBottom) {
|
||||
this.newBottom = newBottom;
|
||||
}
|
||||
|
||||
@@ -167,8 +158,7 @@ public abstract sealed class GrindstoneEvent extends Event
|
||||
* This is the experience amount that will be returned by the event. <br>
|
||||
* @return The experience amount given to the player. <br>
|
||||
*/
|
||||
public int getXp()
|
||||
{
|
||||
public int getXp() {
|
||||
return super.getXp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -33,9 +34,9 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* If the event is cancelled, the container's logic halts, the carried item and the slot will not be swapped, and handling is assumed to have been done by the mod.
|
||||
* This also means that the two vanilla checks described above will not be called.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class ItemStackedOnOtherEvent extends Event
|
||||
{
|
||||
public final class ItemStackedOnOtherEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ItemStackedOnOtherEvent> BUS = CancellableEventBus.create(ItemStackedOnOtherEvent.class);
|
||||
|
||||
private final ItemStack carriedItem;
|
||||
private final ItemStack stackedOnItem;
|
||||
private final Slot slot;
|
||||
@@ -44,8 +45,7 @@ public final class ItemStackedOnOtherEvent extends Event
|
||||
private final SlotAccess carriedSlotAccess;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ItemStackedOnOtherEvent(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess)
|
||||
{
|
||||
public ItemStackedOnOtherEvent(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess) {
|
||||
this.carriedItem = carriedItem;
|
||||
this.stackedOnItem = stackedOnItem;
|
||||
this.slot = slot;
|
||||
@@ -57,48 +57,42 @@ public final class ItemStackedOnOtherEvent extends Event
|
||||
/**
|
||||
* {@return the stack being carried by the mouse} This may be empty!
|
||||
*/
|
||||
public ItemStack getCarriedItem()
|
||||
{
|
||||
public ItemStack getCarriedItem() {
|
||||
return carriedItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the stack currently in the slot being clicked on} This may be empty!
|
||||
*/
|
||||
public ItemStack getStackedOnItem()
|
||||
{
|
||||
public ItemStack getStackedOnItem() {
|
||||
return stackedOnItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the slot being clicked on}
|
||||
*/
|
||||
public Slot getSlot()
|
||||
{
|
||||
public Slot getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the click action being used} By default {@linkplain ClickAction#PRIMARY} corresponds to left-click, and {@linkplain ClickAction#SECONDARY} is right-click.
|
||||
*/
|
||||
public ClickAction getClickAction()
|
||||
{
|
||||
public ClickAction getClickAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player doing the item swap attempt}
|
||||
*/
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a fake slot allowing the listener to see and change what item is being carried}
|
||||
*/
|
||||
public SlotAccess getCarriedSlotAccess()
|
||||
{
|
||||
public SlotAccess getCarriedSlotAccess() {
|
||||
return carriedSlotAccess;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,9 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
@@ -23,30 +24,26 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public final class LootTableLoadEvent extends Event
|
||||
{
|
||||
public final class LootTableLoadEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LootTableLoadEvent> BUS = CancellableEventBus.create(LootTableLoadEvent.class);
|
||||
|
||||
private final ResourceLocation name;
|
||||
private LootTable table;
|
||||
|
||||
public LootTableLoadEvent(ResourceLocation name, LootTable table)
|
||||
{
|
||||
public LootTableLoadEvent(ResourceLocation name, LootTable table) {
|
||||
this.name = name;
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public ResourceLocation getName()
|
||||
{
|
||||
public ResourceLocation getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public LootTable getTable()
|
||||
{
|
||||
public LootTable getTable() {
|
||||
return this.table;
|
||||
}
|
||||
|
||||
public void setTable(LootTable table)
|
||||
{
|
||||
public void setTable(LootTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
@@ -39,8 +39,11 @@ import java.util.stream.Stream;
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* on both {@linkplain LogicalSide logical sides}.</p>
|
||||
*/
|
||||
public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public final class ModMismatchEvent implements IModBusEvent {
|
||||
public static EventBus<ModMismatchEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, ModMismatchEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The level being loaded. Useful for things like {@link net.minecraft.world.level.storage.DimensionDataStorage}
|
||||
* to manage multiple files changing between mod versions.
|
||||
@@ -58,8 +61,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
private final HashMap<String, ModContainer> resolved;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ModMismatchEvent(LevelStorageSource.LevelDirectory levelDirectory, Map<String, ArtifactVersion> previousVersions, Map<String, ArtifactVersion> missingVersions)
|
||||
{
|
||||
public ModMismatchEvent(LevelStorageSource.LevelDirectory levelDirectory, Map<String, ArtifactVersion> previousVersions, Map<String, ArtifactVersion> missingVersions) {
|
||||
this.levelDirectory = levelDirectory;
|
||||
this.resolved = new HashMap<>(previousVersions.size());
|
||||
this.versionDifferences = new HashMap<>();
|
||||
@@ -76,8 +78,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
* Gets the current level directory for the world being loaded.
|
||||
* Can be used for file operations and manual modification of mod files before world load.
|
||||
*/
|
||||
public LevelStorageSource.LevelDirectory getLevelDirectory()
|
||||
{
|
||||
public LevelStorageSource.LevelDirectory getLevelDirectory() {
|
||||
return this.levelDirectory;
|
||||
}
|
||||
|
||||
@@ -87,8 +88,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
* @return The previously known mod version, or {@link Optional#empty()} if unknown/not found.
|
||||
*/
|
||||
@Nullable
|
||||
public ArtifactVersion getPreviousVersion(String modId)
|
||||
{
|
||||
public ArtifactVersion getPreviousVersion(String modId) {
|
||||
if (this.versionDifferences.containsKey(modId))
|
||||
return this.versionDifferences.get(modId).oldVersion();
|
||||
|
||||
@@ -96,8 +96,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ArtifactVersion getCurrentVersion(String modid)
|
||||
{
|
||||
public ArtifactVersion getCurrentVersion(String modid) {
|
||||
if (this.versionDifferences.containsKey(modid))
|
||||
return this.versionDifferences.get(modid).newVersion();
|
||||
|
||||
@@ -107,8 +106,7 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
/**
|
||||
* Marks the mod version mismatch as having been resolved safely by the current mod.
|
||||
*/
|
||||
public void markResolved(String modId)
|
||||
{
|
||||
public void markResolved(String modId) {
|
||||
final var resolvedBy = ModLoadingContext.get().getActiveContainer();
|
||||
resolved.putIfAbsent(modId, resolvedBy);
|
||||
}
|
||||
@@ -116,65 +114,53 @@ public final class ModMismatchEvent extends Event implements IModBusEvent
|
||||
/**
|
||||
* Fetches the status of a mod mismatch handling state.
|
||||
*/
|
||||
public boolean wasResolved(String modId)
|
||||
{
|
||||
public boolean wasResolved(String modId) {
|
||||
return this.resolved.containsKey(modId);
|
||||
}
|
||||
|
||||
public Optional<MismatchedVersionInfo> getVersionDifference(String modid)
|
||||
{
|
||||
public Optional<MismatchedVersionInfo> getVersionDifference(String modid) {
|
||||
return Optional.ofNullable(this.versionDifferences.get(modid));
|
||||
}
|
||||
|
||||
public Optional<ModContainer> getResolver(String modid)
|
||||
{
|
||||
public Optional<ModContainer> getResolver(String modid) {
|
||||
return Optional.ofNullable(this.resolved.get(modid));
|
||||
}
|
||||
|
||||
public boolean anyUnresolved()
|
||||
{
|
||||
public boolean anyUnresolved() {
|
||||
return resolved.size() < versionDifferences.size();
|
||||
}
|
||||
|
||||
public Stream<MismatchResolutionResult> getUnresolved()
|
||||
{
|
||||
public Stream<MismatchResolutionResult> getUnresolved() {
|
||||
return versionDifferences.keySet().stream()
|
||||
.filter(modid -> !resolved.containsKey(modid))
|
||||
.map(unresolved -> new MismatchResolutionResult(unresolved, versionDifferences.get(unresolved), null))
|
||||
.sorted(Comparator.comparing(MismatchResolutionResult::modid));
|
||||
}
|
||||
|
||||
public boolean anyResolved()
|
||||
{
|
||||
public boolean anyResolved() {
|
||||
return !resolved.isEmpty();
|
||||
}
|
||||
|
||||
public Stream<MismatchResolutionResult> getResolved()
|
||||
{
|
||||
public Stream<MismatchResolutionResult> getResolved() {
|
||||
return resolved.keySet().stream()
|
||||
.map(modid -> new MismatchResolutionResult(modid, versionDifferences.get(modid), resolved.get(modid)))
|
||||
.sorted(Comparator.comparing(MismatchResolutionResult::modid));
|
||||
}
|
||||
|
||||
public record MismatchResolutionResult(String modid, MismatchedVersionInfo versionDifference, @Nullable ModContainer resolver)
|
||||
{
|
||||
public boolean wasSelfResolved()
|
||||
{
|
||||
public record MismatchResolutionResult(String modid, MismatchedVersionInfo versionDifference, @Nullable ModContainer resolver) {
|
||||
public boolean wasSelfResolved() {
|
||||
return resolver != null && resolver.getModId().equals(modid);
|
||||
}
|
||||
}
|
||||
|
||||
public record MismatchedVersionInfo(ArtifactVersion oldVersion, @Nullable ArtifactVersion newVersion)
|
||||
{
|
||||
public boolean isMissing()
|
||||
{
|
||||
public record MismatchedVersionInfo(ArtifactVersion oldVersion, @Nullable ArtifactVersion newVersion) {
|
||||
public boolean isMissing() {
|
||||
return newVersion == null;
|
||||
}
|
||||
|
||||
public boolean wasUpgrade()
|
||||
{
|
||||
public boolean wasUpgrade() {
|
||||
if (newVersion == null) return false;
|
||||
return newVersion.compareTo(oldVersion) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,7 +18,9 @@ import java.util.List;
|
||||
* before tags and crafting recipes are sent to the client. Send datapack data
|
||||
* to clients when this event fires.
|
||||
*/
|
||||
public final class OnDatapackSyncEvent extends Event {
|
||||
public final class OnDatapackSyncEvent extends MutableEvent {
|
||||
public static final EventBus<OnDatapackSyncEvent> BUS = EventBus.create(OnDatapackSyncEvent.class);
|
||||
|
||||
private final PlayerList playerList;
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -13,8 +13,11 @@ 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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Objects;
|
||||
@@ -37,8 +40,9 @@ import java.util.Objects;
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public sealed class PlayLevelSoundEvent extends Event {
|
||||
public sealed class PlayLevelSoundEvent extends MutableEvent implements Cancellable, InheritableEvent {
|
||||
public static final CancellableEventBus<PlayLevelSoundEvent> BUS = CancellableEventBus.create(PlayLevelSoundEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final float originalVolume;
|
||||
private final float originalPitch;
|
||||
@@ -150,6 +154,8 @@ public sealed class PlayLevelSoundEvent extends Event {
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static final class AtEntity extends PlayLevelSoundEvent {
|
||||
public static final EventBus<AtEntity> BUS = EventBus.create(AtEntity.class);
|
||||
|
||||
private final Entity entity;
|
||||
|
||||
public AtEntity(Level level, @Nullable Entity entity, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch) {
|
||||
@@ -177,6 +183,8 @@ public sealed class PlayLevelSoundEvent extends Event {
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public static final class AtPosition extends PlayLevelSoundEvent {
|
||||
public static final EventBus<AtPosition> BUS = EventBus.create(AtPosition.class);
|
||||
|
||||
private final Vec3 position;
|
||||
|
||||
public AtPosition(Level level, Vec3 position, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch) {
|
||||
|
||||
@@ -9,11 +9,11 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
|
||||
/**
|
||||
* Commands are rebuilt whenever {@link ReloadableServerResources} is recreated.
|
||||
@@ -21,14 +21,14 @@ import net.minecraft.commands.Commands;
|
||||
*
|
||||
* The event is fired on the {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
public final class RegisterCommandsEvent extends Event
|
||||
{
|
||||
public final class RegisterCommandsEvent extends MutableEvent {
|
||||
public static final EventBus<RegisterCommandsEvent> BUS = EventBus.create(RegisterCommandsEvent.class);
|
||||
|
||||
private final CommandDispatcher<CommandSourceStack> dispatcher;
|
||||
private final Commands.CommandSelection environment;
|
||||
private final CommandBuildContext context;
|
||||
|
||||
public RegisterCommandsEvent(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment, CommandBuildContext context)
|
||||
{
|
||||
public RegisterCommandsEvent(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment, CommandBuildContext context) {
|
||||
this.dispatcher = dispatcher;
|
||||
this.environment = environment;
|
||||
this.context = context;
|
||||
@@ -37,24 +37,21 @@ public final class RegisterCommandsEvent extends Event
|
||||
/**
|
||||
* {@return the command dispatcher for registering commands to be executed on the client}
|
||||
*/
|
||||
public CommandDispatcher<CommandSourceStack> getDispatcher()
|
||||
{
|
||||
public CommandDispatcher<CommandSourceStack> getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the environment the command is being registered for}
|
||||
*/
|
||||
public Commands.CommandSelection getCommandSelection()
|
||||
{
|
||||
public Commands.CommandSelection getCommandSelection() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the context to build the commands for}
|
||||
*/
|
||||
public CommandBuildContext getBuildContext()
|
||||
{
|
||||
public CommandBuildContext getBuildContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,14 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Fired for registering structure conversions for pre-1.18.2 worlds. This is used by {@link StructuresBecomeConfiguredFix}
|
||||
@@ -35,15 +36,16 @@ import com.google.common.base.Preconditions;
|
||||
* @see StructuresBecomeConfiguredFix
|
||||
* @see #register(String, StructuresBecomeConfiguredFix.Conversion)
|
||||
*/
|
||||
public final class RegisterStructureConversionsEvent extends Event
|
||||
{
|
||||
public final class RegisterStructureConversionsEvent extends MutableEvent {
|
||||
public static final EventBus<RegisterStructureConversionsEvent> BUS = EventBus.create(RegisterStructureConversionsEvent.class);
|
||||
|
||||
private final Map<String, StructuresBecomeConfiguredFix.Conversion> map;
|
||||
|
||||
/**
|
||||
* @hidden For internal use only.
|
||||
*/
|
||||
public RegisterStructureConversionsEvent(Map<String, StructuresBecomeConfiguredFix.Conversion> map)
|
||||
{
|
||||
@ApiStatus.Internal
|
||||
public RegisterStructureConversionsEvent(Map<String, StructuresBecomeConfiguredFix.Conversion> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@@ -89,15 +91,13 @@ public final class RegisterStructureConversionsEvent extends Event
|
||||
* @throws IllegalArgumentException if the old structure ID is not in full lowercase, or if a conversion for that
|
||||
* structure ID has already been registered previously
|
||||
*/
|
||||
public void register(String oldStructureID, StructuresBecomeConfiguredFix.Conversion conversion)
|
||||
{
|
||||
public void register(String oldStructureID, StructuresBecomeConfiguredFix.Conversion conversion) {
|
||||
Preconditions.checkNotNull(oldStructureID, "Original structure ID must not be null");
|
||||
Preconditions.checkArgument(oldStructureID.toLowerCase(Locale.ROOT).equals(oldStructureID),
|
||||
"Original structure ID should be in all lowercase");
|
||||
Preconditions.checkNotNull(conversion, "Structure conversion must not be null");
|
||||
Preconditions.checkNotNull(conversion.fallback(), "Fallback structure ID in structure conversion must not be null");
|
||||
if (map.putIfAbsent(oldStructureID.toLowerCase(Locale.ROOT), conversion) != null)
|
||||
{
|
||||
if (map.putIfAbsent(oldStructureID.toLowerCase(Locale.ROOT), conversion) != null) {
|
||||
throw new IllegalArgumentException("Conversion has already been registered for structure " + oldStructureID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,9 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -25,8 +26,9 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class ServerChatEvent extends Event {
|
||||
public final class ServerChatEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ServerChatEvent> BUS = CancellableEventBus.create(ServerChatEvent.class);
|
||||
|
||||
private final ServerPlayer player;
|
||||
private final String username;
|
||||
private final String rawText;
|
||||
|
||||
@@ -6,19 +6,20 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
|
||||
/**
|
||||
* Fired when tags are updated on either server or client. This event can be used to refresh data that depends on tags.
|
||||
*/
|
||||
public final class TagsUpdatedEvent extends Event
|
||||
{
|
||||
public final class TagsUpdatedEvent extends MutableEvent {
|
||||
public static final EventBus<TagsUpdatedEvent> BUS = EventBus.create(TagsUpdatedEvent.class);
|
||||
|
||||
private final RegistryAccess registryAccess;
|
||||
private final UpdateCause updateCause;
|
||||
private final boolean integratedServer;
|
||||
|
||||
public TagsUpdatedEvent(RegistryAccess registryAccess, boolean fromClientPacket, boolean isIntegratedServerConnection)
|
||||
{
|
||||
public TagsUpdatedEvent(RegistryAccess registryAccess, boolean fromClientPacket, boolean isIntegratedServerConnection) {
|
||||
this.registryAccess = registryAccess;
|
||||
this.updateCause = fromClientPacket ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
|
||||
this.integratedServer = isIntegratedServerConnection;
|
||||
@@ -27,16 +28,14 @@ public final class TagsUpdatedEvent extends Event
|
||||
/**
|
||||
* @return The dynamic registries that have had their tags rebound.
|
||||
*/
|
||||
public RegistryAccess getRegistryAccess()
|
||||
{
|
||||
public RegistryAccess getRegistryAccess() {
|
||||
return registryAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cause for this tag update
|
||||
*/
|
||||
public UpdateCause getUpdateCause()
|
||||
{
|
||||
public UpdateCause getUpdateCause() {
|
||||
return updateCause;
|
||||
}
|
||||
|
||||
@@ -44,16 +43,14 @@ public final class TagsUpdatedEvent extends Event
|
||||
* Whether static data (which in single player is shared between server and client thread) should be updated as a
|
||||
* result of this event. Effectively this means that in single player only the server-side updates this data.
|
||||
*/
|
||||
public boolean shouldUpdateStaticData()
|
||||
{
|
||||
public boolean shouldUpdateStaticData() {
|
||||
return updateCause == UpdateCause.SERVER_DATA_LOAD || !integratedServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the cause for a tag update.
|
||||
*/
|
||||
public enum UpdateCause
|
||||
{
|
||||
public enum UpdateCause {
|
||||
/**
|
||||
* The tag update is caused by the server loading datapack data. Note that in single player this still happens
|
||||
* on the client thread.
|
||||
|
||||
@@ -13,10 +13,19 @@ import java.util.function.BooleanSupplier;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
public sealed class TickEvent extends Event {
|
||||
public sealed class TickEvent extends MutableEvent implements InheritableEvent {
|
||||
/**
|
||||
* @deprecated Use one of the subclasses instead, as subscribing to the abstract {@link TickEvent} class will call
|
||||
* your listener possibly hundreds of times per tick which is inefficient/slow and probably not what you want
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<TickEvent> BUS = EventBus.create(TickEvent.class);
|
||||
|
||||
public enum Type {
|
||||
LEVEL, PLAYER, CLIENT, SERVER, RENDER
|
||||
}
|
||||
@@ -27,6 +36,11 @@ public sealed class TickEvent extends Event {
|
||||
|
||||
public final Type type;
|
||||
public final LogicalSide side;
|
||||
|
||||
/**
|
||||
* @deprecated For better performance, add listeners to the Pre or Post event subclasses instead of checking the phase
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public final Phase phase;
|
||||
|
||||
public TickEvent(Type type, LogicalSide side, Phase phase) {
|
||||
@@ -36,6 +50,12 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static sealed class ServerTickEvent extends TickEvent {
|
||||
/**
|
||||
* @deprecated Use {@link ServerTickEvent.Pre} or {@link ServerTickEvent.Post} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<ServerTickEvent> BUS = EventBus.create(ServerTickEvent.class);
|
||||
|
||||
private final BooleanSupplier haveTime;
|
||||
private final MinecraftServer server;
|
||||
|
||||
@@ -62,12 +82,16 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static final class Pre extends ServerTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
public Pre(BooleanSupplier haveTime, MinecraftServer server) {
|
||||
super(haveTime, server, Phase.START);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends ServerTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(BooleanSupplier haveTime, MinecraftServer server) {
|
||||
super(haveTime, server, Phase.END);
|
||||
}
|
||||
@@ -75,17 +99,29 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static sealed class ClientTickEvent extends TickEvent {
|
||||
/**
|
||||
* @deprecated Use {@link ClientTickEvent.Pre} or {@link ClientTickEvent.Post} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<ClientTickEvent> BUS = EventBus.create(ClientTickEvent.class);
|
||||
|
||||
protected ClientTickEvent(Phase phase) {
|
||||
super(Type.CLIENT, LogicalSide.CLIENT, phase);
|
||||
}
|
||||
|
||||
public static final class Pre extends ClientTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
public static final Pre INSTANCE = new Pre();
|
||||
|
||||
public Pre() {
|
||||
super(Phase.START);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends ClientTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
public static final Post INSTANCE = new Post();
|
||||
|
||||
public Post() {
|
||||
super(Phase.END);
|
||||
}
|
||||
@@ -93,6 +129,12 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static sealed class LevelTickEvent extends TickEvent {
|
||||
/**
|
||||
* @deprecated Use {@link LevelTickEvent.Pre} or {@link LevelTickEvent.Post} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<LevelTickEvent> BUS = EventBus.create(LevelTickEvent.class);
|
||||
|
||||
public final Level level;
|
||||
private final BooleanSupplier haveTime;
|
||||
|
||||
@@ -113,12 +155,16 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static final class Pre extends LevelTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
public Pre(LogicalSide side, Level level, BooleanSupplier haveTime) {
|
||||
super(side, level, haveTime, Phase.START);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends LevelTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(LogicalSide side, Level level, BooleanSupplier haveTime) {
|
||||
super(side, level, haveTime, Phase.END);
|
||||
}
|
||||
@@ -126,6 +172,12 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static sealed class PlayerTickEvent extends TickEvent {
|
||||
/**
|
||||
* @deprecated Use {@link PlayerTickEvent.Pre} or {@link PlayerTickEvent.Post} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<PlayerTickEvent> BUS = EventBus.create(PlayerTickEvent.class);
|
||||
|
||||
public final Player player;
|
||||
|
||||
protected PlayerTickEvent(Player player, Phase phase) {
|
||||
@@ -134,19 +186,29 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static final class Pre extends PlayerTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
public Pre(Player player) {
|
||||
super(player, Phase.START);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends PlayerTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(Player player) {
|
||||
super(player, Phase.END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static sealed class RenderTickEvent extends TickEvent {
|
||||
public static sealed abstract class RenderTickEvent extends TickEvent {
|
||||
/**
|
||||
* @deprecated Use {@link RenderTickEvent.Pre} or {@link RenderTickEvent.Post} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.6")
|
||||
public static final EventBus<RenderTickEvent> BUS = EventBus.create(RenderTickEvent.class);
|
||||
|
||||
private final DeltaTracker timer;
|
||||
|
||||
private RenderTickEvent(Phase phase, DeltaTracker timer) {
|
||||
@@ -159,12 +221,16 @@ public sealed class TickEvent extends Event {
|
||||
}
|
||||
|
||||
public static final class Pre extends RenderTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
public Pre(DeltaTracker timer) {
|
||||
super(Phase.START, timer);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends RenderTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(DeltaTracker timer) {
|
||||
super(Phase.END, timer);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,9 @@ 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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -23,16 +24,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* Cancel this event to prevent Vanilla from posting the {@link GameEvent} to all nearby {@link net.minecraft.world.level.gameevent.GameEventListener GameEventListeners}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class VanillaGameEvent extends Event
|
||||
{
|
||||
public final class VanillaGameEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<VanillaGameEvent> BUS = CancellableEventBus.create(VanillaGameEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final GameEvent vanillaEvent;
|
||||
private final Vec3 position;
|
||||
private final GameEvent.Context context;
|
||||
|
||||
public VanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 position, GameEvent.Context context)
|
||||
{
|
||||
public VanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 position, GameEvent.Context context) {
|
||||
this.level = level;
|
||||
this.vanillaEvent = vanillaEvent;
|
||||
this.position = position;
|
||||
@@ -42,8 +42,7 @@ public final class VanillaGameEvent extends Event
|
||||
/**
|
||||
* @return The level the Vanilla {@link GameEvent} occurred.
|
||||
*/
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -51,32 +50,28 @@ public final class VanillaGameEvent extends Event
|
||||
* @return The entity that was the source or "cause" of the {@link GameEvent}.
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getCause()
|
||||
{
|
||||
public Entity getCause() {
|
||||
return context.sourceEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Vanilla event.
|
||||
*/
|
||||
public GameEvent getVanillaEvent()
|
||||
{
|
||||
public GameEvent getVanillaEvent() {
|
||||
return vanillaEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position the event took place at.
|
||||
*/
|
||||
public Vec3 getEventPosition()
|
||||
{
|
||||
public Vec3 getEventPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context of the vanilla event
|
||||
*/
|
||||
public GameEvent.Context getContext()
|
||||
{
|
||||
public GameEvent.Context getContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
package net.minecraftforge.event.brewing;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
@@ -13,38 +15,27 @@ import net.minecraft.world.item.alchemy.PotionBrewing;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraftforge.common.brewing.BrewingRecipe;
|
||||
import net.minecraftforge.common.brewing.IBrewingRecipe;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
public final class BrewingRecipeRegisterEvent extends Event {
|
||||
private final PotionBrewing.Builder builder;
|
||||
private final FeatureFlagSet features;
|
||||
@NullMarked
|
||||
public record BrewingRecipeRegisterEvent(PotionBrewing.Builder getBuilder, FeatureFlagSet getFeatures) implements RecordEvent {
|
||||
public static final EventBus<BrewingRecipeRegisterEvent> BUS = EventBus.create(BrewingRecipeRegisterEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BrewingRecipeRegisterEvent(PotionBrewing.Builder builder, FeatureFlagSet features) {
|
||||
this.builder = builder;
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
public PotionBrewing.Builder getBuilder() {
|
||||
return this.builder;
|
||||
}
|
||||
|
||||
public FeatureFlagSet getFeatures() {
|
||||
return this.features;
|
||||
public BrewingRecipeRegisterEvent {
|
||||
assert getBuilder != null;
|
||||
assert getFeatures != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
||||
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
||||
*
|
||||
* @param input
|
||||
* The Ingredient that goes in same slots as the water bottles
|
||||
* would.
|
||||
* @param ingredient
|
||||
* The Ingredient that goes in the same slot as nether wart would.
|
||||
* @param output
|
||||
* The ItemStack that will replace the input once the brewing is
|
||||
* done.
|
||||
* @param input The Ingredient that goes in same slots as the water bottles
|
||||
* would.
|
||||
* @param ingredient The Ingredient that goes in the same slot as nether wart would.
|
||||
* @param output The ItemStack that will replace the input once the brewing is
|
||||
* done.
|
||||
*/
|
||||
public void addRecipe(Ingredient input, Ingredient ingredient, ItemStack output) {
|
||||
addRecipe(new BrewingRecipe(input, ingredient, output));
|
||||
@@ -55,6 +46,6 @@ public final class BrewingRecipeRegisterEvent extends Event {
|
||||
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
||||
*/
|
||||
public void addRecipe(IBrewingRecipe recipe) {
|
||||
getBuilder().add(recipe);
|
||||
getBuilder.add(recipe);
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,18 @@ 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 net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event is called when a player picks up a potion from a brewing stand.
|
||||
*/
|
||||
public final class PlayerBrewedPotionEvent extends PlayerEvent
|
||||
{
|
||||
public final class PlayerBrewedPotionEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerBrewedPotionEvent> BUS = EventBus.create(PlayerBrewedPotionEvent.class);
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
public PlayerBrewedPotionEvent(Player player, @NotNull ItemStack stack)
|
||||
{
|
||||
public PlayerBrewedPotionEvent(Player player, @NotNull ItemStack stack) {
|
||||
super(player);
|
||||
this.stack = stack;
|
||||
}
|
||||
@@ -27,8 +28,7 @@ public final class PlayerBrewedPotionEvent extends PlayerEvent
|
||||
* The ItemStack of the potion.
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getStack()
|
||||
{
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -8,36 +8,35 @@ package net.minecraftforge.event.brewing;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public sealed class PotionBrewEvent extends Event
|
||||
{
|
||||
public sealed abstract class PotionBrewEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<PotionBrewEvent> BUS = EventBus.create(PotionBrewEvent.class);
|
||||
|
||||
private final NonNullList<ItemStack> stacks;
|
||||
|
||||
protected PotionBrewEvent(NonNullList<ItemStack> stacks)
|
||||
{
|
||||
protected PotionBrewEvent(NonNullList<ItemStack> stacks) {
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getItem(int index)
|
||||
{
|
||||
public ItemStack getItem(int index) {
|
||||
if (index < 0 || index >= stacks.size()) return ItemStack.EMPTY;
|
||||
return stacks.get(index);
|
||||
}
|
||||
|
||||
public void setItem(int index, @NotNull ItemStack stack)
|
||||
{
|
||||
if (index < stacks.size())
|
||||
{
|
||||
public void setItem(int index, @NotNull ItemStack stack) {
|
||||
if (index < stacks.size()) {
|
||||
stacks.set(index, stack);
|
||||
}
|
||||
}
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
public int getLength() {
|
||||
return stacks.size();
|
||||
}
|
||||
|
||||
@@ -58,11 +57,10 @@ public sealed class PotionBrewEvent extends Event
|
||||
* <br>
|
||||
* If this event is canceled, and items have been modified, PotionBrewEvent.Post will automatically be fired.
|
||||
**/
|
||||
@Cancelable
|
||||
public static final class Pre extends PotionBrewEvent
|
||||
{
|
||||
public Pre(NonNullList<ItemStack> stacks)
|
||||
{
|
||||
public static final class Pre extends PotionBrewEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
public Pre(NonNullList<ItemStack> stacks) {
|
||||
super(stacks);
|
||||
}
|
||||
}
|
||||
@@ -80,10 +78,10 @@ public sealed class PotionBrewEvent extends Event
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static final class Post extends PotionBrewEvent
|
||||
{
|
||||
public Post(NonNullList<ItemStack> stacks)
|
||||
{
|
||||
public static final class Post extends PotionBrewEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(NonNullList<ItemStack> stacks) {
|
||||
super(stacks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ package net.minecraftforge.event.enchanting;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -18,8 +20,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
* from 0-15 and indicates how many bookshelves surround the enchanting table. The {@link #itemStack} representing the item being
|
||||
* enchanted is also available.
|
||||
*/
|
||||
public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
public final class EnchantmentLevelSetEvent extends MutableEvent {
|
||||
public static final EventBus<EnchantmentLevelSetEvent> BUS = EventBus.create(EnchantmentLevelSetEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
private final int enchantRow;
|
||||
@@ -29,8 +32,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
private final int originalLevel;
|
||||
private int enchantLevel;
|
||||
|
||||
public EnchantmentLevelSetEvent(Level level, BlockPos pos, int enchantRow, int power, @NotNull ItemStack itemStack, int enchantLevel)
|
||||
{
|
||||
public EnchantmentLevelSetEvent(Level level, BlockPos pos, int enchantRow, int power, @NotNull ItemStack itemStack, int enchantLevel) {
|
||||
this.level = level;
|
||||
this.pos = pos;
|
||||
this.enchantRow = enchantRow;
|
||||
@@ -45,8 +47,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the world object
|
||||
*/
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -55,8 +56,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the pos of the enchantment table
|
||||
*/
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the row for which the enchantment level is being set
|
||||
*/
|
||||
public int getEnchantRow()
|
||||
{
|
||||
public int getEnchantRow() {
|
||||
return enchantRow;
|
||||
}
|
||||
|
||||
@@ -75,8 +74,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the power (# of bookshelves) for the enchanting table
|
||||
*/
|
||||
public int getPower()
|
||||
{
|
||||
public int getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
@@ -86,8 +84,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
* @return the item being enchanted
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItem()
|
||||
{
|
||||
public ItemStack getItem() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -96,8 +93,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the original level of the enchantment for this row (0-30)
|
||||
*/
|
||||
public int getOriginalLevel()
|
||||
{
|
||||
public int getOriginalLevel() {
|
||||
return originalLevel;
|
||||
}
|
||||
|
||||
@@ -106,8 +102,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @return the level of the enchantment for this row (0-30)
|
||||
*/
|
||||
public int getEnchantLevel()
|
||||
{
|
||||
public int getEnchantLevel() {
|
||||
return enchantLevel;
|
||||
}
|
||||
|
||||
@@ -116,8 +111,7 @@ public final class EnchantmentLevelSetEvent extends net.minecraftforge.eventbus.
|
||||
*
|
||||
* @param level the new level of the enchantment (0-30)
|
||||
*/
|
||||
public void setEnchantLevel(int level)
|
||||
{
|
||||
public void setEnchantLevel(int level) {
|
||||
this.enchantLevel = level;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
||||
import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,11 @@ import net.minecraftforge.fml.event.IModBusEvent;
|
||||
* <br>
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
**/
|
||||
public final class EntityAttributeCreationEvent extends Event implements IModBusEvent {
|
||||
public final class EntityAttributeCreationEvent implements IModBusEvent {
|
||||
public static EventBus<EntityAttributeCreationEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, EntityAttributeCreationEvent.class);
|
||||
}
|
||||
|
||||
private final Map<EntityType<? extends LivingEntity>, AttributeSupplier> map;
|
||||
|
||||
public EntityAttributeCreationEvent(Map<EntityType<? extends LivingEntity>, AttributeSupplier> map) {
|
||||
|
||||
@@ -13,7 +13,8 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
||||
import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@@ -28,7 +29,11 @@ import java.util.stream.Collectors;
|
||||
* <br>
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
**/
|
||||
public final class EntityAttributeModificationEvent extends Event implements IModBusEvent {
|
||||
public final class EntityAttributeModificationEvent implements IModBusEvent {
|
||||
public static EventBus<EntityAttributeModificationEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, EntityAttributeModificationEvent.class);
|
||||
}
|
||||
|
||||
private final Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> entityAttributes;
|
||||
private final List<EntityType<? extends LivingEntity>> entityTypes;
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ package net.minecraftforge.event.entity;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
|
||||
/**
|
||||
* EntityEvent is fired when an event involving any Entity occurs.<br>
|
||||
@@ -19,7 +21,9 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class EntityEvent extends Event {
|
||||
public class EntityEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<EntityEvent> BUS = EventBus.create(EntityEvent.class);
|
||||
|
||||
private final Entity entity;
|
||||
|
||||
public EntityEvent(Entity entity) {
|
||||
@@ -41,6 +45,8 @@ public class EntityEvent extends Event {
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static final class EntityConstructing extends EntityEvent {
|
||||
public static final EventBus<EntityConstructing> BUS = EventBus.create(EntityConstructing.class);
|
||||
|
||||
public EntityConstructing(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
@@ -59,6 +65,8 @@ public class EntityEvent extends Event {
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static final class EnteringSection extends EntityEvent {
|
||||
public static final EventBus<EnteringSection> BUS = EventBus.create(EnteringSection.class);
|
||||
|
||||
private final long packedOldPos;
|
||||
private final long packedNewPos;
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
@@ -26,8 +27,9 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class EntityJoinLevelEvent extends EntityEvent {
|
||||
public final class EntityJoinLevelEvent extends EntityEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityJoinLevelEvent> BUS = CancellableEventBus.create(EntityJoinLevelEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final boolean loadedFromDisk;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ 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;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* This event is fired whenever an {@link Entity} leaves a {@link Level}.
|
||||
@@ -21,6 +21,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* on both logical sides.
|
||||
**/
|
||||
public final class EntityLeaveLevelEvent extends EntityEvent {
|
||||
public static final EventBus<EntityLeaveLevelEvent> BUS = EventBus.create(EntityLeaveLevelEvent.class);
|
||||
|
||||
private final Level level;
|
||||
|
||||
public EntityLeaveLevelEvent(Entity entity, Level level) {
|
||||
|
||||
@@ -7,7 +7,9 @@ package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* EntityMobGriefingEvent is fired when mob griefing is about to occur and allows an event listener to specify whether it should or not.<br>
|
||||
@@ -21,11 +23,22 @@ import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
* </ul>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@HasResult
|
||||
public final class EntityMobGriefingEvent extends EntityEvent
|
||||
{
|
||||
public EntityMobGriefingEvent(Entity entity)
|
||||
{
|
||||
public final class EntityMobGriefingEvent extends EntityEvent implements HasResult {
|
||||
public static final EventBus<EntityMobGriefingEvent> BUS = EventBus.create(EntityMobGriefingEvent.class);
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public EntityMobGriefingEvent(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ package net.minecraftforge.event.entity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event gets fired whenever a entity mounts/dismounts another entity.<br>
|
||||
@@ -23,10 +24,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*
|
||||
*/
|
||||
|
||||
@Cancelable
|
||||
public final class EntityMountEvent extends EntityEvent
|
||||
{
|
||||
public final class EntityMountEvent extends EntityEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityMountEvent> BUS = CancellableEventBus.create(EntityMountEvent.class);
|
||||
|
||||
private final Entity entityMounting;
|
||||
private final Entity entityBeingMounted;
|
||||
@@ -34,8 +33,7 @@ public final class EntityMountEvent extends EntityEvent
|
||||
|
||||
private final boolean isMounting;
|
||||
|
||||
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, Level level, boolean isMounting)
|
||||
{
|
||||
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, Level level, boolean isMounting) {
|
||||
super(entityMounting);
|
||||
this.entityMounting = entityMounting;
|
||||
this.entityBeingMounted = entityBeingMounted;
|
||||
@@ -43,28 +41,23 @@ public final class EntityMountEvent extends EntityEvent
|
||||
this.isMounting = isMounting;
|
||||
}
|
||||
|
||||
public boolean isMounting()
|
||||
{
|
||||
public boolean isMounting() {
|
||||
return isMounting;
|
||||
}
|
||||
|
||||
public boolean isDismounting()
|
||||
{
|
||||
public boolean isDismounting() {
|
||||
return !isMounting;
|
||||
}
|
||||
|
||||
public Entity getEntityMounting()
|
||||
{
|
||||
public Entity getEntityMounting() {
|
||||
return entityMounting;
|
||||
}
|
||||
|
||||
public Entity getEntityBeingMounted()
|
||||
{
|
||||
public Entity getEntityBeingMounted() {
|
||||
return entityBeingMounted;
|
||||
}
|
||||
|
||||
public Level getLevel()
|
||||
{
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* EntityStruckByLightningEvent is fired when an Entity is about to be struck by lightening.<br>
|
||||
@@ -25,19 +26,17 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public final class EntityStruckByLightningEvent extends EntityEvent
|
||||
{
|
||||
public final class EntityStruckByLightningEvent extends EntityEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityStruckByLightningEvent> BUS = CancellableEventBus.create(EntityStruckByLightningEvent.class);
|
||||
|
||||
private final LightningBolt lightning;
|
||||
|
||||
public EntityStruckByLightningEvent(Entity entity, LightningBolt lightning)
|
||||
{
|
||||
public EntityStruckByLightningEvent(Entity entity, LightningBolt lightning) {
|
||||
super(entity);
|
||||
this.lightning = lightning;
|
||||
}
|
||||
|
||||
public LightningBolt getLightning()
|
||||
{
|
||||
public LightningBolt getLightning() {
|
||||
return lightning;
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,9 +28,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
@Cancelable
|
||||
public sealed class EntityTeleportEvent extends EntityEvent
|
||||
{
|
||||
public sealed class EntityTeleportEvent extends EntityEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityTeleportEvent> BUS = CancellableEventBus.create(EntityTeleportEvent.class);
|
||||
|
||||
protected double targetX;
|
||||
protected double targetY;
|
||||
protected double targetZ;
|
||||
@@ -69,11 +69,10 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class TeleportCommand extends EntityTeleportEvent
|
||||
{
|
||||
public TeleportCommand(Entity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
public static final class TeleportCommand extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<TeleportCommand> BUS = CancellableEventBus.create(TeleportCommand.class);
|
||||
|
||||
public TeleportCommand(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
}
|
||||
}
|
||||
@@ -93,11 +92,10 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class SpreadPlayersCommand extends EntityTeleportEvent
|
||||
{
|
||||
public SpreadPlayersCommand(Entity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
public static final class SpreadPlayersCommand extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<SpreadPlayersCommand> BUS = CancellableEventBus.create(SpreadPlayersCommand.class);
|
||||
|
||||
public SpreadPlayersCommand(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
}
|
||||
}
|
||||
@@ -116,19 +114,17 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class EnderEntity extends EntityTeleportEvent
|
||||
{
|
||||
public static final class EnderEntity extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<EnderEntity> BUS = CancellableEventBus.create(EnderEntity.class);
|
||||
|
||||
private final LivingEntity entityLiving;
|
||||
|
||||
public EnderEntity(LivingEntity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
public EnderEntity(LivingEntity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.entityLiving = entity;
|
||||
}
|
||||
|
||||
public LivingEntity getEntityLiving()
|
||||
{
|
||||
public LivingEntity getEntityLiving() {
|
||||
return entityLiving;
|
||||
}
|
||||
}
|
||||
@@ -147,17 +143,16 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class EnderPearl extends EntityTeleportEvent
|
||||
{
|
||||
public static final class EnderPearl extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<EnderPearl> BUS = CancellableEventBus.create(EnderPearl.class);
|
||||
|
||||
private final ServerPlayer player;
|
||||
private final ThrownEnderpearl pearlEntity;
|
||||
private float attackDamage;
|
||||
private final HitResult hitResult;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public EnderPearl(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage, HitResult hitResult)
|
||||
{
|
||||
public EnderPearl(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage, HitResult hitResult) {
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.pearlEntity = pearlEntity;
|
||||
this.player = entity;
|
||||
@@ -165,29 +160,24 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
this.hitResult = hitResult;
|
||||
}
|
||||
|
||||
public ThrownEnderpearl getPearlEntity()
|
||||
{
|
||||
public ThrownEnderpearl getPearlEntity() {
|
||||
return pearlEntity;
|
||||
}
|
||||
|
||||
public ServerPlayer getPlayer()
|
||||
{
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public HitResult getHitResult()
|
||||
{
|
||||
public HitResult getHitResult() {
|
||||
return this.hitResult;
|
||||
}
|
||||
|
||||
public float getAttackDamage()
|
||||
{
|
||||
public float getAttackDamage() {
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
public void setAttackDamage(float attackDamage)
|
||||
{
|
||||
public void setAttackDamage(float attackDamage) {
|
||||
this.attackDamage = attackDamage;
|
||||
}
|
||||
}
|
||||
@@ -206,19 +196,17 @@ public sealed class EntityTeleportEvent extends EntityEvent
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class ChorusFruit extends EntityTeleportEvent
|
||||
{
|
||||
public static final class ChorusFruit extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<ChorusFruit> BUS = CancellableEventBus.create(ChorusFruit.class);
|
||||
|
||||
private final LivingEntity entityLiving;
|
||||
|
||||
public ChorusFruit(LivingEntity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
public ChorusFruit(LivingEntity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.entityLiving = entity;
|
||||
}
|
||||
|
||||
public LivingEntity getEntityLiving()
|
||||
{
|
||||
public LivingEntity getEntityLiving() {
|
||||
return entityLiving;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* EntityTravelToDimensionEvent is fired before an Entity travels to a dimension.<br>
|
||||
@@ -23,19 +24,17 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
@Cancelable
|
||||
public final class EntityTravelToDimensionEvent extends EntityEvent
|
||||
{
|
||||
public final class EntityTravelToDimensionEvent extends EntityEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityTravelToDimensionEvent> BUS = CancellableEventBus.create(EntityTravelToDimensionEvent.class);
|
||||
|
||||
private final ResourceKey<Level> dimension;
|
||||
|
||||
public EntityTravelToDimensionEvent(Entity entity, ResourceKey<Level> dimension)
|
||||
{
|
||||
public EntityTravelToDimensionEvent(Entity entity, ResourceKey<Level> dimension) {
|
||||
super(entity);
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public ResourceKey<Level> getDimension()
|
||||
{
|
||||
public ResourceKey<Level> getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -23,6 +24,8 @@ import java.util.Objects;
|
||||
* @see #setImpactResult(ImpactResult)
|
||||
*/
|
||||
public final class ProjectileImpactEvent extends EntityEvent {
|
||||
public static final EventBus<ProjectileImpactEvent> BUS = EventBus.create(ProjectileImpactEvent.class);
|
||||
|
||||
private final HitResult ray;
|
||||
private final Projectile projectile;
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@ import net.minecraft.world.entity.SpawnPlacementType;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.SpawnPlacements;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@@ -42,7 +41,11 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
*
|
||||
* Fired on the Mod bus {@link IModBusEvent}.<br>
|
||||
*/
|
||||
public final class SpawnPlacementRegisterEvent extends Event implements IModBusEvent {
|
||||
public final class SpawnPlacementRegisterEvent implements IModBusEvent {
|
||||
public static EventBus<SpawnPlacementRegisterEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, SpawnPlacementRegisterEvent.class);
|
||||
}
|
||||
|
||||
private final Map<EntityType<?>, MergedSpawnPredicate<?>> map;
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.event.entity.item;
|
||||
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* Base class for all {@link ItemEntity} events. Contains a reference to the
|
||||
@@ -14,8 +15,9 @@ import net.minecraftforge.event.entity.EntityEvent;
|
||||
* additional useful data from the firing method that isn't already contained
|
||||
* within the ItemEntity instance.
|
||||
*/
|
||||
public class ItemEvent extends EntityEvent
|
||||
{
|
||||
public sealed class ItemEvent extends EntityEvent permits ItemExpireEvent, ItemTossEvent {
|
||||
public static final EventBus<ItemEvent> BUS = EventBus.create(ItemEvent.class);
|
||||
|
||||
private final ItemEntity itemEntity;
|
||||
|
||||
/**
|
||||
@@ -23,8 +25,7 @@ public class ItemEvent extends EntityEvent
|
||||
*
|
||||
* @param itemEntity The ItemEntity for this event
|
||||
*/
|
||||
public ItemEvent(ItemEntity itemEntity)
|
||||
{
|
||||
public ItemEvent(ItemEntity itemEntity) {
|
||||
super(itemEntity);
|
||||
this.itemEntity = itemEntity;
|
||||
}
|
||||
@@ -33,8 +34,7 @@ public class ItemEvent extends EntityEvent
|
||||
* The relevant {@link ItemEntity} for this event.
|
||||
*/
|
||||
@Override
|
||||
public ItemEntity getEntity()
|
||||
{
|
||||
public ItemEntity getEntity() {
|
||||
return itemEntity;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
package net.minecraftforge.event.entity.item;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* Event that is fired when an EntityItem's age has reached its maximum
|
||||
@@ -14,9 +15,8 @@ import net.minecraft.world.entity.item.ItemEntity;
|
||||
* flagged as dead, thus staying it's removal from the world. If canceled
|
||||
* it will add more time to the entities life equal to extraLife.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class ItemExpireEvent extends ItemEvent
|
||||
{
|
||||
public final class ItemExpireEvent extends ItemEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ItemExpireEvent> BUS = CancellableEventBus.create(ItemExpireEvent.class);
|
||||
|
||||
private int extraLife;
|
||||
|
||||
@@ -26,19 +26,16 @@ public final class ItemExpireEvent extends ItemEvent
|
||||
* @param entityItem The EntityItem being deleted.
|
||||
* @param extraLife The amount of time to be added to this entities lifespan if the event is canceled.
|
||||
*/
|
||||
public ItemExpireEvent(ItemEntity entityItem, int extraLife)
|
||||
{
|
||||
public ItemExpireEvent(ItemEntity entityItem, int extraLife) {
|
||||
super(entityItem);
|
||||
this.setExtraLife(extraLife);
|
||||
}
|
||||
|
||||
public int getExtraLife()
|
||||
{
|
||||
public int getExtraLife() {
|
||||
return extraLife;
|
||||
}
|
||||
|
||||
public void setExtraLife(int extraLife)
|
||||
{
|
||||
public void setExtraLife(int extraLife) {
|
||||
this.extraLife = extraLife;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
package net.minecraftforge.event.entity.item;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* Event that is fired whenever a player tosses (Q) an item or drag-n-drops a
|
||||
@@ -15,9 +16,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
* stop the items from entering the world, but will not prevent them being
|
||||
* removed from the inventory - and thus removed from the system.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class ItemTossEvent extends ItemEvent
|
||||
{
|
||||
public final class ItemTossEvent extends ItemEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ItemTossEvent> BUS = CancellableEventBus.create(ItemTossEvent.class);
|
||||
|
||||
private final Player player;
|
||||
|
||||
@@ -27,8 +27,7 @@ public final class ItemTossEvent extends ItemEvent
|
||||
* @param entityItem The EntityItem being tossed.
|
||||
* @param player The player tossing the item.
|
||||
*/
|
||||
public ItemTossEvent(ItemEntity entityItem, Player player)
|
||||
{
|
||||
public ItemTossEvent(ItemEntity entityItem, Player player) {
|
||||
super(entityItem);
|
||||
this.player = player;
|
||||
}
|
||||
@@ -36,8 +35,7 @@ public final class ItemTossEvent extends ItemEvent
|
||||
/**
|
||||
* The player tossing the item.
|
||||
*/
|
||||
public Player getPlayer()
|
||||
{
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event is fired when an {@link Animal} is tamed. <br>
|
||||
@@ -18,26 +19,23 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}. If canceled, taming the animal will fail.
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class AnimalTameEvent extends LivingEvent
|
||||
{
|
||||
public final class AnimalTameEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<AnimalTameEvent> BUS = CancellableEventBus.create(AnimalTameEvent.class);
|
||||
|
||||
private final Animal animal;
|
||||
private final Player tamer;
|
||||
|
||||
public AnimalTameEvent(Animal animal, Player tamer)
|
||||
{
|
||||
public AnimalTameEvent(Animal animal, Player tamer) {
|
||||
super(animal);
|
||||
this.animal = animal;
|
||||
this.tamer = tamer;
|
||||
}
|
||||
|
||||
public Animal getAnimal()
|
||||
{
|
||||
public Animal getAnimal() {
|
||||
return animal;
|
||||
}
|
||||
|
||||
public Player getTamer()
|
||||
{
|
||||
public Player getTamer() {
|
||||
return tamer;
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,10 @@ import net.minecraft.world.entity.animal.Animal;
|
||||
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 net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -37,8 +38,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class BabyEntitySpawnEvent extends Event {
|
||||
public final class BabyEntitySpawnEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<BabyEntitySpawnEvent> BUS = CancellableEventBus.create(BabyEntitySpawnEvent.class);
|
||||
|
||||
private final Mob parentA;
|
||||
private final Mob parentB;
|
||||
private final Player causedByPlayer;
|
||||
|
||||
@@ -8,9 +8,10 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingAttackEvent is fired when a living Entity is attacked. <br>
|
||||
@@ -30,13 +31,13 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
*<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingAttackEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingAttackEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingAttackEvent> BUS = CancellableEventBus.create(LivingAttackEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private final float amount;
|
||||
public LivingAttackEvent(LivingEntity entity, DamageSource source, float amount)
|
||||
{
|
||||
|
||||
public LivingAttackEvent(LivingEntity entity, DamageSource source, float amount) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.amount = amount;
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* LivingBreatheEvent is fired whenever a living entity ticks.<br>
|
||||
@@ -24,6 +24,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
public final class LivingBreatheEvent extends LivingEvent {
|
||||
public static final EventBus<LivingBreatheEvent> BUS = EventBus.create(LivingBreatheEvent.class);
|
||||
|
||||
private boolean canBreathe;
|
||||
private boolean canRefillAir;
|
||||
private int consumeAirAmount;
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.ai.behavior.StartAttacking;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event allows you to change the target an entity has. <br>
|
||||
@@ -33,8 +34,9 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class LivingChangeTargetEvent extends LivingEvent {
|
||||
public final class LivingChangeTargetEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingChangeTargetEvent> BUS = CancellableEventBus.create(LivingChangeTargetEvent.class);
|
||||
|
||||
private final ILivingTargetType targetType;
|
||||
private final LivingEntity originalTarget;
|
||||
private LivingEntity newTarget;
|
||||
@@ -81,12 +83,12 @@ public final class LivingChangeTargetEvent extends LivingEvent {
|
||||
* targets. For a list of default target types, take a look at
|
||||
* {@link LivingTargetType}.
|
||||
*/
|
||||
public static interface ILivingTargetType { }
|
||||
public interface ILivingTargetType {}
|
||||
|
||||
/**
|
||||
* This enum contains two default living target types.
|
||||
*/
|
||||
public static enum LivingTargetType implements ILivingTargetType {
|
||||
public enum LivingTargetType implements ILivingTargetType {
|
||||
/**
|
||||
* This target type indicates that the target has been set by calling {@link Mob#setTarget(LivingEntity)}.
|
||||
*/
|
||||
@@ -94,6 +96,6 @@ public final class LivingChangeTargetEvent extends LivingEvent {
|
||||
/**
|
||||
* This target type indicates that the target has been set by the {@link StartAttacking} behavior.
|
||||
*/
|
||||
BEHAVIOR_TARGET;
|
||||
BEHAVIOR_TARGET
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -25,7 +28,9 @@ import java.util.function.Consumer;
|
||||
* Tadpole -> Frog when it grows up
|
||||
* Mushroom Cow -> Cow when sheared
|
||||
*/
|
||||
public sealed class LivingConversionEvent extends LivingEvent {
|
||||
public sealed class LivingConversionEvent extends LivingEvent implements InheritableEvent {
|
||||
public static final EventBus<LivingConversionEvent> BUS = EventBus.create(LivingConversionEvent.class);
|
||||
|
||||
public LivingConversionEvent(LivingEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
@@ -41,8 +46,9 @@ public sealed class LivingConversionEvent extends LivingEvent {
|
||||
* This event is {@link Cancelable}
|
||||
* If cancelled, the replacement will not occur
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Pre extends LivingConversionEvent {
|
||||
public static final class Pre extends LivingConversionEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
private final EntityType<? extends LivingEntity> outcome;
|
||||
private final Consumer<Integer> timer;
|
||||
|
||||
@@ -80,6 +86,8 @@ public sealed class LivingConversionEvent extends LivingEvent {
|
||||
* The old living entity is likely to be removed right after this event.
|
||||
*/
|
||||
public static final class Post extends LivingConversionEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
private final LivingEntity outcome;
|
||||
|
||||
public Post(LivingEntity entity, LivingEntity outcome) {
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingDamageEvent is fired just before damage is applied to entity.<br>
|
||||
@@ -29,13 +30,13 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* @see LivingHurtEvent
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingDamageEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingDamageEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingDamageEvent> BUS = CancellableEventBus.create(LivingDamageEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private float amount;
|
||||
public LivingDamageEvent(LivingEntity entity, DamageSource source, float amount)
|
||||
{
|
||||
|
||||
public LivingDamageEvent(LivingEntity entity, DamageSource source, float amount) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.amount = amount;
|
||||
|
||||
@@ -9,9 +9,10 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingDeathEvent is fired when an Entity dies. <br>
|
||||
@@ -31,12 +32,12 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingDeathEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingDeathEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingDeathEvent> BUS = CancellableEventBus.create(LivingDeathEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
public LivingDeathEvent(LivingEntity entity, DamageSource source)
|
||||
{
|
||||
|
||||
public LivingDeathEvent(LivingEntity entity, DamageSource source) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* Fired when the ender dragon or wither attempts to destroy a block and when ever a zombie attempts to break a door. Basically a event version of {@link Block#canEntityDestroy(BlockState, BlockGetter, BlockPos, Entity)}<br>
|
||||
@@ -24,14 +25,13 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingDestroyBlockEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingDestroyBlockEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingDestroyBlockEvent> BUS = CancellableEventBus.create(LivingDestroyBlockEvent.class);
|
||||
|
||||
private final BlockPos pos;
|
||||
private final BlockState state;
|
||||
|
||||
public LivingDestroyBlockEvent(LivingEntity entity, BlockPos pos, BlockState state)
|
||||
{
|
||||
public LivingDestroyBlockEvent(LivingEntity entity, BlockPos pos, BlockState state) {
|
||||
super(entity);
|
||||
this.pos = pos;
|
||||
this.state = state;
|
||||
|
||||
@@ -12,7 +12,8 @@ import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingDropsEvent is fired when an Entity's death causes dropped items to appear.<br>
|
||||
@@ -33,8 +34,9 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public final class LivingDropsEvent extends LivingEvent {
|
||||
public final class LivingDropsEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingDropsEvent> BUS = CancellableEventBus.create(LivingDropsEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private final Collection<ItemEntity> drops;
|
||||
private final boolean recentlyHit;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
@@ -12,21 +14,19 @@ import net.minecraft.world.damagesource.DamageSources;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* LivingDrownEvent is fired whenever a living entity can't breathe and its air supply is less than or equal to zero.
|
||||
* <p>
|
||||
* This event is fired via {@link ForgeHooks#onLivingBreathe(LivingEntity, int, int)}.
|
||||
* <p>
|
||||
* This event is {@link Cancelable}. Effects of cancellation are noted in {@link #setCanceled(boolean)}.
|
||||
* This event is {@link Cancellable}. Cancelling the event also acts as if you called {@link #setDrowning(boolean)} with
|
||||
* a value of {@code false}.
|
||||
* <p>
|
||||
* This event does not {@linkplain HasResult have a result}.
|
||||
* This event is fired on {@link MinecraftForge#EVENT_BUS}
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingDrownEvent extends LivingEvent {
|
||||
public final class LivingDrownEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingDrownEvent> BUS = CancellableEventBus.create(LivingDrownEvent.class);
|
||||
|
||||
private boolean isDrowning;
|
||||
private float damageAmount;
|
||||
private int bubbleCount;
|
||||
@@ -111,14 +111,4 @@ public final class LivingDrownEvent extends LivingEvent {
|
||||
public void setBubbleCount(int bubbleCount) {
|
||||
this.bubbleCount = bubbleCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the drowning event.<br>
|
||||
* Cancellation is mostly equivalent to {@link #setDrowning(boolean)} with a value of false.<br>
|
||||
* However, this also incurs the usual side effects of cancellation.
|
||||
*/
|
||||
@Override
|
||||
public void setCanceled(boolean cancel) {
|
||||
super.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-30
@@ -7,34 +7,33 @@ 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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public sealed class LivingEntityUseItemEvent extends LivingEvent
|
||||
{
|
||||
public sealed abstract class LivingEntityUseItemEvent extends LivingEvent {
|
||||
public static final EventBus<LivingEntityUseItemEvent> BUS = EventBus.create(LivingEntityUseItemEvent.class);
|
||||
|
||||
private final ItemStack item;
|
||||
private int duration;
|
||||
|
||||
private LivingEntityUseItemEvent(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
private LivingEntityUseItemEvent(LivingEntity entity, @NotNull ItemStack item, int duration) {
|
||||
super(entity);
|
||||
this.item = item;
|
||||
this.setDuration(duration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getItem()
|
||||
{
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getDuration()
|
||||
{
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration)
|
||||
{
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@@ -49,11 +48,10 @@ public sealed class LivingEntityUseItemEvent extends LivingEvent
|
||||
* Cancel the event, or set the duration or {@literal <} 0 to prevent it from processing.
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Start extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Start(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
public static final class Start extends LivingEntityUseItemEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Start> BUS = CancellableEventBus.create(Start.class);
|
||||
|
||||
public Start(LivingEntity entity, @NotNull ItemStack item, int duration) {
|
||||
super(entity, item, duration);
|
||||
}
|
||||
}
|
||||
@@ -64,11 +62,10 @@ public sealed class LivingEntityUseItemEvent extends LivingEvent
|
||||
* Cancel the event, or set the duration to {@literal <=} 0 to cause the player to stop using the item.
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Tick extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Tick(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
public static final class Tick extends LivingEntityUseItemEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Tick> BUS = CancellableEventBus.create(Tick.class);
|
||||
|
||||
public Tick(LivingEntity entity, @NotNull ItemStack item, int duration) {
|
||||
super(entity, item, duration);
|
||||
}
|
||||
}
|
||||
@@ -85,11 +82,10 @@ public sealed class LivingEntityUseItemEvent extends LivingEvent
|
||||
* Canceling this event will prevent the Item from being notified that it has stopped being used,
|
||||
* The only vanilla item this would effect are bows, and it would cause them NOT to fire there arrow.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Stop extends LivingEntityUseItemEvent
|
||||
{
|
||||
public Stop(LivingEntity entity, @NotNull ItemStack item, int duration)
|
||||
{
|
||||
public static final class Stop extends LivingEntityUseItemEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Stop> BUS = CancellableEventBus.create(Stop.class);
|
||||
|
||||
public Stop(LivingEntity entity, @NotNull ItemStack item, int duration) {
|
||||
super(entity, item, duration);
|
||||
}
|
||||
}
|
||||
@@ -106,11 +102,12 @@ public sealed class LivingEntityUseItemEvent extends LivingEvent
|
||||
* The result item stack is the stack that is placed in the player's inventory in replacement of the stack that is currently being used.
|
||||
*
|
||||
*/
|
||||
public static final class Finish extends LivingEntityUseItemEvent
|
||||
{
|
||||
public static final class Finish extends LivingEntityUseItemEvent {
|
||||
public static final EventBus<Finish> BUS = EventBus.create(Finish.class);
|
||||
|
||||
private ItemStack result;
|
||||
public Finish(LivingEntity entity, @NotNull ItemStack item, int duration, @NotNull ItemStack result)
|
||||
{
|
||||
|
||||
public Finish(LivingEntity entity, @NotNull ItemStack item, int duration, @NotNull ItemStack result) {
|
||||
super(entity, item, duration);
|
||||
this.setResultStack(result);
|
||||
}
|
||||
|
||||
+3
-1
@@ -9,7 +9,7 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -29,6 +29,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class LivingEquipmentChangeEvent extends LivingEvent {
|
||||
public static final EventBus<LivingEquipmentChangeEvent> BUS = EventBus.create(LivingEquipmentChangeEvent.class);
|
||||
|
||||
private final EquipmentSlot slot;
|
||||
private final ItemStack from;
|
||||
private final ItemStack to;
|
||||
|
||||
@@ -9,10 +9,11 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -22,19 +23,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class LivingEvent extends EntityEvent
|
||||
{
|
||||
public class LivingEvent extends EntityEvent {
|
||||
public static final EventBus<LivingEvent> BUS = EventBus.create(LivingEvent.class);
|
||||
|
||||
private final LivingEntity livingEntity;
|
||||
|
||||
public LivingEvent(LivingEntity entity)
|
||||
{
|
||||
public LivingEvent(LivingEntity entity) {
|
||||
super(entity);
|
||||
livingEntity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity()
|
||||
{
|
||||
public LivingEntity getEntity() {
|
||||
return livingEntity;
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ public class LivingEvent extends EntityEvent
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public static final class LivingTickEvent extends LivingEvent
|
||||
{
|
||||
public LivingTickEvent(LivingEntity e){ super(e); }
|
||||
public static final class LivingTickEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingTickEvent> BUS = CancellableEventBus.create(LivingTickEvent.class);
|
||||
|
||||
public LivingTickEvent(LivingEntity e) { super(e); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,19 +70,20 @@ public class LivingEvent extends EntityEvent
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public static final class LivingJumpEvent extends LivingEvent
|
||||
{
|
||||
public LivingJumpEvent(LivingEntity e){ super(e); }
|
||||
public static final class LivingJumpEvent extends LivingEvent {
|
||||
public static final EventBus<LivingJumpEvent> BUS = EventBus.create(LivingJumpEvent.class);
|
||||
|
||||
public LivingJumpEvent(LivingEntity e) { super(e); }
|
||||
}
|
||||
|
||||
public static final class LivingVisibilityEvent extends LivingEvent
|
||||
{
|
||||
public static final class LivingVisibilityEvent extends LivingEvent {
|
||||
public static final EventBus<LivingVisibilityEvent> BUS = EventBus.create(LivingVisibilityEvent.class);
|
||||
|
||||
private double visibilityModifier;
|
||||
@Nullable
|
||||
private final Entity lookingEntity;
|
||||
|
||||
public LivingVisibilityEvent(LivingEntity livingEntity, @Nullable Entity lookingEntity, double originalMultiplier)
|
||||
{
|
||||
public LivingVisibilityEvent(LivingEntity livingEntity, @Nullable Entity lookingEntity, double originalMultiplier) {
|
||||
super(livingEntity);
|
||||
this.visibilityModifier = originalMultiplier;
|
||||
this.lookingEntity = lookingEntity;
|
||||
@@ -91,16 +92,14 @@ public class LivingEvent extends EntityEvent
|
||||
/**
|
||||
* @param mod Is multiplied with the current modifier
|
||||
*/
|
||||
public void modifyVisibility(double mod)
|
||||
{
|
||||
public void modifyVisibility(double mod) {
|
||||
visibilityModifier *= mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current modifier
|
||||
*/
|
||||
public double getVisibilityModifier()
|
||||
{
|
||||
public double getVisibilityModifier() {
|
||||
return visibilityModifier;
|
||||
}
|
||||
|
||||
@@ -108,8 +107,7 @@ public class LivingEvent extends EntityEvent
|
||||
* @return The entity trying to see this LivingEntity, if available
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getLookingEntity()
|
||||
{
|
||||
public Entity getLookingEntity() {
|
||||
return lookingEntity;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-14
@@ -7,7 +7,8 @@ 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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -15,29 +16,26 @@ import org.jetbrains.annotations.Nullable;
|
||||
* the amount of experience points dropped or completely prevent dropping of experience
|
||||
* by canceling the event.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class LivingExperienceDropEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingExperienceDropEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingExperienceDropEvent> BUS = CancellableEventBus.create(LivingExperienceDropEvent.class);
|
||||
|
||||
@Nullable private final Player attackingPlayer;
|
||||
private final int originalExperiencePoints;
|
||||
|
||||
private int droppedExperiencePoints;
|
||||
|
||||
public LivingExperienceDropEvent(LivingEntity entity, @Nullable Player attackingPlayer, int originalExperience)
|
||||
{
|
||||
public LivingExperienceDropEvent(LivingEntity entity, @Nullable Player attackingPlayer, int originalExperience) {
|
||||
super(entity);
|
||||
|
||||
this.attackingPlayer = attackingPlayer;
|
||||
this.originalExperiencePoints = this.droppedExperiencePoints = originalExperience;
|
||||
}
|
||||
|
||||
public int getDroppedExperience()
|
||||
{
|
||||
public int getDroppedExperience() {
|
||||
return droppedExperiencePoints;
|
||||
}
|
||||
|
||||
public void setDroppedExperience(int droppedExperience)
|
||||
{
|
||||
public void setDroppedExperience(int droppedExperience) {
|
||||
this.droppedExperiencePoints = droppedExperience;
|
||||
}
|
||||
|
||||
@@ -45,13 +43,11 @@ public final class LivingExperienceDropEvent extends LivingEvent
|
||||
* @return The player that last attacked the entity and thus caused the experience. This can be null, in case the player has since logged out.
|
||||
*/
|
||||
@Nullable
|
||||
public Player getAttackingPlayer()
|
||||
{
|
||||
public Player getAttackingPlayer() {
|
||||
return attackingPlayer;
|
||||
}
|
||||
|
||||
public int getOriginalExperience()
|
||||
{
|
||||
public int getOriginalExperience() {
|
||||
return originalExperiencePoints;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingFallEvent is fired when an Entity is set to be falling.<br>
|
||||
@@ -27,8 +27,9 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingFallEvent extends LivingEvent {
|
||||
public final class LivingFallEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingFallEvent> BUS = CancellableEventBus.create(LivingFallEvent.class);
|
||||
|
||||
private double distance;
|
||||
private float damageMultiplier;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* This event is fired when a living entity attempts to get a projectile with the
|
||||
@@ -20,13 +21,13 @@ import net.minecraft.world.item.ItemStack;
|
||||
* <p>
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public final class LivingGetProjectileEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingGetProjectileEvent extends LivingEvent {
|
||||
public static final EventBus<LivingGetProjectileEvent> BUS = EventBus.create(LivingGetProjectileEvent.class);
|
||||
|
||||
private final ItemStack projectileWeaponItemStack;
|
||||
private ItemStack projectileItemStack;
|
||||
|
||||
public LivingGetProjectileEvent(LivingEntity livingEntity, ItemStack projectileWeaponItemStack, ItemStack ammo)
|
||||
{
|
||||
public LivingGetProjectileEvent(LivingEntity livingEntity, ItemStack projectileWeaponItemStack, ItemStack ammo) {
|
||||
super(livingEntity);
|
||||
this.projectileWeaponItemStack = projectileWeaponItemStack;
|
||||
this.projectileItemStack = ammo;
|
||||
@@ -37,8 +38,7 @@ public final class LivingGetProjectileEvent extends LivingEvent
|
||||
* an itemstack of a {@link net.minecraft.world.item.ProjectileWeaponItem}, but it's possible for that to not be the
|
||||
* case if modder uses a different implementation of {@link LivingEntity#getProjectile(ItemStack)}.
|
||||
*/
|
||||
public ItemStack getProjectileWeaponItemStack()
|
||||
{
|
||||
public ItemStack getProjectileWeaponItemStack() {
|
||||
return this.projectileWeaponItemStack;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,7 @@ public final class LivingGetProjectileEvent extends LivingEvent
|
||||
* behaviour, but it's possible for thatnot to be the case if a modder uses a different implementation of
|
||||
* {@link LivingEntity#getProjectile(ItemStack)}.
|
||||
*/
|
||||
public ItemStack getProjectileItemStack()
|
||||
{
|
||||
public ItemStack getProjectileItemStack() {
|
||||
return this.projectileItemStack;
|
||||
}
|
||||
|
||||
@@ -63,8 +62,7 @@ public final class LivingGetProjectileEvent extends LivingEvent
|
||||
* {@link LivingEntity#level} is client-side, you will want to make a conditional to always set the item stack to
|
||||
* what you'd want it to be to avoid client-server desyncs.
|
||||
*/
|
||||
public void setProjectileItemStack(ItemStack projectileItemStack)
|
||||
{
|
||||
public void setProjectileItemStack(ItemStack projectileItemStack) {
|
||||
this.projectileItemStack = projectileItemStack;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,9 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingHealEvent is fired when an Entity is set to be healed. <br>
|
||||
@@ -25,23 +26,21 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class LivingHealEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingHealEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingHealEvent> BUS = CancellableEventBus.create(LivingHealEvent.class);
|
||||
|
||||
private float amount;
|
||||
public LivingHealEvent(LivingEntity entity, float amount)
|
||||
{
|
||||
|
||||
public LivingHealEvent(LivingEntity entity, float amount) {
|
||||
super(entity);
|
||||
this.setAmount(amount);
|
||||
}
|
||||
|
||||
public float getAmount()
|
||||
{
|
||||
public float getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(float amount)
|
||||
{
|
||||
public void setAmount(float amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingHurtEvent is fired when an Entity is set to be hurt. <br>
|
||||
@@ -30,13 +31,13 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* @see LivingDamageEvent
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public final class LivingHurtEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingHurtEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingHurtEvent> BUS = CancellableEventBus.create(LivingHurtEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private float amount;
|
||||
public LivingHurtEvent(LivingEntity entity, DamageSource source, float amount)
|
||||
{
|
||||
|
||||
public LivingHurtEvent(LivingEntity entity, DamageSource source, float amount) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.amount = amount;
|
||||
|
||||
@@ -12,7 +12,8 @@ import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* LivingKnockBackEvent is fired when a living entity is about to be knocked back. <br>
|
||||
@@ -28,23 +29,19 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* {@link #ratioX} contains the x ratio of the knock back. <br>
|
||||
* {@link #ratioZ} contains the z ratio of the knock back. <br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If this event is canceled, the entity is not knocked back.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
*<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public class LivingKnockBackEvent extends LivingEvent
|
||||
{
|
||||
public class LivingKnockBackEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingKnockBackEvent> BUS = CancellableEventBus.create(LivingKnockBackEvent.class);
|
||||
|
||||
protected float strength;
|
||||
protected double ratioX, ratioZ;
|
||||
protected final float originalStrength;
|
||||
protected final double originalRatioX, originalRatioZ;
|
||||
|
||||
public LivingKnockBackEvent(LivingEntity target, float strength, double ratioX, double ratioZ)
|
||||
{
|
||||
public LivingKnockBackEvent(LivingEntity target, float strength, double ratioX, double ratioZ) {
|
||||
super(target);
|
||||
this.strength = this.originalStrength = strength;
|
||||
this.ratioX = this.originalRatioX = ratioX;
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraft.world.entity.ai.Brain;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BrainBuilder;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* LivingMakeBrainEvent is fired whenever a new {@link net.minecraft.world.entity.ai.Brain} instance is created using {@link LivingEntity#makeBrain(Dynamic)}.<br>
|
||||
@@ -31,18 +31,18 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class LivingMakeBrainEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingMakeBrainEvent extends LivingEvent {
|
||||
public static final EventBus<LivingMakeBrainEvent> BUS = EventBus.create(LivingMakeBrainEvent.class);
|
||||
|
||||
private final BrainBuilder<?> brainBuilder;
|
||||
|
||||
public LivingMakeBrainEvent(LivingEntity entity, BrainBuilder<?> brainBuilder)
|
||||
{
|
||||
public LivingMakeBrainEvent(LivingEntity entity, BrainBuilder<?> brainBuilder) {
|
||||
super(entity);
|
||||
this.brainBuilder = brainBuilder;
|
||||
}
|
||||
|
||||
public <E extends LivingEntity> BrainBuilder<E> getTypedBrainBuilder(E ignoredEntity)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends LivingEntity> BrainBuilder<E> getTypedBrainBuilder(E ignoredEntity) {
|
||||
return (BrainBuilder<E>) this.brainBuilder;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,20 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public final class LivingPackSizeEvent extends LivingEvent implements HasResult {
|
||||
public static final EventBus<LivingPackSizeEvent> BUS = EventBus.create(LivingPackSizeEvent.class);
|
||||
|
||||
@HasResult
|
||||
public final class LivingPackSizeEvent extends LivingEvent
|
||||
{
|
||||
private int maxPackSize;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public LivingPackSizeEvent(Mob entity)
|
||||
{
|
||||
public LivingPackSizeEvent(Mob entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -26,13 +30,21 @@ public final class LivingPackSizeEvent extends LivingEvent
|
||||
* If you set the result to 'ALLOW', it means that you want to return
|
||||
* the value of maxPackSize as the maximum pack size for current entity.
|
||||
*/
|
||||
public int getMaxPackSize()
|
||||
{
|
||||
public int getMaxPackSize() {
|
||||
return maxPackSize;
|
||||
}
|
||||
|
||||
public void setMaxPackSize(int maxPackSize)
|
||||
{
|
||||
public void setMaxPackSize(int maxPackSize) {
|
||||
this.maxPackSize = maxPackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,13 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
{
|
||||
public sealed class LivingSwapItemsEvent extends LivingEvent {
|
||||
public static final EventBus<LivingSwapItemsEvent> EVENT_BUS = EventBus.create(LivingSwapItemsEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LivingSwapItemsEvent(LivingEntity entity)
|
||||
@@ -26,15 +28,14 @@ public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Hands extends LivingSwapItemsEvent
|
||||
{
|
||||
public static final class Hands extends LivingSwapItemsEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Hands> BUS = CancellableEventBus.create(Hands.class);
|
||||
|
||||
private ItemStack toMainHand;
|
||||
private ItemStack toOffHand;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Hands(LivingEntity entity)
|
||||
{
|
||||
public Hands(LivingEntity entity) {
|
||||
super(entity);
|
||||
this.toMainHand = entity.getOffhandItem(); //the main hand will be swapped with the offhand
|
||||
this.toOffHand = entity.getMainHandItem(); //the offhand will be swapped with the main hand
|
||||
@@ -44,8 +45,7 @@ public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
* Gets the item that will be swapped to the main hand of the entity.
|
||||
* @return The item that will be swapped to the main hand.
|
||||
*/
|
||||
public ItemStack getItemSwappedToMainHand()
|
||||
{
|
||||
public ItemStack getItemSwappedToMainHand() {
|
||||
return toMainHand;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
* Gets the item that will be swapped to the offhand of the entity.
|
||||
* @return The item that will be swapped to the offhand.
|
||||
*/
|
||||
public ItemStack getItemSwappedToOffHand()
|
||||
{
|
||||
public ItemStack getItemSwappedToOffHand() {
|
||||
return toOffHand;
|
||||
}
|
||||
|
||||
@@ -62,8 +61,7 @@ public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
* Sets the item that will be swapped to the main hand of the entity.
|
||||
* @param item The item to swap to the main hand.
|
||||
*/
|
||||
public void setItemSwappedToMainHand(ItemStack item)
|
||||
{
|
||||
public void setItemSwappedToMainHand(ItemStack item) {
|
||||
this.toMainHand = item;
|
||||
}
|
||||
|
||||
@@ -71,8 +69,7 @@ public sealed class LivingSwapItemsEvent extends LivingEvent
|
||||
* Sets the item that will be swapped to the offhand of the entity.
|
||||
* @param item The item to swap to the offhand.
|
||||
*/
|
||||
public void setItemSwappedToOffHand(ItemStack item)
|
||||
{
|
||||
public void setItemSwappedToOffHand(ItemStack item) {
|
||||
this.toOffHand = item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
@@ -22,15 +23,14 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public final class LivingUseTotemEvent extends LivingEvent
|
||||
{
|
||||
public final class LivingUseTotemEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LivingUseTotemEvent> BUS = CancellableEventBus.create(LivingUseTotemEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private final ItemStack totem;
|
||||
private final InteractionHand hand;
|
||||
|
||||
public LivingUseTotemEvent(LivingEntity entity, DamageSource source, ItemStack totem, InteractionHand hand)
|
||||
{
|
||||
public LivingUseTotemEvent(LivingEntity entity, DamageSource source, ItemStack totem, InteractionHand hand) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.totem = totem;
|
||||
@@ -40,24 +40,21 @@ public final class LivingUseTotemEvent extends LivingEvent
|
||||
/**
|
||||
* {@return the damage source that caused the entity to die}
|
||||
*/
|
||||
public DamageSource getSource()
|
||||
{
|
||||
public DamageSource getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the totem of undying being used from the entity's inventory}
|
||||
*/
|
||||
public ItemStack getTotem()
|
||||
{
|
||||
public ItemStack getTotem() {
|
||||
return totem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the hand holding the totem}
|
||||
*/
|
||||
public InteractionHand getHandHolding()
|
||||
{
|
||||
public InteractionHand getHandHolding() {
|
||||
return hand;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,11 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class LootingLevelEvent extends LivingEvent {
|
||||
public static final EventBus<LootingLevelEvent> BUS = EventBus.create(LootingLevelEvent.class);
|
||||
|
||||
@Nullable
|
||||
private final DamageSource damageSource;
|
||||
|
||||
@@ -11,7 +11,11 @@ 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 net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -21,6 +25,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public sealed class MobEffectEvent extends LivingEvent {
|
||||
public static final EventBus<MobEffectEvent> BUS = EventBus.create(MobEffectEvent.class);
|
||||
|
||||
@Nullable
|
||||
protected final MobEffectInstance effectInstance;
|
||||
|
||||
@@ -39,8 +45,9 @@ public sealed class MobEffectEvent extends LivingEvent {
|
||||
* This Event is {@link Cancelable}. If canceled, the effect will not be removed.
|
||||
* This Event does not have a result.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class Remove extends MobEffectEvent {
|
||||
public static final class Remove extends MobEffectEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Remove> BUS = CancellableEventBus.create(Remove.class);
|
||||
|
||||
private final MobEffect effect;
|
||||
|
||||
public Remove(LivingEntity living, MobEffect effect) {
|
||||
@@ -79,8 +86,11 @@ public sealed class MobEffectEvent extends LivingEvent {
|
||||
* {@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 final class Applicable extends MobEffectEvent {
|
||||
public static final class Applicable extends MobEffectEvent implements HasResult {
|
||||
public static final EventBus<Applicable> BUS = EventBus.create(Applicable.class);
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public Applicable(LivingEntity living, @NotNull MobEffectInstance effectInstance) {
|
||||
super(living, effectInstance);
|
||||
}
|
||||
@@ -90,6 +100,16 @@ public sealed class MobEffectEvent extends LivingEvent {
|
||||
public MobEffectInstance getEffectInstance() {
|
||||
return super.getEffectInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +119,8 @@ public sealed class MobEffectEvent extends LivingEvent {
|
||||
* This event does not have a result.
|
||||
*/
|
||||
public static final class Added extends MobEffectEvent {
|
||||
public static final EventBus<Added> BUS = EventBus.create(Added.class);
|
||||
|
||||
private final MobEffectInstance oldEffectInstance;
|
||||
private final Entity source;
|
||||
|
||||
@@ -140,6 +162,8 @@ public sealed class MobEffectEvent extends LivingEvent {
|
||||
* This event does not have a result.
|
||||
*/
|
||||
public static final class Expired extends MobEffectEvent {
|
||||
public static final EventBus<Expired> BUS = EventBus.create(Expired.class);
|
||||
|
||||
public Expired(LivingEntity living, MobEffectInstance effect) {
|
||||
super(living, effect);
|
||||
}
|
||||
|
||||
@@ -6,23 +6,27 @@
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.level.BaseSpawner;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraftforge.common.ForgeInternalHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.SpawnPlacementRegisterEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
@@ -37,6 +41,8 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* {@link AllowDespawn} is not related to the mob spawn event flow, as it fires when a despawn is attempted.
|
||||
*/
|
||||
public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
public static final EventBus<MobSpawnEvent> BUS = EventBus.create(MobSpawnEvent.class);
|
||||
|
||||
private final ServerLevelAccessor level;
|
||||
private final double x;
|
||||
private final double y;
|
||||
@@ -103,14 +109,16 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
* @apiNote If your modifications are for a single entity, and do not vary at runtime, use {@link SpawnPlacementRegisterEvent}.
|
||||
* @see SpawnPlacementRegisterEvent
|
||||
*/
|
||||
@HasResult
|
||||
public static final class SpawnPlacementCheck extends Event {
|
||||
public static final class SpawnPlacementCheck extends MutableEvent implements HasResult {
|
||||
public static final EventBus<SpawnPlacementCheck> BUS = EventBus.create(SpawnPlacementCheck.class);
|
||||
|
||||
private final EntityType<?> entityType;
|
||||
private final ServerLevelAccessor level;
|
||||
private final EntitySpawnReason spawnReason;
|
||||
private final BlockPos pos;
|
||||
private final RandomSource random;
|
||||
private final boolean defaultResult;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
/**
|
||||
* Internal.
|
||||
@@ -171,6 +179,16 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
public boolean getDefaultResult() {
|
||||
return this.defaultResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,11 +218,13 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
* @see {@link SpawnPlacementRegisterEvent} To modify spawn placements statically at startup.
|
||||
* @see {@link SpawnPlacementCheck} To modify the result of spawn placements at runtime.
|
||||
*/
|
||||
@HasResult
|
||||
public static final class PositionCheck extends MobSpawnEvent {
|
||||
public static final class PositionCheck extends MobSpawnEvent implements HasResult {
|
||||
public static final EventBus<PositionCheck> BUS = EventBus.create(PositionCheck.class);
|
||||
|
||||
@Nullable
|
||||
private final BaseSpawner spawner;
|
||||
private final EntitySpawnReason spawnReason;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public PositionCheck(Mob mob, ServerLevelAccessor level, EntitySpawnReason spawnReason, @Nullable BaseSpawner spawner) {
|
||||
super(mob, level, mob.getX(), mob.getY(), mob.getZ());
|
||||
@@ -230,6 +250,16 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
public EntitySpawnReason getSpawnReason() {
|
||||
return this.spawnReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,8 +274,9 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
* @see ForgeEventFactory#onFinalizeSpawn
|
||||
* @apiNote Callers do not need to check if the entity's spawn was cancelled, as the spawn will be blocked by Forge.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class FinalizeSpawn extends MobSpawnEvent {
|
||||
public static final class FinalizeSpawn extends MobSpawnEvent implements Cancellable {
|
||||
public static final CancellableEventBus<FinalizeSpawn> BUS = CancellableEventBus.create(FinalizeSpawn.class);
|
||||
|
||||
private final EntitySpawnReason spawnReason;
|
||||
@Nullable
|
||||
private final BaseSpawner spawner;
|
||||
@@ -254,13 +285,13 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
@Nullable
|
||||
private SpawnGroupData spawnData;
|
||||
@Nullable
|
||||
private CompoundTag spawnTag;
|
||||
private ValueInput spawnTag;
|
||||
|
||||
/**
|
||||
* @apiNote Do not construct directly. Access via {@link ForgeEventFactory#onFinalizeSpawn} / {@link ForgeEventFactory#onFinalizeSpawnSpawner}.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public FinalizeSpawn(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, EntitySpawnReason spawnReason, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag spawnTag, @Nullable BaseSpawner spawner) {
|
||||
public FinalizeSpawn(Mob entity, ServerLevelAccessor level, double x, double y, double z, DifficultyInstance difficulty, EntitySpawnReason spawnReason, @Nullable SpawnGroupData spawnData, @Nullable ValueInput spawnTag, @Nullable BaseSpawner spawner) {
|
||||
super(entity, level, x, y, z);
|
||||
this.difficulty = difficulty;
|
||||
this.spawnReason = spawnReason;
|
||||
@@ -320,7 +351,7 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
* @return The spawn data this entity was or will be loaded from, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public CompoundTag getSpawnTag() {
|
||||
public ValueInput getSpawnTag() {
|
||||
return this.spawnTag;
|
||||
}
|
||||
|
||||
@@ -329,7 +360,7 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
* The only vanilla mob known to use this tag for anything in finalize is tropical fish for setting the variant when spawned via bucket.
|
||||
* @param tag The new spawn tag
|
||||
*/
|
||||
public void setSpawnTag(@Nullable CompoundTag tag) {
|
||||
public void setSpawnTag(@Nullable ValueInput tag) {
|
||||
this.spawnTag = tag;
|
||||
}
|
||||
|
||||
@@ -382,10 +413,23 @@ public abstract sealed class MobSpawnEvent extends EntityEvent {
|
||||
*/
|
||||
// TODO: 1.20 Move to standalone class, as it is unrelated to the complex mob spawning flow.
|
||||
// Such a refactor will allow the BaseSpawner and MobSpawnType params to be hoisted to MobSpawnEvent.
|
||||
@HasResult
|
||||
public static final class AllowDespawn extends MobSpawnEvent {
|
||||
public static final class AllowDespawn extends MobSpawnEvent implements HasResult {
|
||||
public static final EventBus<AllowDespawn> BUS = EventBus.create(AllowDespawn.class);
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public AllowDespawn(Mob mob, ServerLevelAccessor level) {
|
||||
super(mob, level, mob.getX(), mob.getY(), mob.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.extensions.IForgeItem;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event is fired on the forge bus before an Monster detects that a player is looking at them.
|
||||
@@ -19,8 +20,9 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* <p>
|
||||
* This event does not have a {@link Result}.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class MonsterDisguiseEvent extends LivingEvent {
|
||||
public final class MonsterDisguiseEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<MonsterDisguiseEvent> BUS = CancellableEventBus.create(MonsterDisguiseEvent.class);
|
||||
|
||||
private final Player player;
|
||||
|
||||
public MonsterDisguiseEvent(Monster monster, Player player) {
|
||||
@@ -37,6 +39,6 @@ public final class MonsterDisguiseEvent extends LivingEvent {
|
||||
|
||||
@Override
|
||||
public Monster getEntity() {
|
||||
return (Monster)super.getEntity();
|
||||
return (Monster) super.getEntity();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* The ShieldBlockEvent is fired when an entity successfully blocks with a shield.<br>
|
||||
@@ -18,8 +19,9 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* Note: The shield item stack "should" be available from {@link LivingEntity#getUseItem()}
|
||||
* at least for players.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class ShieldBlockEvent extends LivingEvent {
|
||||
public final class ShieldBlockEvent extends LivingEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ShieldBlockEvent> BUS = CancellableEventBus.create(ShieldBlockEvent.class);
|
||||
|
||||
private final DamageSource source;
|
||||
private final float originalBlocked;
|
||||
private float dmgBlocked;
|
||||
|
||||
@@ -9,9 +9,11 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.monster.Zombie;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* ZombieEvent is fired whenever a zombie is spawned for aid.
|
||||
@@ -21,17 +23,17 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public sealed class ZombieEvent extends EntityEvent {
|
||||
public static final EventBus<ZombieEvent> BUS = EventBus.create(ZombieEvent.class);
|
||||
|
||||
private final Zombie zombie;
|
||||
|
||||
public ZombieEvent(Zombie zombie)
|
||||
{
|
||||
public ZombieEvent(Zombie zombie) {
|
||||
super(zombie);
|
||||
this.zombie = zombie;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Zombie getEntity()
|
||||
{
|
||||
public Zombie getEntity() {
|
||||
return this.zombie;
|
||||
}
|
||||
|
||||
@@ -58,8 +60,9 @@ public sealed class ZombieEvent extends EntityEvent {
|
||||
*
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@HasResult
|
||||
public static final class SummonAidEvent extends ZombieEvent {
|
||||
public static final class SummonAidEvent extends ZombieEvent implements HasResult {
|
||||
public static final EventBus<SummonAidEvent> BUS = EventBus.create(SummonAidEvent.class);
|
||||
|
||||
private Zombie customSummonedAid;
|
||||
|
||||
private final Level level;
|
||||
@@ -68,9 +71,9 @@ public sealed class ZombieEvent extends EntityEvent {
|
||||
private final int z;
|
||||
private final LivingEntity attacker;
|
||||
private final double summonChance;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public SummonAidEvent(Zombie zombie, Level level, 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(zombie);
|
||||
this.level = level;
|
||||
this.x = x;
|
||||
@@ -91,5 +94,15 @@ public sealed class ZombieEvent extends EntityEvent {
|
||||
public int getZ() { return z; }
|
||||
public LivingEntity getAttacker() { return attacker; }
|
||||
public double getSummonChance() { return summonChance; }
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* Base class used for advancement-related events. Should not be used directly.
|
||||
@@ -17,6 +18,8 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
* @see AdvancementProgressEvent
|
||||
*/
|
||||
public sealed class AdvancementEvent extends PlayerEvent {
|
||||
public static final EventBus<AdvancementEvent> BUS = EventBus.create(AdvancementEvent.class);
|
||||
|
||||
private final AdvancementHolder advancement;
|
||||
|
||||
public AdvancementEvent(Player player, AdvancementHolder advancement) {
|
||||
@@ -42,6 +45,8 @@ public sealed class AdvancementEvent extends PlayerEvent {
|
||||
* @see AdvancementProgress#isDone()
|
||||
*/
|
||||
public static final class AdvancementEarnEvent extends AdvancementEvent {
|
||||
public static final EventBus<AdvancementEarnEvent> BUS = EventBus.create(AdvancementEarnEvent.class);
|
||||
|
||||
public AdvancementEarnEvent(Player player, AdvancementHolder earned) {
|
||||
super(player, earned);
|
||||
}
|
||||
@@ -60,6 +65,8 @@ public sealed class AdvancementEvent extends PlayerEvent {
|
||||
* @see net.minecraft.server.PlayerAdvancements#revoke(Advancement, String)
|
||||
*/
|
||||
public static final class AdvancementProgressEvent extends AdvancementEvent {
|
||||
public static final EventBus<AdvancementProgressEvent> BUS = EventBus.create(AdvancementProgressEvent.class);
|
||||
|
||||
private final AdvancementProgress advancementProgress;
|
||||
private final String criterionName;
|
||||
private final AdvancementEvent.AdvancementProgressEvent.ProgressType progressType;
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -16,8 +17,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* ItemStacks are the inputs/output from the anvil. They cannot be edited.
|
||||
*/
|
||||
public final class AnvilRepairEvent extends PlayerEvent
|
||||
{
|
||||
public final class AnvilRepairEvent extends PlayerEvent {
|
||||
public static final EventBus<AnvilRepairEvent> BUS = EventBus.create(AnvilRepairEvent.class);
|
||||
|
||||
@NotNull
|
||||
private final ItemStack left; // The left side of the input
|
||||
@NotNull
|
||||
@@ -26,8 +28,7 @@ public final class AnvilRepairEvent extends PlayerEvent
|
||||
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, @NotNull ItemStack left, @NotNull ItemStack right, @NotNull ItemStack output)
|
||||
{
|
||||
public AnvilRepairEvent(Player player, @NotNull ItemStack left, @NotNull ItemStack right, @NotNull ItemStack output) {
|
||||
super(player);
|
||||
this.output = output;
|
||||
this.left = left;
|
||||
|
||||
@@ -8,10 +8,11 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.BowItem;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -30,16 +31,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class ArrowLooseEvent extends PlayerEvent
|
||||
{
|
||||
public final class ArrowLooseEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ArrowLooseEvent> BUS = CancellableEventBus.create(ArrowLooseEvent.class);
|
||||
|
||||
private final ItemStack bow;
|
||||
private final Level level;
|
||||
private final boolean hasAmmo;
|
||||
private int charge;
|
||||
|
||||
public ArrowLooseEvent(Player player, @NotNull ItemStack bow, Level level, int charge, boolean hasAmmo)
|
||||
{
|
||||
public ArrowLooseEvent(Player player, @NotNull ItemStack bow, Level level, int charge, boolean hasAmmo) {
|
||||
super(player);
|
||||
this.bow = bow;
|
||||
this.level = level;
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class ArrowNockEvent extends PlayerEvent {
|
||||
public static final EventBus<ArrowNockEvent> BUS = EventBus.create(ArrowNockEvent.class);
|
||||
|
||||
private final ItemStack bow;
|
||||
private final InteractionHand hand;
|
||||
private final Level level;
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* AttackEntityEvent is fired when a player attacks an Entity.<br>
|
||||
@@ -24,18 +25,17 @@ import net.minecraft.world.entity.player.Player;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class AttackEntityEvent extends PlayerEvent
|
||||
{
|
||||
public final class AttackEntityEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<AttackEntityEvent> BUS = CancellableEventBus.create(AttackEntityEvent.class);
|
||||
|
||||
private final Entity target;
|
||||
public AttackEntityEvent(Player player, Entity target)
|
||||
{
|
||||
|
||||
public AttackEntityEvent(Player player, Entity target) {
|
||||
super(player);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,15 @@
|
||||
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,14 +26,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
*
|
||||
* setResult(ALLOW) is the same as the old setHandled()
|
||||
*/
|
||||
@Cancelable
|
||||
@HasResult
|
||||
// TODO: Redesign BonemealEvent the whole thing, it doens't make sense.
|
||||
public final class BonemealEvent extends PlayerEvent {
|
||||
public final class BonemealEvent extends PlayerEvent implements Cancellable, HasResult {
|
||||
public static final CancellableEventBus<BonemealEvent> BUS = CancellableEventBus.create(BonemealEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
private final BlockState block;
|
||||
private final ItemStack stack;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public BonemealEvent(@Nullable Player player, Level level, BlockPos pos, BlockState block, ItemStack stack) {
|
||||
super(player);
|
||||
@@ -57,4 +60,14 @@ public final class BonemealEvent extends PlayerEvent {
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
@@ -24,16 +24,14 @@ import net.minecraft.world.entity.player.Player;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@HasResult
|
||||
public final class CriticalHitEvent extends PlayerEvent
|
||||
{
|
||||
public final class CriticalHitEvent extends PlayerEvent implements HasResult {
|
||||
private float damageModifier;
|
||||
private final float oldDamageModifier;
|
||||
private final Entity target;
|
||||
private final boolean vanillaCritical;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public CriticalHitEvent(Player player, Entity target, float damageModifier, boolean vanillaCritical)
|
||||
{
|
||||
public CriticalHitEvent(Player player, Entity target, float damageModifier, boolean vanillaCritical) {
|
||||
super(player);
|
||||
this.target = target;
|
||||
this.damageModifier = damageModifier;
|
||||
@@ -44,8 +42,7 @@ public final class CriticalHitEvent extends PlayerEvent
|
||||
/**
|
||||
* The Entity that was damaged by the player.
|
||||
*/
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -53,8 +50,7 @@ public final class CriticalHitEvent extends PlayerEvent
|
||||
* This set the damage multiplier for the hit.
|
||||
* If you set it to 0, then the particles are still generated but damage is not done.
|
||||
*/
|
||||
public void setDamageModifier(float mod)
|
||||
{
|
||||
public void setDamageModifier(float mod) {
|
||||
this.damageModifier = mod;
|
||||
}
|
||||
|
||||
@@ -62,8 +58,7 @@ public final class CriticalHitEvent extends PlayerEvent
|
||||
* The damage modifier for the hit.<br>
|
||||
* This is by default 1.5F for ciritcal hits and 1F for normal hits .
|
||||
*/
|
||||
public float getDamageModifier()
|
||||
{
|
||||
public float getDamageModifier() {
|
||||
return this.damageModifier;
|
||||
}
|
||||
|
||||
@@ -71,16 +66,24 @@ public final class CriticalHitEvent extends PlayerEvent
|
||||
* The orignal damage modifier for the hit wthout any changes.<br>
|
||||
* This is 1.5F for ciritcal hits and 1F for normal hits .
|
||||
*/
|
||||
public float getOldDamageModifier()
|
||||
{
|
||||
public float getOldDamageModifier() {
|
||||
return this.oldDamageModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this hit was critical by vanilla
|
||||
*/
|
||||
public boolean isVanillaCritical()
|
||||
{
|
||||
public boolean isVanillaCritical() {
|
||||
return vanillaCritical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event is called when a player collides with a EntityItem on the ground.
|
||||
@@ -20,20 +22,28 @@ import net.minecraft.world.entity.player.Player;
|
||||
*
|
||||
* setResult(ALLOW) is the same as the old setHandled()
|
||||
*/
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
public final class EntityItemPickupEvent extends PlayerEvent
|
||||
{
|
||||
private final ItemEntity item;
|
||||
public final class EntityItemPickupEvent extends PlayerEvent implements Cancellable, HasResult {
|
||||
public static final CancellableEventBus<EntityItemPickupEvent> BUS = CancellableEventBus.create(EntityItemPickupEvent.class);
|
||||
|
||||
public EntityItemPickupEvent(Player player, ItemEntity item)
|
||||
{
|
||||
private final ItemEntity item;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public EntityItemPickupEvent(Player player, ItemEntity item) {
|
||||
super(player);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public ItemEntity getItem()
|
||||
{
|
||||
public ItemEntity getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -23,10 +25,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
* ItemStack to your inventory and reducing the stack size to process.
|
||||
* setResult(ALLOW) is the same as the old setHandled();
|
||||
*/
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
public final class FillBucketEvent extends PlayerEvent
|
||||
{
|
||||
public final class FillBucketEvent extends PlayerEvent implements Cancellable, HasResult {
|
||||
public static final CancellableEventBus<FillBucketEvent> BUS = CancellableEventBus.create(FillBucketEvent.class);
|
||||
|
||||
private final ItemStack current;
|
||||
private final Level level;
|
||||
@@ -34,9 +34,9 @@ public final class FillBucketEvent extends PlayerEvent
|
||||
private final HitResult target;
|
||||
|
||||
private ItemStack result;
|
||||
private Result eventResult = Result.DEFAULT;
|
||||
|
||||
public FillBucketEvent(Player player, @NotNull ItemStack current, Level level, @Nullable HitResult target)
|
||||
{
|
||||
public FillBucketEvent(Player player, @NotNull ItemStack current, Level level, @Nullable HitResult target) {
|
||||
super(player);
|
||||
this.current = current;
|
||||
this.level = level;
|
||||
@@ -51,4 +51,14 @@ public final class FillBucketEvent extends PlayerEvent
|
||||
@NotNull
|
||||
public ItemStack getFilledBucket() { return this.result; }
|
||||
public void setFilledBucket(@NotNull ItemStack bucket) { this.result = bucket; }
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.eventResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.eventResult = result;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import java.util.List;
|
||||
@@ -21,8 +22,9 @@ import java.util.List;
|
||||
* Canceling the event will cause the player to receive no items at all.
|
||||
* The hook will still take the damage specified
|
||||
*/
|
||||
@Cancelable
|
||||
public final class ItemFishedEvent extends PlayerEvent {
|
||||
public final class ItemFishedEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ItemFishedEvent> BUS = CancellableEventBus.create(ItemFishedEvent.class);
|
||||
|
||||
private final NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
private final FishingHook hook;
|
||||
private int rodDamage;
|
||||
|
||||
@@ -12,11 +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 net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class ItemTooltipEvent extends PlayerEvent
|
||||
{
|
||||
public final class ItemTooltipEvent extends PlayerEvent {
|
||||
public static final EventBus<ItemTooltipEvent> BUS = EventBus.create(ItemTooltipEvent.class);
|
||||
|
||||
private final TooltipFlag flags;
|
||||
@NotNull
|
||||
private final ItemStack itemStack;
|
||||
|
||||
@@ -6,21 +6,21 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event will fire when the player is opped or deopped.
|
||||
* <p>
|
||||
* This event is cancelable which will stop the op or deop from happening.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class PermissionsChangedEvent extends PlayerEvent
|
||||
{
|
||||
public final class PermissionsChangedEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<PermissionsChangedEvent> BUS = CancellableEventBus.create(PermissionsChangedEvent.class);
|
||||
|
||||
private final int newLevel;
|
||||
private final int oldLevel;
|
||||
|
||||
public PermissionsChangedEvent(ServerPlayer player, int newLevel, int oldLevel)
|
||||
{
|
||||
public PermissionsChangedEvent(ServerPlayer player, int newLevel, int oldLevel) {
|
||||
super(player);
|
||||
this.oldLevel = oldLevel;
|
||||
this.newLevel = newLevel;
|
||||
@@ -29,15 +29,13 @@ public final class PermissionsChangedEvent extends PlayerEvent
|
||||
/**
|
||||
* @return The new permission level.
|
||||
*/
|
||||
public int getNewLevel()
|
||||
{
|
||||
public int getNewLevel() {
|
||||
return newLevel;
|
||||
}
|
||||
/**
|
||||
* @return The old permission level.
|
||||
*/
|
||||
public int getOldLevel()
|
||||
{
|
||||
public int getOldLevel() {
|
||||
return oldLevel;
|
||||
}
|
||||
}
|
||||
@@ -7,33 +7,35 @@ package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
public sealed class PlayerContainerEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerContainerEvent> BUS = EventBus.create(PlayerContainerEvent.class);
|
||||
|
||||
public sealed class PlayerContainerEvent extends PlayerEvent
|
||||
{
|
||||
private final AbstractContainerMenu container;
|
||||
public PlayerContainerEvent(Player player, AbstractContainerMenu container)
|
||||
{
|
||||
|
||||
public PlayerContainerEvent(Player player, AbstractContainerMenu container) {
|
||||
super(player);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public static final class Open extends PlayerContainerEvent
|
||||
{
|
||||
public Open(Player player, AbstractContainerMenu container)
|
||||
{
|
||||
super(player, container);
|
||||
}
|
||||
}
|
||||
public static final class Close extends PlayerContainerEvent
|
||||
{
|
||||
public Close(Player player, AbstractContainerMenu container)
|
||||
{
|
||||
public static final class Open extends PlayerContainerEvent {
|
||||
public static final EventBus<Open> BUS = EventBus.create(Open.class);
|
||||
|
||||
public Open(Player player, AbstractContainerMenu container) {
|
||||
super(player, container);
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractContainerMenu getContainer()
|
||||
{
|
||||
public static final class Close extends PlayerContainerEvent {
|
||||
public static final EventBus<Close> BUS = EventBus.create(Close.class);
|
||||
|
||||
public Close(Player player, AbstractContainerMenu container) {
|
||||
super(player, container);
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractContainerMenu getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -49,6 +49,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class PlayerDestroyItemEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerDestroyItemEvent> BUS = EventBus.create(PlayerDestroyItemEvent.class);
|
||||
|
||||
@NotNull
|
||||
private final ItemStack original;
|
||||
@Nullable
|
||||
@@ -69,5 +71,4 @@ public final class PlayerDestroyItemEvent extends PlayerEvent {
|
||||
public EquipmentSlot getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,13 +17,15 @@ import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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 net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,22 +33,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
* 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>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public class PlayerEvent extends LivingEvent
|
||||
{
|
||||
public class PlayerEvent extends LivingEvent {
|
||||
public static final EventBus<PlayerEvent> BUS = EventBus.create(PlayerEvent.class);
|
||||
|
||||
private final Player player;
|
||||
|
||||
public PlayerEvent(Player player)
|
||||
{
|
||||
public PlayerEvent(Player player) {
|
||||
super(player);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getEntity()
|
||||
{
|
||||
public Player getEntity() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -59,20 +58,14 @@ public class PlayerEvent extends LivingEvent
|
||||
* <br>
|
||||
* {@link #state} contains the {@link BlockState} that is being checked for harvesting. <br>
|
||||
* {@link #success} contains the boolean value for whether the Block will be successfully harvested. <br>
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.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 static final class HarvestCheck extends PlayerEvent
|
||||
{
|
||||
public static final class HarvestCheck extends PlayerEvent {
|
||||
public static final EventBus<HarvestCheck> BUS = EventBus.create(HarvestCheck.class);
|
||||
|
||||
private final BlockState state;
|
||||
private boolean success;
|
||||
|
||||
public HarvestCheck(Player player, BlockState state, boolean success)
|
||||
{
|
||||
public HarvestCheck(Player player, BlockState state, boolean success) {
|
||||
super(player);
|
||||
this.state = state;
|
||||
this.success = success;
|
||||
@@ -80,7 +73,7 @@ public class PlayerEvent extends LivingEvent
|
||||
|
||||
public BlockState getTargetBlock() { return this.state; }
|
||||
public boolean canHarvest() { return this.success; }
|
||||
public void setCanHarvest(boolean success){ this.success = success; }
|
||||
public void setCanHarvest(boolean success) { this.success = success; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,24 +88,18 @@ public class PlayerEvent extends LivingEvent
|
||||
* {@link #newSpeed} contains the newSpeed at which the player will break the block. <br>
|
||||
* {@link #pos} contains the coordinates at which this event is occurring. Optional value.<br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If it is canceled, the player is unable to break the block.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Cancelable
|
||||
public static final class BreakSpeed extends PlayerEvent
|
||||
{
|
||||
public static final class BreakSpeed extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<BreakSpeed> BUS = CancellableEventBus.create(BreakSpeed.class);
|
||||
|
||||
private static final BlockPos LEGACY_UNKNOWN = new BlockPos(0, -1, 0);
|
||||
private final BlockState state;
|
||||
private final float originalSpeed;
|
||||
private float newSpeed = 0.0f;
|
||||
private final Optional<BlockPos> pos; // Y position of -1 notes unknown location
|
||||
|
||||
public BreakSpeed(Player player, BlockState state, float original, @Nullable BlockPos pos)
|
||||
{
|
||||
public BreakSpeed(Player player, BlockState state, float original, @Nullable BlockPos pos) {
|
||||
super(player);
|
||||
this.state = state;
|
||||
this.originalSpeed = original;
|
||||
@@ -136,37 +123,28 @@ public class PlayerEvent extends LivingEvent
|
||||
* <br>
|
||||
* {@link #username} contains the username of the player.
|
||||
* {@link #displayname} contains the display name of the player.
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public static final class NameFormat extends PlayerEvent
|
||||
{
|
||||
public static final class NameFormat extends PlayerEvent {
|
||||
public static final EventBus<NameFormat> BUS = EventBus.create(NameFormat.class);
|
||||
|
||||
private final Component username;
|
||||
private Component displayname;
|
||||
|
||||
public NameFormat(Player player, Component username)
|
||||
{
|
||||
public NameFormat(Player player, Component username) {
|
||||
super(player);
|
||||
this.username = username;
|
||||
this.setDisplayname(username);
|
||||
}
|
||||
|
||||
public Component getUsername()
|
||||
{
|
||||
public Component getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public Component getDisplayname()
|
||||
{
|
||||
public Component getDisplayname() {
|
||||
return displayname;
|
||||
}
|
||||
|
||||
public void setDisplayname(Component displayname)
|
||||
{
|
||||
public void setDisplayname(Component displayname) {
|
||||
this.displayname = displayname;
|
||||
}
|
||||
}
|
||||
@@ -179,31 +157,23 @@ public class PlayerEvent extends LivingEvent
|
||||
* This event is fired via the {@link ForgeEventFactory#getPlayerTabListDisplayName(Player)}.<br>
|
||||
* <br>
|
||||
* {@link #getDisplayName()} contains the display name of the player or null if the client should determine the display name itself.
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public static final class TabListNameFormat extends PlayerEvent
|
||||
{
|
||||
public static final class TabListNameFormat extends PlayerEvent {
|
||||
public static final EventBus<TabListNameFormat> BUS = EventBus.create(TabListNameFormat.class);
|
||||
|
||||
@Nullable
|
||||
private Component displayName;
|
||||
|
||||
public TabListNameFormat(Player player)
|
||||
{
|
||||
public TabListNameFormat(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Component getDisplayName()
|
||||
{
|
||||
public Component getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(@Nullable Component displayName)
|
||||
{
|
||||
public void setDisplayName(@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
@@ -212,13 +182,13 @@ public class PlayerEvent extends LivingEvent
|
||||
* Fired when the EntityPlayer is cloned, typically caused by the impl sending a RESPAWN_PLAYER event.
|
||||
* Either caused by death, or by traveling from the End to the overworld.
|
||||
*/
|
||||
public static final class Clone extends PlayerEvent
|
||||
{
|
||||
public static final class Clone extends PlayerEvent {
|
||||
public static final EventBus<Clone> BUS = EventBus.create(Clone.class);
|
||||
|
||||
private final Player original;
|
||||
private final boolean wasDeath;
|
||||
|
||||
public Clone(Player _new, Player oldPlayer, boolean wasDeath)
|
||||
{
|
||||
public Clone(Player _new, Player oldPlayer, boolean wasDeath) {
|
||||
super(_new);
|
||||
this.original = oldPlayer;
|
||||
this.wasDeath = wasDeath;
|
||||
@@ -227,8 +197,7 @@ public class PlayerEvent extends LivingEvent
|
||||
/**
|
||||
* The old EntityPlayer that this new entity is a clone of.
|
||||
*/
|
||||
public Player getOriginal()
|
||||
{
|
||||
public Player getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
@@ -236,8 +205,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* True if this event was fired because the player died.
|
||||
* False if it was fired because the entity switched dimensions.
|
||||
*/
|
||||
public boolean isWasDeath()
|
||||
{
|
||||
public boolean isWasDeath() {
|
||||
return wasDeath;
|
||||
}
|
||||
}
|
||||
@@ -247,11 +215,11 @@ public class PlayerEvent extends LivingEvent
|
||||
*
|
||||
*/
|
||||
public static final class StartTracking extends PlayerEvent {
|
||||
public static final EventBus<StartTracking> BUS = EventBus.create(StartTracking.class);
|
||||
|
||||
private final Entity target;
|
||||
|
||||
public StartTracking(Player player, Entity target)
|
||||
{
|
||||
public StartTracking(Player player, Entity target) {
|
||||
super(player);
|
||||
this.target = target;
|
||||
}
|
||||
@@ -259,8 +227,7 @@ public class PlayerEvent extends LivingEvent
|
||||
/**
|
||||
* The Entity now being tracked.
|
||||
*/
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -270,11 +237,11 @@ public class PlayerEvent extends LivingEvent
|
||||
*
|
||||
*/
|
||||
public static final class StopTracking extends PlayerEvent {
|
||||
public static final EventBus<StopTracking> BUS = EventBus.create(StopTracking.class);
|
||||
|
||||
private final Entity target;
|
||||
|
||||
public StopTracking(Player player, Entity target)
|
||||
{
|
||||
public StopTracking(Player player, Entity target) {
|
||||
super(player);
|
||||
this.target = target;
|
||||
}
|
||||
@@ -282,8 +249,7 @@ public class PlayerEvent extends LivingEvent
|
||||
/**
|
||||
* The Entity no longer being tracked.
|
||||
*/
|
||||
public Entity getTarget()
|
||||
{
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -295,11 +261,12 @@ public class PlayerEvent extends LivingEvent
|
||||
* containing additional mod related player data.
|
||||
*/
|
||||
public static final class LoadFromFile extends PlayerEvent {
|
||||
public static final EventBus<LoadFromFile> BUS = EventBus.create(LoadFromFile.class);
|
||||
|
||||
private final File playerDirectory;
|
||||
private final String playerUUID;
|
||||
|
||||
public LoadFromFile(Player player, File originDirectory, String playerUUID)
|
||||
{
|
||||
public LoadFromFile(Player player, File originDirectory, String playerUUID) {
|
||||
super(player);
|
||||
this.playerDirectory = originDirectory;
|
||||
this.playerUUID = playerUUID;
|
||||
@@ -309,8 +276,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* Construct and return a recommended file for the supplied suffix
|
||||
* @param suffix The suffix to use.
|
||||
*/
|
||||
public File getPlayerFile(String suffix)
|
||||
{
|
||||
public File getPlayerFile(String suffix) {
|
||||
if ("dat".equals(suffix)) throw new IllegalArgumentException("The suffix 'dat' is reserved");
|
||||
return new File(this.getPlayerDirectory(), this.getPlayerUUID() +"."+suffix);
|
||||
}
|
||||
@@ -319,8 +285,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* The directory where player data is being stored. Use this
|
||||
* to locate your mod additional file.
|
||||
*/
|
||||
public File getPlayerDirectory()
|
||||
{
|
||||
public File getPlayerDirectory() {
|
||||
return playerDirectory;
|
||||
}
|
||||
|
||||
@@ -328,8 +293,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* The UUID is the standard for player related file storage.
|
||||
* It is broken out here for convenience for quick file generation.
|
||||
*/
|
||||
public String getPlayerUUID()
|
||||
{
|
||||
public String getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
}
|
||||
@@ -347,11 +311,12 @@ public class PlayerEvent extends LivingEvent
|
||||
* corrupt the world state.
|
||||
*/
|
||||
public static final class SaveToFile extends PlayerEvent {
|
||||
public static final EventBus<SaveToFile> BUS = EventBus.create(SaveToFile.class);
|
||||
|
||||
private final File playerDirectory;
|
||||
private final String playerUUID;
|
||||
|
||||
public SaveToFile(Player player, File originDirectory, String playerUUID)
|
||||
{
|
||||
public SaveToFile(Player player, File originDirectory, String playerUUID) {
|
||||
super(player);
|
||||
this.playerDirectory = originDirectory;
|
||||
this.playerUUID = playerUUID;
|
||||
@@ -361,8 +326,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* Construct and return a recommended file for the supplied suffix
|
||||
* @param suffix The suffix to use.
|
||||
*/
|
||||
public File getPlayerFile(String suffix)
|
||||
{
|
||||
public File getPlayerFile(String suffix) {
|
||||
if ("dat".equals(suffix)) throw new IllegalArgumentException("The suffix 'dat' is reserved");
|
||||
return new File(this.getPlayerDirectory(), this.getPlayerUUID() +"."+suffix);
|
||||
}
|
||||
@@ -371,8 +335,7 @@ public class PlayerEvent extends LivingEvent
|
||||
* The directory where player data is being stored. Use this
|
||||
* to locate your mod additional file.
|
||||
*/
|
||||
public File getPlayerDirectory()
|
||||
{
|
||||
public File getPlayerDirectory() {
|
||||
return playerDirectory;
|
||||
}
|
||||
|
||||
@@ -380,13 +343,14 @@ public class PlayerEvent extends LivingEvent
|
||||
* The UUID is the standard for player related file storage.
|
||||
* It is broken out here for convenience for quick file generation.
|
||||
*/
|
||||
public String getPlayerUUID()
|
||||
{
|
||||
public String getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ItemPickupEvent extends PlayerEvent {
|
||||
public static final EventBus<ItemPickupEvent> BUS = EventBus.create(ItemPickupEvent.class);
|
||||
|
||||
/**
|
||||
* Original EntityItem with current remaining stack size
|
||||
*/
|
||||
@@ -395,8 +359,8 @@ public class PlayerEvent extends LivingEvent
|
||||
* Clone item stack, containing the item and amount picked up
|
||||
*/
|
||||
private final ItemStack stack;
|
||||
public ItemPickupEvent(Player player, ItemEntity entPickedUp, ItemStack stack)
|
||||
{
|
||||
|
||||
public ItemPickupEvent(Player player, ItemEntity entPickedUp, ItemStack stack) {
|
||||
super(player);
|
||||
this.originalEntity = entPickedUp;
|
||||
this.stack = stack;
|
||||
@@ -412,63 +376,67 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
|
||||
public static final class ItemCraftedEvent extends PlayerEvent {
|
||||
public static final EventBus<ItemCraftedEvent> BUS = EventBus.create(ItemCraftedEvent.class);
|
||||
|
||||
@NotNull
|
||||
private final ItemStack crafting;
|
||||
private final Container craftMatrix;
|
||||
public ItemCraftedEvent(Player player, @NotNull ItemStack crafting, Container craftMatrix)
|
||||
{
|
||||
|
||||
public ItemCraftedEvent(Player player, @NotNull ItemStack crafting, Container craftMatrix) {
|
||||
super(player);
|
||||
this.crafting = crafting;
|
||||
this.craftMatrix = craftMatrix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getCrafting()
|
||||
{
|
||||
public ItemStack getCrafting() {
|
||||
return this.crafting;
|
||||
}
|
||||
|
||||
public Container getInventory()
|
||||
{
|
||||
public Container getInventory() {
|
||||
return this.craftMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ItemSmeltedEvent extends PlayerEvent {
|
||||
public static final EventBus<ItemSmeltedEvent> BUS = EventBus.create(ItemSmeltedEvent.class);
|
||||
|
||||
@NotNull
|
||||
private final ItemStack smelting;
|
||||
public ItemSmeltedEvent(Player player, @NotNull ItemStack crafting)
|
||||
{
|
||||
|
||||
public ItemSmeltedEvent(Player player, @NotNull ItemStack crafting) {
|
||||
super(player);
|
||||
this.smelting = crafting;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getSmelting()
|
||||
{
|
||||
public ItemStack getSmelting() {
|
||||
return this.smelting;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PlayerLoggedInEvent extends PlayerEvent {
|
||||
public PlayerLoggedInEvent(Player player)
|
||||
{
|
||||
public static final EventBus<PlayerLoggedInEvent> BUS = EventBus.create(PlayerLoggedInEvent.class);
|
||||
|
||||
public PlayerLoggedInEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PlayerLoggedOutEvent extends PlayerEvent {
|
||||
public PlayerLoggedOutEvent(Player player)
|
||||
{
|
||||
public static final EventBus<PlayerLoggedOutEvent> BUS = EventBus.create(PlayerLoggedOutEvent.class);
|
||||
|
||||
public PlayerLoggedOutEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PlayerRespawnEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerRespawnEvent> BUS = EventBus.create(PlayerRespawnEvent.class);
|
||||
|
||||
private final boolean endConquered;
|
||||
|
||||
public PlayerRespawnEvent(Player player, boolean endConquered)
|
||||
{
|
||||
public PlayerRespawnEvent(Player player, boolean endConquered) {
|
||||
super(player);
|
||||
this.endConquered = endConquered;
|
||||
}
|
||||
@@ -477,31 +445,28 @@ public class PlayerEvent extends LivingEvent
|
||||
* Did this respawn event come from the player conquering the end?
|
||||
* @return if this respawn was because the player conquered the end
|
||||
*/
|
||||
public boolean isEndConquered()
|
||||
{
|
||||
public boolean isEndConquered() {
|
||||
return this.endConquered;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static final class PlayerChangedDimensionEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerChangedDimensionEvent> BUS = EventBus.create(PlayerChangedDimensionEvent.class);
|
||||
|
||||
private final ResourceKey<Level> fromDim;
|
||||
private final ResourceKey<Level> toDim;
|
||||
public PlayerChangedDimensionEvent(Player player, ResourceKey<Level> fromDim, ResourceKey<Level> toDim)
|
||||
{
|
||||
|
||||
public PlayerChangedDimensionEvent(Player player, ResourceKey<Level> fromDim, ResourceKey<Level> toDim) {
|
||||
super(player);
|
||||
this.fromDim = fromDim;
|
||||
this.toDim = toDim;
|
||||
}
|
||||
|
||||
public ResourceKey<Level> getFrom()
|
||||
{
|
||||
public ResourceKey<Level> getFrom() {
|
||||
return this.fromDim;
|
||||
}
|
||||
|
||||
public ResourceKey<Level> getTo()
|
||||
{
|
||||
public ResourceKey<Level> getTo() {
|
||||
return this.toDim;
|
||||
}
|
||||
}
|
||||
@@ -510,34 +475,30 @@ public class PlayerEvent extends LivingEvent
|
||||
* Fired when the game type of a server player is changed to a different value than what it was previously. Eg Creative to Survival, not Survival to Survival.
|
||||
* If the event is cancelled the game mode of the player is not changed and the value of <code>newGameMode</code> is ignored.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class PlayerChangeGameModeEvent extends PlayerEvent
|
||||
{
|
||||
public static final class PlayerChangeGameModeEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<PlayerChangeGameModeEvent> BUS = CancellableEventBus.create(PlayerChangeGameModeEvent.class);
|
||||
|
||||
private final GameType currentGameMode;
|
||||
private GameType newGameMode;
|
||||
|
||||
public PlayerChangeGameModeEvent(Player player, GameType currentGameMode, GameType newGameMode)
|
||||
{
|
||||
public PlayerChangeGameModeEvent(Player player, GameType currentGameMode, GameType newGameMode) {
|
||||
super(player);
|
||||
this.currentGameMode = currentGameMode;
|
||||
this.newGameMode = newGameMode;
|
||||
}
|
||||
|
||||
public GameType getCurrentGameMode()
|
||||
{
|
||||
public GameType getCurrentGameMode() {
|
||||
return currentGameMode;
|
||||
}
|
||||
|
||||
public GameType getNewGameMode()
|
||||
{
|
||||
public GameType getNewGameMode() {
|
||||
return newGameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the game mode the player will be changed to if this event is not cancelled.
|
||||
*/
|
||||
public void setNewGameMode(GameType newGameMode)
|
||||
{
|
||||
public void setNewGameMode(GameType newGameMode) {
|
||||
this.newGameMode = newGameMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,20 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* Occurs when a player falls, but is able to fly. Doesn't need to be cancelable, this is mainly for notification purposes.
|
||||
* @author Mithion
|
||||
*
|
||||
*/
|
||||
public final class PlayerFlyableFallEvent extends PlayerEvent
|
||||
{
|
||||
public final class PlayerFlyableFallEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerFlyableFallEvent> BUS = EventBus.create(PlayerFlyableFallEvent.class);
|
||||
|
||||
private float distance;
|
||||
private float multiplier;
|
||||
|
||||
public PlayerFlyableFallEvent(Player player, float distance, float multiplier)
|
||||
{
|
||||
public PlayerFlyableFallEvent(Player player, float distance, float multiplier) {
|
||||
super(player);
|
||||
this.distance = distance;
|
||||
this.multiplier = multiplier;
|
||||
|
||||
@@ -24,8 +24,11 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -38,6 +41,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
* See the individual documentation on each subevent for more details.
|
||||
**/
|
||||
public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerInteractEvent> BUS = EventBus.create(PlayerInteractEvent.class);
|
||||
|
||||
private final InteractionHand hand;
|
||||
private final BlockPos pos;
|
||||
@Nullable
|
||||
@@ -60,8 +65,9 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* Let result be the return value of {@link Entity#interactAt(Player, Vec3, InteractionHand)}, or {@link #cancellationResult} if the event is cancelled.
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then try {@link EntityInteract}.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class EntityInteractSpecific extends PlayerInteractEvent {
|
||||
public static final class EntityInteractSpecific extends PlayerInteractEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityInteractSpecific> BUS = CancellableEventBus.create(EntityInteractSpecific.class);
|
||||
|
||||
private final Vec3 localPos;
|
||||
private final Entity target;
|
||||
|
||||
@@ -99,8 +105,9 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* or {@link #cancellationResult} if the event is cancelled.
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then try {@link RightClickItem}.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class EntityInteract extends PlayerInteractEvent {
|
||||
public static final class EntityInteract extends PlayerInteractEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityInteract> BUS = CancellableEventBus.create(EntityInteract.class);
|
||||
|
||||
private final Entity target;
|
||||
|
||||
public EntityInteract(Player player, InteractionHand hand, Entity target) {
|
||||
@@ -117,7 +124,7 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* This event is fired on both sides whenever the player right clicks while targeting a block. <br>
|
||||
* This event controls which of {@link Item#onItemUseFirst}, {@link Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)},
|
||||
* and {@link Item#useOn(UseOnContext)} will be called. <br>
|
||||
* Canceling the event will cause none of the above three to be called. <br>
|
||||
* Cancelling the event will cause none of the above three to be called. <br>
|
||||
* <br>
|
||||
* Let result be the first non-pass return value of the above three methods, or pass, if they all pass. <br>
|
||||
* Or {@link #cancellationResult} if the event is cancelled. <br>
|
||||
@@ -126,8 +133,9 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* 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!
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class RightClickBlock extends PlayerInteractEvent {
|
||||
public static final class RightClickBlock extends PlayerInteractEvent implements Cancellable {
|
||||
public static final CancellableEventBus<RightClickBlock> BUS = CancellableEventBus.create(RightClickBlock.class);
|
||||
|
||||
private Result useBlock = Result.DEFAULT;
|
||||
private Result useItem = Result.DEFAULT;
|
||||
private final BlockHitResult hitVec;
|
||||
@@ -176,15 +184,6 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
public void setUseItem(Result triggerItem) {
|
||||
this.useItem = triggerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(boolean canceled) {
|
||||
super.setCanceled(canceled);
|
||||
if (canceled) {
|
||||
useBlock = Result.DENY;
|
||||
useItem = Result.DENY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,8 +193,9 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* Let result be the return value of {@link Item#use(Level, Player, InteractionHand)}, or {@link #cancellationResult} if the event is cancelled.
|
||||
* If we are on the client and result is not {@link InteractionResult#SUCCESS}, the client will then continue to other hands.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class RightClickItem extends PlayerInteractEvent {
|
||||
public static final class RightClickItem extends PlayerInteractEvent implements Cancellable {
|
||||
public static final CancellableEventBus<RightClickItem> BUS = CancellableEventBus.create(RightClickItem.class);
|
||||
|
||||
public RightClickItem(Player player, InteractionHand hand) {
|
||||
super(player, hand, player.blockPosition(), null);
|
||||
}
|
||||
@@ -207,6 +207,8 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static final class RightClickEmpty extends PlayerInteractEvent {
|
||||
public static final EventBus<RightClickEmpty> BUS = EventBus.create(RightClickEmpty.class);
|
||||
|
||||
public RightClickEmpty(Player player, InteractionHand hand) {
|
||||
super(player, hand, player.blockPosition(), null);
|
||||
}
|
||||
@@ -227,8 +229,9 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* Also note that creative mode directly breaks the block without running any other logic.
|
||||
* Therefore, in creative mode, {@link #setUseBlock} and {@link #setUseItem} have no effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class LeftClickBlock extends PlayerInteractEvent {
|
||||
public static final class LeftClickBlock extends PlayerInteractEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LeftClickBlock> BUS = CancellableEventBus.create(LeftClickBlock.class);
|
||||
|
||||
private Result useBlock = Result.DEFAULT;
|
||||
private Result useItem = Result.DEFAULT;
|
||||
private final Action action;
|
||||
@@ -269,16 +272,7 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
this.useItem = triggerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(boolean canceled) {
|
||||
super.setCanceled(canceled);
|
||||
if (canceled) {
|
||||
useBlock = Result.DENY;
|
||||
useItem = Result.DENY;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Action {
|
||||
public enum Action {
|
||||
/**
|
||||
* When the player first left clicks a block
|
||||
*/
|
||||
@@ -314,6 +308,8 @@ public sealed class PlayerInteractEvent extends PlayerEvent {
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static final class LeftClickEmpty extends PlayerInteractEvent {
|
||||
public static final EventBus<LeftClickEmpty> BUS = EventBus.create(LeftClickEmpty.class);
|
||||
|
||||
public LeftClickEmpty(Player player) {
|
||||
super(player, InteractionHand.MAIN_HAND, player.blockPosition(), null);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -17,8 +18,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p>
|
||||
* The event can be canceled, which will prevent the spawn point from being changed.
|
||||
*/
|
||||
@Cancelable
|
||||
public final class PlayerSetSpawnEvent extends PlayerEvent {
|
||||
public final class PlayerSetSpawnEvent extends PlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<PlayerSetSpawnEvent> BUS = CancellableEventBus.create(PlayerSetSpawnEvent.class);
|
||||
|
||||
private final @Nullable ServerPlayer.RespawnConfig config;
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.Player.BedSleepingProblem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -24,34 +25,30 @@ import java.util.Optional;
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class PlayerSleepInBedEvent extends PlayerEvent
|
||||
{
|
||||
public final class PlayerSleepInBedEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerSleepInBedEvent> BUS = EventBus.create(PlayerSleepInBedEvent.class);
|
||||
|
||||
private BedSleepingProblem result = null;
|
||||
private final Optional<BlockPos> pos;
|
||||
|
||||
public PlayerSleepInBedEvent(Player player, Optional<BlockPos> pos)
|
||||
{
|
||||
public PlayerSleepInBedEvent(Player player, Optional<BlockPos> pos) {
|
||||
super(player);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public BedSleepingProblem getResultStatus()
|
||||
{
|
||||
public BedSleepingProblem getResultStatus() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(BedSleepingProblem result)
|
||||
{
|
||||
public void setResult(BedSleepingProblem result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public BlockPos getPos()
|
||||
{
|
||||
public BlockPos getPos() {
|
||||
return pos.orElse(null);
|
||||
}
|
||||
|
||||
public Optional<BlockPos> getOptionalPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,9 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.world.level.levelgen.PhantomSpawner;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -22,9 +24,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* @see PlayerSpawnPhantomsEvent#setResult for the effects of each result.
|
||||
*/
|
||||
@Event.HasResult
|
||||
public final class PlayerSpawnPhantomsEvent extends PlayerEvent {
|
||||
public final class PlayerSpawnPhantomsEvent extends PlayerEvent implements HasResult {
|
||||
public static final EventBus<PlayerSpawnPhantomsEvent> BUS = EventBus.create(PlayerSpawnPhantomsEvent.class);
|
||||
|
||||
private int phantomsToSpawn;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public PlayerSpawnPhantomsEvent(Player player, int phantomsToSpawn) {
|
||||
super(player);
|
||||
@@ -46,6 +50,11 @@ public final class PlayerSpawnPhantomsEvent extends PlayerEvent {
|
||||
this.phantomsToSpawn = phantomsToSpawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of this event controls if phantoms will be spawned.<br>
|
||||
* <ul>
|
||||
@@ -56,6 +65,6 @@ public final class PlayerSpawnPhantomsEvent extends PlayerEvent {
|
||||
*/
|
||||
@Override
|
||||
public void setResult(@NotNull Result result) {
|
||||
super.setResult(result);
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,20 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* This event is fired when the player is waking up.<br/>
|
||||
* This is merely for purposes of listening for this to happen.<br/>
|
||||
* There is nothing that can be manipulated with this event.
|
||||
*/
|
||||
public final class PlayerWakeUpEvent extends PlayerEvent
|
||||
{
|
||||
private final boolean wakeImmediately;
|
||||
public final class PlayerWakeUpEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerWakeUpEvent> BUS = EventBus.create(PlayerWakeUpEvent.class);
|
||||
|
||||
private final boolean wakeImmediately;
|
||||
private final boolean updateLevel;
|
||||
|
||||
public PlayerWakeUpEvent(Player player, boolean wakeImmediately, boolean updateLevel)
|
||||
{
|
||||
public PlayerWakeUpEvent(Player player, boolean wakeImmediately, boolean updateLevel) {
|
||||
super(player);
|
||||
this.wakeImmediately = wakeImmediately;
|
||||
this.updateLevel = updateLevel;
|
||||
|
||||
@@ -8,7 +8,9 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* PlayerXpEvent is fired whenever an event involving player experience occurs. <br>
|
||||
@@ -18,6 +20,8 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public sealed class PlayerXpEvent extends PlayerEvent {
|
||||
public static final EventBus<PlayerXpEvent> BUS = EventBus.create(PlayerXpEvent.class);
|
||||
|
||||
public PlayerXpEvent(Player player) {
|
||||
super(player);
|
||||
}
|
||||
@@ -26,8 +30,9 @@ public sealed class PlayerXpEvent extends PlayerEvent {
|
||||
* This event is fired after the player collides with an experience orb, but before the player has been given the experience.
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class PickupXp extends PlayerXpEvent {
|
||||
public static final class PickupXp extends PlayerXpEvent implements Cancellable {
|
||||
public static final CancellableEventBus<PickupXp> BUS = CancellableEventBus.create(PickupXp.class);
|
||||
|
||||
private final ExperienceOrb orb;
|
||||
|
||||
public PickupXp(Player player, ExperienceOrb orb) {
|
||||
@@ -44,8 +49,9 @@ public sealed class PlayerXpEvent extends PlayerEvent {
|
||||
* This event is fired when the player's experience changes through the {@link Player#giveExperiencePoints(int)} method.
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class XpChange extends PlayerXpEvent {
|
||||
public static final class XpChange extends PlayerXpEvent implements Cancellable {
|
||||
public static final CancellableEventBus<XpChange> BUS = CancellableEventBus.create(XpChange.class);
|
||||
|
||||
private int amount;
|
||||
|
||||
public XpChange(Player player, int amount) {
|
||||
@@ -66,8 +72,9 @@ public sealed class PlayerXpEvent extends PlayerEvent {
|
||||
* This event is fired when the player's experience level changes through the {@link Player#giveExperienceLevels(int)} method.
|
||||
* It can be cancelled, and no further processing will be done.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class LevelChange extends PlayerXpEvent {
|
||||
public static final class LevelChange extends PlayerXpEvent implements Cancellable {
|
||||
public static final CancellableEventBus<LevelChange> BUS = CancellableEventBus.create(LevelChange.class);
|
||||
|
||||
private int levels;
|
||||
|
||||
public LevelChange(Player player, int levels) {
|
||||
|
||||
+18
-8
@@ -11,8 +11,10 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* This event is fired when game checks, if sleeping player should be still considered "in bed".<br>
|
||||
@@ -23,20 +25,28 @@ import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
* setResult(ALLOW) informs game that player is still "in bed"<br>
|
||||
* setResult(DEFAULT) causes game to check {@link Block#isBed(BlockState, BlockGetter, BlockPos, Entity)} instead
|
||||
*/
|
||||
@HasResult
|
||||
public final class SleepingLocationCheckEvent extends LivingEvent
|
||||
{
|
||||
public final class SleepingLocationCheckEvent extends LivingEvent implements HasResult {
|
||||
public static final EventBus<SleepingLocationCheckEvent> BUS = EventBus.create(SleepingLocationCheckEvent.class);
|
||||
|
||||
private final BlockPos sleepingLocation;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public SleepingLocationCheckEvent(LivingEntity player, BlockPos sleepingLocation)
|
||||
{
|
||||
public SleepingLocationCheckEvent(LivingEntity player, BlockPos sleepingLocation) {
|
||||
super(player);
|
||||
this.sleepingLocation = sleepingLocation;
|
||||
}
|
||||
|
||||
public BlockPos getSleepingLocation()
|
||||
{
|
||||
public BlockPos getSleepingLocation() {
|
||||
return sleepingLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -21,13 +23,13 @@ import java.util.Optional;
|
||||
* setResult(ALLOW) informs game that player can sleep at this time.<br>
|
||||
* setResult(DEFAULT) causes game to check !{@link Level#isDay()} instead.
|
||||
*/
|
||||
@HasResult
|
||||
public final class SleepingTimeCheckEvent extends PlayerEvent
|
||||
{
|
||||
private final Optional<BlockPos> sleepingLocation;
|
||||
public final class SleepingTimeCheckEvent extends PlayerEvent implements HasResult {
|
||||
public static final EventBus<SleepingTimeCheckEvent> BUS = EventBus.create(SleepingTimeCheckEvent.class);
|
||||
|
||||
public SleepingTimeCheckEvent(Player player, Optional<BlockPos> sleepingLocation)
|
||||
{
|
||||
private final Optional<BlockPos> sleepingLocation;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public SleepingTimeCheckEvent(Player player, Optional<BlockPos> sleepingLocation) {
|
||||
super(player);
|
||||
this.sleepingLocation = sleepingLocation;
|
||||
}
|
||||
@@ -36,8 +38,17 @@ public final class SleepingTimeCheckEvent extends PlayerEvent
|
||||
* Note that the sleeping location may be an approximated one.
|
||||
* @return The player's sleeping location.
|
||||
*/
|
||||
public Optional<BlockPos> getSleepingLocation()
|
||||
{
|
||||
public Optional<BlockPos> getSleepingLocation() {
|
||||
return sleepingLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.world.entity.npc.AbstractVillager;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.trading.MerchantOffer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
@@ -20,14 +20,14 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
*/
|
||||
public final class TradeWithVillagerEvent extends PlayerEvent
|
||||
{
|
||||
public final class TradeWithVillagerEvent extends PlayerEvent {
|
||||
public static final EventBus<TradeWithVillagerEvent> BUS = EventBus.create(TradeWithVillagerEvent.class);
|
||||
|
||||
private final MerchantOffer offer;
|
||||
private final AbstractVillager abstractVillager;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public TradeWithVillagerEvent(Player player, MerchantOffer offer, AbstractVillager abstractVillager)
|
||||
{
|
||||
public TradeWithVillagerEvent(Player player, MerchantOffer offer, AbstractVillager abstractVillager) {
|
||||
super(player);
|
||||
this.offer = offer;
|
||||
this.abstractVillager = abstractVillager;
|
||||
@@ -36,16 +36,14 @@ public final class TradeWithVillagerEvent extends PlayerEvent
|
||||
/**
|
||||
* {@return the {@link MerchantOffer} selected by the player to trade with}
|
||||
*/
|
||||
public MerchantOffer getMerchantOffer()
|
||||
{
|
||||
public MerchantOffer getMerchantOffer() {
|
||||
return offer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the villager the player traded with}
|
||||
*/
|
||||
public AbstractVillager getAbstractVillager()
|
||||
{
|
||||
public AbstractVillager getAbstractVillager() {
|
||||
return abstractVillager;
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ package net.minecraftforge.event.furnace;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -22,23 +22,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* This event is fired from {@link ForgeEventFactory#getItemBurnTime(ItemStack, int, RecipeType)}.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable} to prevent later handlers from changing the value.<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 {@link Cancellable} to prevent later handlers from changing the value.
|
||||
**/
|
||||
@Cancelable
|
||||
public final class FurnaceFuelBurnTimeEvent extends Event
|
||||
{
|
||||
public final class FurnaceFuelBurnTimeEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<FurnaceFuelBurnTimeEvent> BUS = CancellableEventBus.create(FurnaceFuelBurnTimeEvent.class);
|
||||
|
||||
@NotNull
|
||||
private final ItemStack itemStack;
|
||||
@Nullable
|
||||
private final RecipeType<?> recipeType;
|
||||
private int burnTime;
|
||||
|
||||
public FurnaceFuelBurnTimeEvent(@NotNull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType)
|
||||
{
|
||||
public FurnaceFuelBurnTimeEvent(@NotNull ItemStack itemStack, int burnTime, @Nullable RecipeType<?> recipeType) {
|
||||
this.itemStack = itemStack;
|
||||
this.burnTime = burnTime;
|
||||
this.recipeType = recipeType;
|
||||
@@ -48,8 +43,7 @@ public final class FurnaceFuelBurnTimeEvent extends Event
|
||||
* Get the ItemStack "fuel" in question.
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -58,8 +52,7 @@ public final class FurnaceFuelBurnTimeEvent extends Event
|
||||
* Get the recipe type for which to obtain the burn time, if known.
|
||||
*/
|
||||
@Nullable
|
||||
public RecipeType<?> getRecipeType()
|
||||
{
|
||||
public RecipeType<?> getRecipeType() {
|
||||
return recipeType;
|
||||
}
|
||||
|
||||
@@ -67,12 +60,9 @@ public final class FurnaceFuelBurnTimeEvent extends Event
|
||||
* Set the burn time for the given ItemStack.
|
||||
* Setting it to 0 will prevent the item from being used as fuel, overriding vanilla's decision.
|
||||
*/
|
||||
public void setBurnTime(int burnTime)
|
||||
{
|
||||
if (burnTime >= 0)
|
||||
{
|
||||
public void setBurnTime(int burnTime) {
|
||||
if (burnTime >= 0) {
|
||||
this.burnTime = burnTime;
|
||||
setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +70,7 @@ public final class FurnaceFuelBurnTimeEvent extends Event
|
||||
* The resulting value of this event, the burn time for the ItemStack.
|
||||
* A value of 0 will prevent the item from being used as fuel, overriding vanilla's decision.
|
||||
*/
|
||||
public int getBurnTime()
|
||||
{
|
||||
public int getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.world.level.LevelSimulatedReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,9 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* 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}.
|
||||
*/
|
||||
public final class AlterGroundEvent extends Event {
|
||||
public final class AlterGroundEvent extends MutableEvent {
|
||||
public static final EventBus<AlterGroundEvent> BUS = EventBus.create(AlterGroundEvent.class);
|
||||
|
||||
private final LevelSimulatedReader level;
|
||||
private final RandomSource random;
|
||||
private final BlockPos pos;
|
||||
|
||||
@@ -27,14 +27,22 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockEvent extends Event {
|
||||
public class BlockEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<BlockEvent> BUS = EventBus.create(BlockEvent.class);
|
||||
|
||||
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
|
||||
|
||||
private final LevelAccessor level;
|
||||
@@ -61,17 +69,20 @@ public class BlockEvent extends Event {
|
||||
|
||||
/**
|
||||
* Event that is fired when an Block is about to be broken by a player
|
||||
* Canceling this event will prevent the Block from being broken.
|
||||
* Setting the result to {@link Result#DENY} will prevent the Block from being broken.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class BreakEvent extends BlockEvent {
|
||||
public static final class BreakEvent extends BlockEvent implements Cancellable, HasResult {
|
||||
public static final CancellableEventBus<BreakEvent> BUS = CancellableEventBus.create(BreakEvent.class);
|
||||
|
||||
/** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */
|
||||
private final Player player;
|
||||
private int exp;
|
||||
private Result result;
|
||||
|
||||
public BreakEvent(Level level, BlockPos pos, BlockState state, Player player) {
|
||||
public BreakEvent(Level level, BlockPos pos, BlockState state, Player player, Result result) {
|
||||
super(level, pos, state);
|
||||
this.player = player;
|
||||
this.result = result;
|
||||
|
||||
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) { // Handle empty block or player unable to break block scenario
|
||||
this.exp = 0;
|
||||
@@ -91,10 +102,10 @@ public class BlockEvent extends Event {
|
||||
/**
|
||||
* Get the experience dropped by the block after the event has processed
|
||||
*
|
||||
* @return The experience to drop or 0 if the event was canceled
|
||||
* @return The experience to drop or 0 if the event was denied
|
||||
*/
|
||||
public int getExpToDrop() {
|
||||
return this.isCanceled() ? 0 : exp;
|
||||
return this.getResult().isDenied() ? 0 : exp;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +116,16 @@ public class BlockEvent extends Event {
|
||||
public void setExpToDrop(int exp) {
|
||||
this.exp = exp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,8 +133,9 @@ public class BlockEvent extends Event {
|
||||
*
|
||||
* If a Block Place event is cancelled, the block will not be placed.
|
||||
*/
|
||||
@Cancelable
|
||||
public static sealed class EntityPlaceEvent extends BlockEvent {
|
||||
public static sealed class EntityPlaceEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityPlaceEvent> BUS = CancellableEventBus.create(EntityPlaceEvent.class);
|
||||
|
||||
private final Entity entity;
|
||||
private final BlockSnapshot blockSnapshot;
|
||||
private final BlockState placedBlock;
|
||||
@@ -145,8 +167,9 @@ public class BlockEvent extends Event {
|
||||
* the placed block would exist if the placement only affected a single
|
||||
* block.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class EntityMultiPlaceEvent extends EntityPlaceEvent {
|
||||
public static final class EntityMultiPlaceEvent extends EntityPlaceEvent implements Cancellable {
|
||||
public static final CancellableEventBus<EntityMultiPlaceEvent> BUS = CancellableEventBus.create(EntityMultiPlaceEvent.class);
|
||||
|
||||
private final List<BlockSnapshot> blockSnapshots;
|
||||
|
||||
public EntityMultiPlaceEvent(@NotNull List<BlockSnapshot> blockSnapshots, @NotNull BlockState placedAgainst, @Nullable Entity entity) {
|
||||
@@ -173,8 +196,9 @@ public class BlockEvent extends Event {
|
||||
* a way for mods to detect physics updates, in the same way a BUD switch
|
||||
* does. This event is only called on the server.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class NeighborNotifyEvent extends BlockEvent {
|
||||
public static final class NeighborNotifyEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<NeighborNotifyEvent> BUS = CancellableEventBus.create(NeighborNotifyEvent.class);
|
||||
|
||||
private final EnumSet<Direction> notifiedSides;
|
||||
private final boolean forceRedstoneUpdate;
|
||||
|
||||
@@ -208,28 +232,11 @@ public class BlockEvent extends Event {
|
||||
* usually doesn't do that (like lava), and a result of DENY prevents creation
|
||||
* even if the liquid usually does do that (like water).
|
||||
*/
|
||||
@HasResult
|
||||
public static final class CreateFluidSourceEvent extends Event {
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
private final BlockState state;
|
||||
public record CreateFluidSourceEvent(Level getLevel, BlockPos getPos, BlockState getState, Result.Holder resultHolder) implements RecordEvent, HasResult.Record {
|
||||
public static final EventBus<CreateFluidSourceEvent> BUS = EventBus.create(CreateFluidSourceEvent.class);
|
||||
|
||||
public CreateFluidSourceEvent(Level level, BlockPos pos, BlockState state) {
|
||||
this.level = level;
|
||||
this.pos = pos;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public BlockState getState() {
|
||||
return state;
|
||||
this(level, pos, state, new Result.Holder());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +248,9 @@ public class BlockEvent extends Event {
|
||||
* {@link #getState()} will return the block that was originally going to be placed.
|
||||
* {@link #getPos()} will return the position of the block to be changed.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class FluidPlaceBlockEvent extends BlockEvent {
|
||||
public static final class FluidPlaceBlockEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<FluidPlaceBlockEvent> BUS = CancellableEventBus.create(FluidPlaceBlockEvent.class);
|
||||
|
||||
private final BlockPos liquidPos;
|
||||
private BlockState newState;
|
||||
private final BlockState origState;
|
||||
@@ -285,6 +293,8 @@ public class BlockEvent extends Event {
|
||||
*
|
||||
*/
|
||||
public static sealed class CropGrowEvent extends BlockEvent {
|
||||
public static final EventBus<CropGrowEvent> BUS = EventBus.create(CropGrowEvent.class);
|
||||
|
||||
public CropGrowEvent(Level level, BlockPos pos, BlockState state) {
|
||||
super(level, pos, state);
|
||||
}
|
||||
@@ -300,11 +310,24 @@ public class BlockEvent extends Event {
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
*/
|
||||
@HasResult
|
||||
public static final class Pre extends CropGrowEvent {
|
||||
public static final class Pre extends CropGrowEvent implements HasResult {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public Pre(Level level, BlockPos pos, BlockState state) {
|
||||
super(level, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,6 +340,8 @@ public class BlockEvent extends Event {
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
*/
|
||||
public static final class Post extends CropGrowEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
private final BlockState originalState;
|
||||
|
||||
public Post(Level level, BlockPos pos, BlockState original, BlockState state) {
|
||||
@@ -334,8 +359,9 @@ public class BlockEvent extends Event {
|
||||
* Fired when when farmland gets trampled
|
||||
* This event is {@link Cancelable}
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class FarmlandTrampleEvent extends BlockEvent {
|
||||
public static final class FarmlandTrampleEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<FarmlandTrampleEvent> BUS = CancellableEventBus.create(FarmlandTrampleEvent.class);
|
||||
|
||||
private final Entity entity;
|
||||
private final double fallDistance;
|
||||
|
||||
@@ -360,8 +386,9 @@ public class BlockEvent extends Event {
|
||||
*
|
||||
* If cancelled, the portal will not be spawned.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class PortalSpawnEvent extends BlockEvent {
|
||||
public static final class PortalSpawnEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<PortalSpawnEvent> BUS = CancellableEventBus.create(PortalSpawnEvent.class);
|
||||
|
||||
private final PortalShape size;
|
||||
|
||||
public PortalSpawnEvent(LevelAccessor level, BlockPos pos, BlockState state, PortalShape size) {
|
||||
@@ -384,8 +411,9 @@ public class BlockEvent extends Event {
|
||||
* This event is {@link Cancelable}. If canceled, this will prevent the tool
|
||||
* from changing the block's state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static final class BlockToolModificationEvent extends BlockEvent {
|
||||
public static final class BlockToolModificationEvent extends BlockEvent implements Cancellable {
|
||||
public static final CancellableEventBus<BlockToolModificationEvent> BUS = CancellableEventBus.create(BlockToolModificationEvent.class);
|
||||
|
||||
private final UseOnContext context;
|
||||
private final ToolAction toolAction;
|
||||
private final boolean simulate;
|
||||
|
||||
@@ -13,8 +13,7 @@ import net.minecraft.world.level.chunk.status.ChunkType;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
|
||||
/**
|
||||
* ChunkDataEvent is fired when an event involving chunk data occurs.<br>
|
||||
@@ -26,6 +25,8 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public sealed class ChunkDataEvent extends ChunkEvent {
|
||||
public static final EventBus<ChunkDataEvent> BUS = EventBus.create(ChunkDataEvent.class);
|
||||
|
||||
private final SerializableChunkData data;
|
||||
|
||||
public ChunkDataEvent(ChunkAccess chunk, SerializableChunkData data) {
|
||||
@@ -46,14 +47,10 @@ public sealed class ChunkDataEvent extends ChunkEvent {
|
||||
* ChunkDataEvent.Load is fired when vanilla Minecraft attempts to load Chunk data.<br>
|
||||
* This event is fired during chunk loading in
|
||||
* {@link ChunkSerializer#read(ServerLevel, PoiManager, ChunkPos, SerializableChunkData)} which means it is async, so be careful.<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 final class Load extends ChunkDataEvent {
|
||||
public static final EventBus<ChunkDataEvent.Load> BUS = EventBus.create(ChunkDataEvent.Load.class);
|
||||
|
||||
private final ChunkType status;
|
||||
|
||||
public Load(ChunkAccess chunk, SerializableChunkData data, ChunkType status) {
|
||||
@@ -70,14 +67,10 @@ public sealed class ChunkDataEvent extends ChunkEvent {
|
||||
* ChunkDataEvent.Save is fired when vanilla Minecraft attempts to save Chunk data.<br>
|
||||
* This event is fired during chunk saving in
|
||||
* {@code ChunkMap#save(ChunkAccess)}. <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 final class Save extends ChunkDataEvent {
|
||||
public static final EventBus<ChunkDataEvent.Save> BUS = EventBus.create(ChunkDataEvent.Save.class);
|
||||
|
||||
public Save(ChunkAccess chunk, LevelAccessor world, SerializableChunkData data) {
|
||||
super(chunk, world, data);
|
||||
}
|
||||
|
||||
Loaded 100 of 642 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user