mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Make more events records
This commit is contained in:
1 parent
6915753b5a
commit
219abfed22
22 files changed
+188
-522
No files matched your search
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.color.block.BlockTintCache;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.level.ColorResolver;
|
||||
@@ -13,22 +12,23 @@ import net.minecraftforge.client.event.RegisterColorHandlersEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manager for custom {@link ColorResolver} instances, collected via {@link RegisterColorHandlersEvent.ColorResolvers}.
|
||||
*/
|
||||
public final class ColorResolverManager
|
||||
{
|
||||
public final class ColorResolverManager {
|
||||
private ColorResolverManager() {}
|
||||
|
||||
private static ImmutableList<ColorResolver> colorResolvers;
|
||||
private static List<ColorResolver> colorResolvers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void init()
|
||||
{
|
||||
ImmutableList.Builder<ColorResolver> builder = ImmutableList.builder();
|
||||
public static void init() {
|
||||
var builder = new ArrayList<ColorResolver>();
|
||||
ModLoader.get().postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder));
|
||||
colorResolvers = builder.build();
|
||||
colorResolvers = List.copyOf(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,15 +37,9 @@ public final class ColorResolverManager
|
||||
* @param level the level to use
|
||||
* @param target the map to populate
|
||||
*/
|
||||
public static void registerBlockTintCaches(ClientLevel level, Map<ColorResolver, BlockTintCache> target)
|
||||
{
|
||||
for (var resolver : colorResolvers)
|
||||
{
|
||||
public static void registerBlockTintCaches(ClientLevel level, Map<ColorResolver, BlockTintCache> target) {
|
||||
for (var resolver : colorResolvers) {
|
||||
target.put(resolver, new BlockTintCache(pos -> level.calculateBlockTint(pos, resolver)));
|
||||
}
|
||||
}
|
||||
|
||||
private ColorResolverManager()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.renderer.DimensionSpecialEffects;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
||||
@@ -22,7 +21,9 @@ import java.util.Map;
|
||||
* Provides a lookup by dimension type.
|
||||
*/
|
||||
public final class DimensionSpecialEffectsManager {
|
||||
private static ImmutableMap<ResourceLocation, DimensionSpecialEffects> EFFECTS;
|
||||
private DimensionSpecialEffectsManager() {}
|
||||
|
||||
private static Map<ResourceLocation, DimensionSpecialEffects> EFFECTS;
|
||||
private static DimensionSpecialEffects DEFAULT_EFFECTS;
|
||||
|
||||
/**
|
||||
@@ -38,7 +39,7 @@ public final class DimensionSpecialEffectsManager {
|
||||
DEFAULT_EFFECTS = preRegisterVanillaEffects(effects);
|
||||
var event = new RegisterDimensionSpecialEffectsEvent(effects);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
EFFECTS = ImmutableMap.copyOf(effects);
|
||||
EFFECTS = Map.copyOf(effects);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,4 @@ public final class DimensionSpecialEffectsManager {
|
||||
effects.put(BuiltinDimensionTypes.END_EFFECTS, new DimensionSpecialEffects.EndEffects());
|
||||
return overworldEffects;
|
||||
}
|
||||
|
||||
private DimensionSpecialEffectsManager() { }
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraftforge.client.event.RegisterEntitySpectatorShadersEvent;
|
||||
@@ -21,29 +20,24 @@ import java.util.Map;
|
||||
* <p>
|
||||
* Provides a lookup.
|
||||
*/
|
||||
public final class EntitySpectatorShaderManager
|
||||
{
|
||||
public final class EntitySpectatorShaderManager {
|
||||
private EntitySpectatorShaderManager() {}
|
||||
|
||||
private static Map<EntityType<?>, ResourceLocation> SHADERS;
|
||||
|
||||
/**
|
||||
* Finds the path to the spectator mode shader used for the specified entity type, or null if none is registered.
|
||||
*/
|
||||
@Nullable
|
||||
public static ResourceLocation get(EntityType<?> entityType)
|
||||
{
|
||||
public static ResourceLocation get(EntityType<?> entityType) {
|
||||
return SHADERS.get(entityType);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void init()
|
||||
{
|
||||
public static void init() {
|
||||
var shaders = new HashMap<EntityType<?>, ResourceLocation>();
|
||||
var event = new RegisterEntitySpectatorShadersEvent(shaders);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
SHADERS = ImmutableMap.copyOf(shaders);
|
||||
}
|
||||
|
||||
private EntitySpectatorShaderManager()
|
||||
{
|
||||
SHADERS = Map.copyOf(shaders);
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,14 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
import net.minecraftforge.client.event.RegisterPresetEditorsEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
|
||||
public final class PresetEditorManager
|
||||
{
|
||||
public final class PresetEditorManager {
|
||||
private PresetEditorManager() {} // Utility class
|
||||
|
||||
private static Map<ResourceKey<WorldPreset>, PresetEditor> editors = Map.of();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ApiStatus.Internal
|
||||
static void init()
|
||||
{
|
||||
static void init() {
|
||||
// Start with the vanilla entries
|
||||
Map<ResourceKey<WorldPreset>, PresetEditor> gatheredEditors = new HashMap<>();
|
||||
// Vanilla's map uses Optional<ResourceKey>s as its keys.
|
||||
@@ -41,7 +39,7 @@ public final class PresetEditorManager
|
||||
RegisterPresetEditorsEvent event = new RegisterPresetEditorsEvent(gatheredEditors);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
|
||||
editors = gatheredEditors;
|
||||
editors = Map.copyOf(gatheredEditors);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,8 +48,7 @@ public final class PresetEditorManager
|
||||
* @param key ResourceKey for the specified WorldPreset/PresetEditor.
|
||||
*/
|
||||
@Nullable
|
||||
public static PresetEditor get(ResourceKey<WorldPreset> key)
|
||||
{
|
||||
public static PresetEditor get(ResourceKey<WorldPreset> key) {
|
||||
return editors.get(key);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
@@ -60,12 +61,10 @@ public abstract sealed class EntityRenderersEvent implements IModBusEvent {
|
||||
/**
|
||||
* Fired for registering layer definitions at the appropriate time.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class RegisterLayerDefinitions extends EntityRenderersEvent {
|
||||
public static final class RegisterLayerDefinitions extends EntityRenderersEvent implements SelfDestructing {
|
||||
public static EventBus<RegisterLayerDefinitions> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterLayerDefinitions.class);
|
||||
}
|
||||
@@ -92,12 +91,10 @@ public abstract sealed class EntityRenderersEvent implements IModBusEvent {
|
||||
* For registering entity renderer layers to existing entity renderers (whether vanilla or registered through this
|
||||
* event), listen for the {@link AddLayers} event instead.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class RegisterRenderers extends EntityRenderersEvent {
|
||||
public static final class RegisterRenderers extends EntityRenderersEvent implements SelfDestructing {
|
||||
public static EventBus<RegisterRenderers> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterRenderers.class);
|
||||
}
|
||||
|
||||
+2
-3
@@ -11,6 +11,7 @@ import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
@@ -22,12 +23,10 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
*
|
||||
* <p>For registering reload listeners on the server-side resource manager, see {@link AddReloadListenerEvent}.</p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public final class RegisterClientReloadListenersEvent implements IModBusEvent {
|
||||
public final class RegisterClientReloadListenersEvent implements SelfDestructing, IModBusEvent {
|
||||
public static EventBus<RegisterClientReloadListenersEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterClientReloadListenersEvent.class);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,14 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ColorResolver;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Fired for registering block and item color handlers at the appropriate time.
|
||||
@@ -76,15 +80,16 @@ public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent
|
||||
* Allows registration of custom {@link ColorResolver} implementations to be used with
|
||||
* {@link net.minecraft.world.level.BlockAndTintGetter#getBlockTint(BlockPos, ColorResolver)}.
|
||||
*/
|
||||
public static final class ColorResolvers extends RegisterColorHandlersEvent {
|
||||
@NullMarked
|
||||
public static final class ColorResolvers extends RegisterColorHandlersEvent implements SelfDestructing {
|
||||
public static EventBus<ColorResolvers> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, ColorResolvers.class);
|
||||
}
|
||||
|
||||
private final ImmutableList.Builder<ColorResolver> builder;
|
||||
private final ArrayList<ColorResolver> builder;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ColorResolvers(ImmutableList.Builder<ColorResolver> builder) {
|
||||
public ColorResolvers(ArrayList<ColorResolver> builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -9,22 +9,23 @@ import net.minecraft.client.renderer.DimensionSpecialEffects;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Allows users to register custom {@link DimensionSpecialEffects} for their dimensions.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public final class RegisterDimensionSpecialEffectsEvent implements IModBusEvent {
|
||||
@NullMarked
|
||||
public final class RegisterDimensionSpecialEffectsEvent implements SelfDestructing, IModBusEvent {
|
||||
public static EventBus<RegisterDimensionSpecialEffectsEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterDimensionSpecialEffectsEvent.class);
|
||||
}
|
||||
|
||||
+4
-3
@@ -9,10 +9,12 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,12 +22,11 @@ import java.util.Map;
|
||||
* Allows users to register custom shaders to be used when the player spectates a certain kind of entity.
|
||||
* Vanilla examples of this are the green effect for creepers and the invert effect for endermen.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public final class RegisterEntitySpectatorShadersEvent implements IModBusEvent {
|
||||
@NullMarked
|
||||
public final class RegisterEntitySpectatorShadersEvent implements SelfDestructing, IModBusEvent {
|
||||
public static EventBus<RegisterEntitySpectatorShadersEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterEntitySpectatorShadersEvent.class);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.SelfDestructing;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -24,12 +25,10 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
/**
|
||||
* <p>Event for registering {@link PresetEditor} screen factories for world presets.</p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public final class RegisterPresetEditorsEvent implements IModBusEvent {
|
||||
public final class RegisterPresetEditorsEvent implements SelfDestructing, IModBusEvent {
|
||||
public static EventBus<RegisterPresetEditorsEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterPresetEditorsEvent.class);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -21,48 +20,24 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* and can be used to replace the rendering of the player's arm, such as for rendering armor on the arm or outright
|
||||
* replacing the arm with armor.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the arm will not be rendered.</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}. If this event is cancelled, then the arm will not be rendered.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getPoseStack The pose stack used for rendering
|
||||
* @param getMultiBufferSource The source of rendering buffers
|
||||
* @param getArm The arm being rendered
|
||||
*/
|
||||
public final class RenderArmEvent extends MutableEvent implements Cancellable {
|
||||
public record RenderArmEvent(
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
int getPackedLight,
|
||||
HumanoidArm getArm
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<RenderArmEvent> BUS = CancellableEventBus.create(RenderArmEvent.class);
|
||||
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
private final HumanoidArm arm;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderArmEvent(PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, HumanoidArm arm) {
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
this.arm = arm;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the arm being rendered}
|
||||
*/
|
||||
public HumanoidArm getArm() {
|
||||
return arm;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
public RenderArmEvent {}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
@@ -70,6 +45,6 @@ public final class RenderArmEvent extends MutableEvent implements Cancellable {
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
return getPackedLight;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -19,13 +18,21 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
/**
|
||||
* Fired before a block texture will be overlaid on the player's view.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the overlay will not be rendered.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* @param getPlayer The player which the overlay will apply to
|
||||
* @param getPoseStack The pose stack used for rendering
|
||||
* @param getOverlayType The type of the overlay
|
||||
* @param getBlockState The block which the overlay is gotten from
|
||||
* @param getBlockPos The position of the block which the overlay is gotten from
|
||||
*/
|
||||
public final class RenderBlockScreenEffectEvent extends MutableEvent implements Cancellable {
|
||||
public record RenderBlockScreenEffectEvent(
|
||||
Player getPlayer,
|
||||
PoseStack getPoseStack,
|
||||
OverlayType getOverlayType,
|
||||
BlockState getBlockState,
|
||||
BlockPos getBlockPos
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<RenderBlockScreenEffectEvent> BUS = CancellableEventBus.create(RenderBlockScreenEffectEvent.class);
|
||||
|
||||
/**
|
||||
@@ -48,53 +55,6 @@ public final class RenderBlockScreenEffectEvent extends MutableEvent implements
|
||||
WATER
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
private final PoseStack poseStack;
|
||||
private final OverlayType overlayType;
|
||||
private final BlockState blockState;
|
||||
private final BlockPos blockPos;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderBlockScreenEffectEvent(Player player, PoseStack poseStack, OverlayType type, BlockState block, BlockPos blockPos) {
|
||||
this.player = player;
|
||||
this.poseStack = poseStack;
|
||||
this.overlayType = type;
|
||||
this.blockState = block;
|
||||
this.blockPos = blockPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player which the overlay will apply to}
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type of the overlay}
|
||||
*/
|
||||
public OverlayType getOverlayType() {
|
||||
return overlayType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the block which the overlay is gotten from}
|
||||
*/
|
||||
public BlockState getBlockState() {
|
||||
return blockState;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the position of the block which the overlay is gotten from}
|
||||
*/
|
||||
public BlockPos getBlockPos() {
|
||||
return blockPos;
|
||||
}
|
||||
public RenderBlockScreenEffectEvent {}
|
||||
}
|
||||
@@ -10,9 +10,8 @@ import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -20,63 +19,36 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
/**
|
||||
* Fired before a hand is rendered in the first person view.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the hand will not be rendered.</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}. If this event is cancelled, then the hand will not be rendered.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getHand The hand being rendered
|
||||
* @param getPoseStack The pose stack used for rendering
|
||||
* @param getMultiBufferSource The source of rendering buffers
|
||||
* @param getPartialTick The partial tick
|
||||
* @param getInterpolatedPitch The interpolated pitch of the player entity
|
||||
* @param getSwingProgress The swing progress of the hand being rendered
|
||||
* @param getEquipProgress The progress of the equip animation, from {@code 0.0} to {@code 1.0}
|
||||
* @param getItemStack The item stack to be rendered
|
||||
*
|
||||
* @see RenderArmEvent
|
||||
*/
|
||||
public final class RenderHandEvent extends MutableEvent implements Cancellable {
|
||||
public record RenderHandEvent(
|
||||
InteractionHand getHand,
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
int getPackedLight,
|
||||
float getPartialTick,
|
||||
float getInterpolatedPitch,
|
||||
float getSwingProgress,
|
||||
float getEquipProgress,
|
||||
ItemStack getItemStack
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<RenderHandEvent> BUS = CancellableEventBus.create(RenderHandEvent.class);
|
||||
|
||||
private final InteractionHand hand;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
private final float partialTick;
|
||||
private final float interpolatedPitch;
|
||||
private final float swingProgress;
|
||||
private final float equipProgress;
|
||||
private final ItemStack stack;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderHandEvent(InteractionHand hand, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight,
|
||||
float partialTick, float interpolatedPitch,
|
||||
float swingProgress, float equipProgress, ItemStack stack)
|
||||
{
|
||||
this.hand = hand;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
this.partialTick = partialTick;
|
||||
this.interpolatedPitch = interpolatedPitch;
|
||||
this.swingProgress = swingProgress;
|
||||
this.equipProgress = equipProgress;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the hand being rendered}
|
||||
*/
|
||||
public InteractionHand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
public RenderHandEvent {}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
@@ -84,41 +56,6 @@ public final class RenderHandEvent extends MutableEvent implements Cancellable {
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the interpolated pitch of the player entity}
|
||||
*/
|
||||
public float getInterpolatedPitch() {
|
||||
return interpolatedPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the swing progress of the hand being rendered}
|
||||
*/
|
||||
public float getSwingProgress() {
|
||||
return swingProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the progress of the equip animation, from {@code 0.0} to {@code 1.0}}
|
||||
*/
|
||||
public float getEquipProgress() {
|
||||
return equipProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the item stack to be rendered}
|
||||
*/
|
||||
public ItemStack getItemStack() {
|
||||
return stack;
|
||||
return getPackedLight;
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,8 @@ import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.ItemFrameRenderState;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -21,59 +20,28 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* Fired before an item stack is rendered in an item frame.
|
||||
* This can be used to prevent normal rendering or add custom rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, then the item stack will not be rendered</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}. If the event is cancelled, then the item stack will not be rendered</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getItemFrameState The item frame entity
|
||||
* @param getRenderer The renderer for the item frame entity
|
||||
* @param getPoseStack The pose stack used for rendering
|
||||
* @param getMultiBufferSource The source of rendering buffers
|
||||
*
|
||||
* @see ItemFrameRenderer
|
||||
*/
|
||||
public final class RenderItemInFrameEvent extends MutableEvent implements Cancellable {
|
||||
public record RenderItemInFrameEvent(
|
||||
ItemFrameRenderState getItemFrameState,
|
||||
ItemFrameRenderer<?> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
int getPackedLight
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<RenderItemInFrameEvent> BUS = CancellableEventBus.create(RenderItemInFrameEvent.class);
|
||||
|
||||
private final ItemFrameRenderState state;
|
||||
private final ItemFrameRenderer<?> renderer;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderItemInFrameEvent(ItemFrameRenderState state, ItemFrameRenderer<?> renderItemFrame, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
this.state = state;
|
||||
this.renderer = renderItemFrame;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the item frame entity}
|
||||
*/
|
||||
public ItemFrameRenderState getItemFrameState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the renderer for the item frame entity}
|
||||
*/
|
||||
public ItemFrameRenderer<?> getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
public RenderItemInFrameEvent {}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
@@ -81,6 +49,6 @@ public final class RenderItemInFrameEvent extends MutableEvent implements Cancel
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
return getPackedLight;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -22,8 +21,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
@@ -30,69 +30,27 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* This event (and items stacking on others in general) is fired on both {@linkplain LogicalSide sides}, but only on {@linkplain LogicalSide#CLIENT the client} in the creative menu.
|
||||
* Practically, that means that listeners of this event should require the player to be in survival mode if using capabilities that are not synced.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* This event is {@linkplain Cancellable cancellable}.
|
||||
* 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.
|
||||
*
|
||||
* @param getCarriedItem The stack being carried by the mouse, which may be empty
|
||||
* @param getStackedOnItem The stack currently in the slot being clicked on, which may be empty
|
||||
* @param getSlot The slot being clicked on
|
||||
* @param getClickAction The click action being used. By default, {@linkplain ClickAction#PRIMARY} corresponds to left-click, and {@linkplain ClickAction#SECONDARY} is right-click.
|
||||
* @param getPlayer The player doing the item swap attempt
|
||||
* @param getCarriedSlotAccess A fake slot allowing the listener to see and change what item is being carried
|
||||
*/
|
||||
public final class ItemStackedOnOtherEvent extends MutableEvent implements Cancellable {
|
||||
public record ItemStackedOnOtherEvent(
|
||||
ItemStack getCarriedItem,
|
||||
ItemStack getStackedOnItem,
|
||||
Slot getSlot,
|
||||
ClickAction getClickAction,
|
||||
Player getPlayer,
|
||||
SlotAccess getCarriedSlotAccess
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<ItemStackedOnOtherEvent> BUS = CancellableEventBus.create(ItemStackedOnOtherEvent.class);
|
||||
|
||||
private final ItemStack carriedItem;
|
||||
private final ItemStack stackedOnItem;
|
||||
private final Slot slot;
|
||||
private final ClickAction action;
|
||||
private final Player player;
|
||||
private final SlotAccess carriedSlotAccess;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ItemStackedOnOtherEvent(ItemStack carriedItem, ItemStack stackedOnItem, Slot slot, ClickAction action, Player player, SlotAccess carriedSlotAccess) {
|
||||
this.carriedItem = carriedItem;
|
||||
this.stackedOnItem = stackedOnItem;
|
||||
this.slot = slot;
|
||||
this.action = action;
|
||||
this.player = player;
|
||||
this.carriedSlotAccess = carriedSlotAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the stack being carried by the mouse} This may be empty!
|
||||
*/
|
||||
public ItemStack getCarriedItem() {
|
||||
return carriedItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the stack currently in the slot being clicked on} This may be empty!
|
||||
*/
|
||||
public ItemStack getStackedOnItem() {
|
||||
return stackedOnItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the slot being clicked on}
|
||||
*/
|
||||
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() {
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player doing the item swap attempt}
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a fake slot allowing the listener to see and change what item is being carried}
|
||||
*/
|
||||
public SlotAccess getCarriedSlotAccess() {
|
||||
return carriedSlotAccess;
|
||||
}
|
||||
public ItemStackedOnOtherEvent {}
|
||||
}
|
||||
@@ -8,8 +8,9 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,41 +18,19 @@ import java.util.List;
|
||||
* Fires when a player joins the server or when the reload command is ran,
|
||||
* before tags and crafting recipes are sent to the client. Send datapack data
|
||||
* to clients when this event fires.
|
||||
*
|
||||
* @param getPlayerList The server's player list to get a view of all players.
|
||||
* @param getPlayer The player to sync datapacks to. Null when syncing for all players, such as when the reload command runs.
|
||||
*/
|
||||
public final class OnDatapackSyncEvent extends MutableEvent {
|
||||
@NullMarked
|
||||
public record OnDatapackSyncEvent(PlayerList getPlayerList, @Nullable ServerPlayer getPlayer) implements RecordEvent {
|
||||
public static final EventBus<OnDatapackSyncEvent> BUS = EventBus.create(OnDatapackSyncEvent.class);
|
||||
|
||||
private final PlayerList playerList;
|
||||
|
||||
@Nullable
|
||||
private final ServerPlayer player;
|
||||
|
||||
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player) {
|
||||
this.playerList = playerList;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The server's player list to get a view of all players.
|
||||
*/
|
||||
public PlayerList getPlayerList() {
|
||||
return this.playerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The player to sync datapacks to. Null when syncing for all players,
|
||||
* such as when the reload command runs.
|
||||
*/
|
||||
@Nullable
|
||||
public ServerPlayer getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of players that should receive data during this event, which is the specified player (if not null)
|
||||
* or all players otherwise.
|
||||
*/
|
||||
public List<ServerPlayer> getPlayers() {
|
||||
return this.player == null ? this.playerList.getPlayers() : List.of(this.player);
|
||||
return getPlayer == null ? getPlayerList.getPlayers() : List.of(this.getPlayer);
|
||||
}
|
||||
}
|
||||
@@ -8,50 +8,24 @@ package net.minecraftforge.event;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* Commands are rebuilt whenever {@link ReloadableServerResources} is recreated.
|
||||
* You can use this event to register your commands whenever the {@link Commands} class in constructed.
|
||||
*
|
||||
* The event is fired on the {@link MinecraftForge#EVENT_BUS}
|
||||
* @param getDispatcher The command dispatcher for registering commands to be executed on the client
|
||||
* @param getCommandSelection The environment the command is being registered for
|
||||
* @param getBuildContext The context to build the commands for
|
||||
*/
|
||||
public final class RegisterCommandsEvent extends MutableEvent {
|
||||
public record RegisterCommandsEvent(
|
||||
CommandDispatcher<CommandSourceStack> getDispatcher,
|
||||
Commands.CommandSelection getCommandSelection,
|
||||
CommandBuildContext getBuildContext
|
||||
) implements RecordEvent {
|
||||
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) {
|
||||
this.dispatcher = dispatcher;
|
||||
this.environment = environment;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the command dispatcher for registering commands to be executed on the client}
|
||||
*/
|
||||
public CommandDispatcher<CommandSourceStack> getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the environment the command is being registered for}
|
||||
*/
|
||||
public Commands.CommandSelection getCommandSelection() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the context to build the commands for}
|
||||
*/
|
||||
public CommandBuildContext getBuildContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
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.Nullable;
|
||||
|
||||
@@ -20,58 +19,26 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <br>
|
||||
* This allows for listening to Vanilla's events in a more structured and global way that is not tied to needing a block entity listener. <br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}. <br>
|
||||
* <br>
|
||||
* Cancel this event to prevent Vanilla from posting the {@link GameEvent} to all nearby {@link net.minecraft.world.level.gameevent.GameEventListener GameEventListeners}.
|
||||
*
|
||||
* @param getLevel The level the Vanilla {@link GameEvent} occurred in
|
||||
* @param getVanillaEvent The Vanilla event
|
||||
* @param getEventPosition The position the event took place at
|
||||
* @param getContext The context of the Vanilla event
|
||||
**/
|
||||
public final class VanillaGameEvent extends MutableEvent implements Cancellable {
|
||||
public record VanillaGameEvent(
|
||||
Level getLevel,
|
||||
GameEvent getVanillaEvent,
|
||||
Vec3 getEventPosition,
|
||||
GameEvent.Context getContext
|
||||
) implements Cancellable, RecordEvent {
|
||||
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) {
|
||||
this.level = level;
|
||||
this.vanillaEvent = vanillaEvent;
|
||||
this.position = position;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The level the Vanilla {@link GameEvent} occurred.
|
||||
*/
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The entity that was the source or "cause" of the {@link GameEvent}.
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getCause() {
|
||||
return context.sourceEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Vanilla event.
|
||||
*/
|
||||
public GameEvent getVanillaEvent() {
|
||||
return vanillaEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position the event took place at.
|
||||
*/
|
||||
public Vec3 getEventPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context of the vanilla event
|
||||
*/
|
||||
public GameEvent.Context getContext() {
|
||||
return context;
|
||||
return getContext.sourceEntity();
|
||||
}
|
||||
}
|
||||
+10
-22
@@ -11,40 +11,28 @@ import java.util.Set;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* Fired when the channel registration (see minecraft custom channel documentation) changes.
|
||||
* <br>
|
||||
* It seems plausible that this will fire multiple times for the same state, depending on what the server is doing.
|
||||
* It just directly dispatches upon receipt.
|
||||
*
|
||||
* @param getType The type of change, either {@link Type#REGISTER} or {@link Type#UNREGISTER}
|
||||
*/
|
||||
public final class ChannelRegistrationChangeEvent extends MutableEvent {
|
||||
public record ChannelRegistrationChangeEvent(
|
||||
Connection getSource,
|
||||
Type getType,
|
||||
Set<ResourceLocation> getChannels
|
||||
) implements RecordEvent {
|
||||
public static final EventBus<ChannelRegistrationChangeEvent> BUS = EventBus.create(ChannelRegistrationChangeEvent.class);
|
||||
|
||||
public enum Type {
|
||||
REGISTER, UNREGISTER
|
||||
}
|
||||
|
||||
private final Connection source;
|
||||
private final Type changeType;
|
||||
private final Set<ResourceLocation> channels;
|
||||
|
||||
public ChannelRegistrationChangeEvent(Connection source, Type changeType, Set<ResourceLocation> channels) {
|
||||
this.source = source;
|
||||
this.changeType = changeType;
|
||||
this.channels = Collections.unmodifiableSet(channels);
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return changeType;
|
||||
}
|
||||
|
||||
public Connection getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getChannels() {
|
||||
return channels;
|
||||
public ChannelRegistrationChangeEvent {
|
||||
getChannels = Collections.unmodifiableSet(getChannels);
|
||||
}
|
||||
}
|
||||
@@ -10,43 +10,20 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.entity.ai.village.VillageSiege;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* VillageSiegeEvent is fired just before a zombie siege finds a successful location in
|
||||
* {@code VillageSiege#tryToSetupSiege(ServerLevel)}, to give mods the chance to stop the siege.<br>
|
||||
* <br>
|
||||
* Canceling this event stops the siege.<br>
|
||||
* Cancelling this event stops the siege.<br>
|
||||
*/
|
||||
public final class VillageSiegeEvent extends MutableEvent implements Cancellable {
|
||||
public record VillageSiegeEvent(
|
||||
VillageSiege getSiege,
|
||||
Level getLevel,
|
||||
Player getPlayer,
|
||||
Vec3 getAttemptedSpawnPos
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<VillageSiegeEvent> BUS = CancellableEventBus.create(VillageSiegeEvent.class);
|
||||
|
||||
private final VillageSiege siege;
|
||||
private final Level level;
|
||||
private final Player player;
|
||||
private final Vec3 attemptedSpawnPos;
|
||||
|
||||
public VillageSiegeEvent(VillageSiege siege, Level level, Player player, Vec3 attemptedSpawnPos) {
|
||||
this.siege = siege;
|
||||
this.level = level;
|
||||
this.player = player;
|
||||
this.attemptedSpawnPos = attemptedSpawnPos;
|
||||
}
|
||||
|
||||
public VillageSiege getSiege() {
|
||||
return siege;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Vec3 getAttemptedSpawnPos() {
|
||||
return attemptedSpawnPos;
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ package net.minecraftforge.registries;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -55,7 +55,7 @@ public final class IdMappingEvent extends MutableEvent {
|
||||
this.isFrozen = isFrozen;
|
||||
this.remaps = Maps.newHashMap();
|
||||
remaps.forEach((name, rm) -> {
|
||||
List<ModRemapping> tmp = Lists.newArrayList();
|
||||
List<ModRemapping> tmp = new ArrayList<>();
|
||||
rm.forEach((key, value) -> tmp.add(new ModRemapping(name, key, value.currId, value.newId)));
|
||||
tmp.sort(Comparator.comparingInt(o -> o.newId));
|
||||
this.remaps.put(name, ImmutableList.copyOf(tmp));
|
||||
|
||||
Reference in new issue
Block a user