mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Minecraft 1.21.9 update.
There a lot of performance improvements related to events. No more InheritableEvent for abstract events that you shouldn't add listeners to anyway, like EntityEvent. Use their sub-events. Made a lot more events records and interfaces. Mostly just a binary break, but has better performance. Mod bus posting methods are now static, no more ModLoader.get() for those. ObjectHolder was removed, use RegistryObject. Changed RuntimeEnumExtender to only target Minecraft classes. If you want other modders to interact with your API, use an Interface instead of Enum. Moved some abstract event methods to only the relevant sub-events now, e.g. can no longer check the side of a ClientTickEvent, because it'll always be client Rendering has changed a lot, they now batch most things together so that the game will render faster. RenderHighlightEvent changed a lot See https://github.com/MinecraftForge/MinecraftForge-Experimental/tree/1.21.9-dev for unsquashed commits. Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
490 files changed
+4601
-6528
No files matched your search
@@ -57,7 +57,7 @@ public class ClientCommandSourceStack extends CommandSourceStack {
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getOnlinePlayerNames() {
|
||||
return Minecraft.getInstance().getConnection().getOnlinePlayers().stream().map((player) -> player.getProfile().getName()).collect(Collectors.toList());
|
||||
return Minecraft.getInstance().getConnection().getOnlinePlayers().stream().map((player) -> player.getProfile().name()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class ColorResolverManager {
|
||||
@ApiStatus.Internal
|
||||
public static void init() {
|
||||
var builder = new ArrayList<ColorResolver>();
|
||||
ModLoader.get().postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder));
|
||||
ModLoader.postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder));
|
||||
colorResolvers = List.copyOf(builder);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class DimensionSpecialEffectsManager {
|
||||
var effects = new HashMap<ResourceLocation, DimensionSpecialEffects>();
|
||||
DEFAULT_EFFECTS = preRegisterVanillaEffects(effects);
|
||||
var event = new RegisterDimensionSpecialEffectsEvent(effects);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
EFFECTS = Map.copyOf(effects);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class EntitySpectatorShaderManager {
|
||||
public static void init() {
|
||||
var shaders = new HashMap<EntityType<?>, ResourceLocation>();
|
||||
var event = new RegisterEntitySpectatorShadersEvent(shaders);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
SHADERS = Map.copyOf(shaders);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,9 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.input.CharacterEvent;
|
||||
import net.minecraft.client.input.KeyEvent;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.model.Model;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
@@ -42,13 +45,16 @@ import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.particle.ParticleRenderType;
|
||||
import net.minecraft.client.particle.ParticleResources;
|
||||
import net.minecraft.client.player.ClientInput;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
|
||||
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
|
||||
import net.minecraft.client.renderer.fog.FogData;
|
||||
import net.minecraft.client.renderer.state.LevelRenderState;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -62,6 +68,7 @@ import net.minecraft.client.resources.model.UnbakedGeometry;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.data.AtlasIds;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
@@ -71,6 +78,7 @@ import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.metadata.MetadataSectionType;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
@@ -103,6 +111,7 @@ import net.minecraftforge.client.event.SystemMessageReceivedEvent;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.client.event.ForgeEventFactoryClient;
|
||||
import net.minecraftforge.client.event.GatherAtlasMetadataSectionsEvent;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.ModelEvent;
|
||||
import net.minecraftforge.client.event.MovementInputUpdateEvent;
|
||||
@@ -160,6 +169,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -237,29 +247,33 @@ public class ForgeHooksClient {
|
||||
}
|
||||
*/
|
||||
|
||||
public static boolean onDrawHighlight(LevelRenderer context, Camera camera, HitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource) {
|
||||
switch (target.getType()) {
|
||||
case BLOCK:
|
||||
if (!(target instanceof BlockHitResult blockTarget)) return false;
|
||||
return RenderHighlightEvent.Block.BUS.post(new RenderHighlightEvent.Block(context, camera, blockTarget, partialTick, poseStack, bufferSource));
|
||||
case ENTITY:
|
||||
if (!(target instanceof EntityHitResult entityTarget)) return false;
|
||||
return RenderHighlightEvent.Entity.BUS.post(new RenderHighlightEvent.Entity(context, camera, entityTarget, partialTick, poseStack, bufferSource));
|
||||
default:
|
||||
return false; // NO-OP - This doesn't even get called for anything other than blocks and entities
|
||||
private static final RenderHighlightEvent.Callback NOOP_HIGHLIGHTER = (source, stack, translucent, state) -> { };
|
||||
|
||||
public static RenderHighlightEvent.Callback onExtractBlockOutline(LevelRenderer context, Camera camera, LevelRenderState state, HitResult target) {
|
||||
if (target instanceof BlockHitResult blockTarget) {
|
||||
var event = new RenderHighlightEvent.Block(context, camera, state, blockTarget);
|
||||
if (RenderHighlightEvent.Block.BUS.post(event))
|
||||
return NOOP_HIGHLIGHTER;
|
||||
return event.getCustomRenderer();
|
||||
} else if (target instanceof EntityHitResult entityTarget) {
|
||||
var event = new RenderHighlightEvent.Entity(context, camera, state, entityTarget);
|
||||
if (RenderHighlightEvent.Entity.BUS.post(event))
|
||||
return NOOP_HIGHLIGHTER;
|
||||
return event.getCustomRenderer();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean renderSpecificFirstPersonHand(InteractionHand hand, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, float partialTick, float interpPitch, float swingProgress, float equipProgress, ItemStack stack) {
|
||||
return RenderHandEvent.BUS.post(new RenderHandEvent(hand, poseStack, bufferSource, packedLight, partialTick, interpPitch, swingProgress, equipProgress, stack));
|
||||
public static boolean renderSpecificFirstPersonHand(InteractionHand hand, PoseStack poseStack, SubmitNodeCollector nodeCollector, int packedLight, float partialTick, float interpPitch, float swingProgress, float equipProgress, ItemStack stack) {
|
||||
return RenderHandEvent.BUS.post(new RenderHandEvent(hand, poseStack, nodeCollector, packedLight, partialTick, interpPitch, swingProgress, equipProgress, stack));
|
||||
}
|
||||
|
||||
public static void onTextureStitchedPost(TextureAtlas map) {
|
||||
ModLoader.get().postEvent(new TextureStitchEvent.Post(map));
|
||||
ModLoader.postEvent(new TextureStitchEvent.Post(map));
|
||||
}
|
||||
|
||||
public static void onBlockColorsInit(BlockColors blockColors) {
|
||||
ModLoader.get().postEvent(new RegisterColorHandlersEvent.Block(blockColors));
|
||||
ModLoader.postEvent(new RegisterColorHandlersEvent.Block(blockColors));
|
||||
}
|
||||
|
||||
public static Model getArmorModel(HumanoidRenderState state, ItemStack itemStack, EquipmentSlot slot, HumanoidModel<?> _default) {
|
||||
@@ -267,6 +281,7 @@ public class ForgeHooksClient {
|
||||
}
|
||||
|
||||
/** Copies humanoid model properties from the original model to another, used for armor models */
|
||||
/* Mojang removied copying in 1.21.9
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends HumanoidRenderState> void copyModelProperties(HumanoidModel<T> original, HumanoidModel<?> replacement) {
|
||||
// this function does not make use of the <T> generic, so the unchecked cast should be safe
|
||||
@@ -279,6 +294,7 @@ public class ForgeHooksClient {
|
||||
replacement.rightLeg.visible = original.rightLeg.visible;
|
||||
replacement.leftLeg.visible = original.leftLeg.visible;
|
||||
}
|
||||
*/
|
||||
|
||||
//This properly moves the domain, if provided, to the front of the string before concatenating
|
||||
public static String fixDomain(String base, String complex) {
|
||||
@@ -315,7 +331,7 @@ public class ForgeHooksClient {
|
||||
|
||||
private static void drawScreenInternal(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
if (!ScreenEvent.Render.Pre.BUS.post(new ScreenEvent.Render.Pre(screen, guiGraphics, mouseX, mouseY, partialTick)))
|
||||
screen.renderWithTooltip(guiGraphics, mouseX, mouseY, partialTick);
|
||||
screen.renderWithTooltipAndSubtitles(guiGraphics, mouseX, mouseY, partialTick);
|
||||
ScreenEvent.Render.Post.BUS.post(new ScreenEvent.Render.Post(screen, guiGraphics, mouseX, mouseY, partialTick));
|
||||
}
|
||||
|
||||
@@ -343,23 +359,21 @@ public class ForgeHooksClient {
|
||||
}
|
||||
|
||||
public static void onModifyBakingResult(ModelBakery modelBakery, ModelBakery.BakingResult results) {
|
||||
ModLoader.get().postEvent(new ModelEvent.ModifyBakingResult(modelBakery, results));
|
||||
ModLoader.postEvent(new ModelEvent.ModifyBakingResult(modelBakery, results));
|
||||
}
|
||||
|
||||
public static void onModelBake(ModelManager modelManager, ModelBakery modelBakery) {
|
||||
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, modelBakery));
|
||||
ModLoader.postEvent(new ModelEvent.BakingCompleted(modelManager, modelBakery));
|
||||
}
|
||||
|
||||
public static TextureAtlasSprite[] getFluidSprites(BlockAndTintGetter level, BlockPos pos, FluidState fluidStateIn) {
|
||||
IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluidStateIn);
|
||||
ResourceLocation overlayTexture = props.getOverlayTexture(fluidStateIn, level, pos);
|
||||
@SuppressWarnings("deprecation")
|
||||
var BLOCKS = TextureAtlas.LOCATION_BLOCKS;
|
||||
var atlas = Minecraft.getInstance().getTextureAtlas(BLOCKS);
|
||||
var atlas = Minecraft.getInstance().getAtlasManager().getAtlasOrThrow(AtlasIds.BLOCKS);
|
||||
return new TextureAtlasSprite[] {
|
||||
atlas.apply(props.getStillTexture(fluidStateIn, level, pos)),
|
||||
atlas.apply(props.getFlowingTexture(fluidStateIn, level, pos)),
|
||||
overlayTexture == null ? null : atlas.apply(overlayTexture),
|
||||
atlas.getSprite(props.getStillTexture(fluidStateIn, level, pos)),
|
||||
atlas.getSprite(props.getFlowingTexture(fluidStateIn, level, pos)),
|
||||
overlayTexture == null ? null : atlas.getSprite(overlayTexture),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -413,26 +427,26 @@ public class ForgeHooksClient {
|
||||
MovementInputUpdateEvent.BUS.post(new MovementInputUpdateEvent(player, movementInput));
|
||||
}
|
||||
|
||||
public static boolean onScreenKeyPressed(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
return ForgeEventFactoryClient.onScreenKeyPressedPre(screen, keyCode, scanCode, modifiers)
|
||||
|| screen.keyPressed(keyCode, scanCode, modifiers)
|
||||
|| ForgeEventFactoryClient.onScreenKeyPressedPost(screen, keyCode, scanCode, modifiers);
|
||||
public static boolean onScreenKeyPressed(Screen screen, KeyEvent info) {
|
||||
return ForgeEventFactoryClient.onScreenKeyPressedPre(screen, info.key(), info.scancode(), info.modifiers())
|
||||
|| screen.keyPressed(info)
|
||||
|| ForgeEventFactoryClient.onScreenKeyPressedPost(screen, info.key(), info.scancode(), info.modifiers());
|
||||
}
|
||||
|
||||
public static boolean onScreenKeyReleased(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
return ForgeEventFactoryClient.onScreenKeyReleasedPre(screen, keyCode, scanCode, modifiers)
|
||||
|| screen.keyReleased(keyCode, scanCode, modifiers)
|
||||
|| ForgeEventFactoryClient.onScreenKeyReleasedPost(screen, keyCode, scanCode, modifiers);
|
||||
public static boolean onScreenKeyReleased(Screen screen, KeyEvent info) {
|
||||
return ForgeEventFactoryClient.onScreenKeyReleasedPre(screen, info.key(), info.scancode(), info.modifiers())
|
||||
|| screen.keyReleased(info)
|
||||
|| ForgeEventFactoryClient.onScreenKeyReleasedPost(screen, info.key(), info.scancode(), info.modifiers());
|
||||
}
|
||||
|
||||
public static boolean onScreenCharTyped(Screen screen, char codePoint, int modifiers) {
|
||||
return ForgeEventFactoryClient.onScreenCharTypedPre(screen, codePoint, modifiers)
|
||||
|| screen.charTyped(codePoint, modifiers)
|
||||
|| ForgeEventFactoryClient.onScreenCharTypedPost(screen, codePoint, modifiers);
|
||||
public static boolean onScreenCharTyped(Screen screen, CharacterEvent info) {
|
||||
return ForgeEventFactoryClient.onScreenCharTypedPre(screen, (char)info.codepoint(), info.modifiers())
|
||||
|| screen.charTyped(info)
|
||||
|| ForgeEventFactoryClient.onScreenCharTypedPost(screen, (char)info.codepoint(), info.modifiers());
|
||||
}
|
||||
|
||||
public static void onKeyInput(int key, int scanCode, int action, int modifiers) {
|
||||
InputEvent.Key.BUS.post(new InputEvent.Key(key, scanCode, action, modifiers));
|
||||
public static void onKeyInput(KeyEvent info, int action) {
|
||||
InputEvent.Key.BUS.post(new InputEvent.Key(info.key(), info.scancode(), action, info.modifiers()));
|
||||
}
|
||||
|
||||
public static boolean isNameplateInRenderDistance(Entity entity, double squareDistance) {
|
||||
@@ -449,24 +463,32 @@ public class ForgeHooksClient {
|
||||
return IClientMobEffectExtensions.of(effectInstance).isVisibleInInventory(effectInstance);
|
||||
}
|
||||
|
||||
public static Set<MetadataSectionType<?>> getAtlastMetadataSections(ResourceLocation atlasId, Set<MetadataSectionType<?>> vanilla) {
|
||||
var ret = new HashSet<>(vanilla);
|
||||
ret.add(ForgeTextureMetadata.TYPE);
|
||||
|
||||
var event = new GatherAtlasMetadataSectionsEvent(ret);
|
||||
GatherAtlasMetadataSectionsEvent.BUS.post(event);
|
||||
return Set.of(ret.toArray(new MetadataSectionType<?>[0]));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SpriteContents loadSpriteContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, ResourceMetadata animationMeta) {
|
||||
try {
|
||||
ForgeTextureMetadata forgeMeta = ForgeTextureMetadata.forResource(resource);
|
||||
return forgeMeta.loader() == null ? null : forgeMeta.loader().loadContents(name, resource, frameSize, image, animationMeta, forgeMeta);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Unable to get Forge metadata for {}, falling back to vanilla loading", name);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
public static SpriteContents loadSpriteContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, List<MetadataSectionType.WithValue<?>> metadata) {
|
||||
for (var meta : metadata) {
|
||||
var forgeMeta = meta.unwrapToType(ForgeTextureMetadata.TYPE).orElse(null);
|
||||
if (forgeMeta != null && forgeMeta.loader() != null)
|
||||
return forgeMeta.loader().loadContents(name, resource, frameSize, image, metadata);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextureAtlasSprite loadTextureAtlasSprite(ResourceLocation atlasName, SpriteContents contents, int atlasWidth, int atlasHeight, int spriteX, int spriteY, int mipmapLevel) {
|
||||
if (contents.forgeMeta == null || contents.forgeMeta.loader() == null)
|
||||
var forgeMeta = contents.getAdditionalMetadata(ForgeTextureMetadata.TYPE).orElse(null);
|
||||
if (forgeMeta == null || forgeMeta.loader() == null)
|
||||
return null;
|
||||
|
||||
return contents.forgeMeta.loader().makeSprite(atlasName, contents, atlasWidth, atlasHeight, spriteX, spriteY, mipmapLevel);
|
||||
return forgeMeta.loader().makeSprite(atlasName, contents, atlasWidth, atlasHeight, spriteX, spriteY, mipmapLevel);
|
||||
}
|
||||
|
||||
private static final Map<ModelLayerLocation, Supplier<LayerDefinition>> layerDefinitions = new HashMap<>();
|
||||
@@ -592,12 +614,12 @@ public class ForgeHooksClient {
|
||||
GameData.revertToFrozen();
|
||||
}
|
||||
|
||||
public static void onRegisterParticleProviders(ParticleEngine particleEngine) {
|
||||
ModLoader.get().postEvent(new RegisterParticleProvidersEvent(particleEngine));
|
||||
public static void onRegisterParticleProviders(ParticleResources particles) {
|
||||
ModLoader.postEvent(new RegisterParticleProvidersEvent(particles));
|
||||
}
|
||||
|
||||
public static void onRegisterKeyMappings(Options options) {
|
||||
ModLoader.get().postEvent(new RegisterKeyMappingsEvent(options));
|
||||
ModLoader.postEvent(new RegisterKeyMappingsEvent(options));
|
||||
}
|
||||
|
||||
public static void onRegisterPictureInPictureRenderers(List<PictureInPictureRenderer<?>> renderers,
|
||||
@@ -777,9 +799,9 @@ public class ForgeHooksClient {
|
||||
throw new IllegalStateException("Client hooks initialized more than once");
|
||||
initializedClientHooks = true;
|
||||
|
||||
ModLoader.get().postEvent(new RegisterClientReloadListenersEvent(resourceManager));
|
||||
ModLoader.get().postEvent(new EntityRenderersEvent.RegisterLayerDefinitions());
|
||||
ModLoader.get().postEvent(new EntityRenderersEvent.RegisterRenderers());
|
||||
ModLoader.postEvent(new RegisterClientReloadListenersEvent(resourceManager));
|
||||
ModLoader.postEvent(new EntityRenderersEvent.RegisterLayerDefinitions());
|
||||
ModLoader.postEvent(new EntityRenderersEvent.RegisterRenderers());
|
||||
TextureAtlasSpriteLoaderManager.init();
|
||||
ClientTooltipComponentManager.init();
|
||||
EntitySpectatorShaderManager.init();
|
||||
@@ -800,10 +822,10 @@ public class ForgeHooksClient {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseDrag(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
return ForgeEventFactoryClient.onScreenMouseDragPre(screen, mouseX, mouseY, mouseButton, dragX, dragY)
|
||||
|| screen.mouseDragged(mouseX, mouseY, mouseButton, dragX, dragY)
|
||||
|| ForgeEventFactoryClient.onScreenMouseDragPost(screen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
public static boolean onScreenMouseDrag(Screen screen, MouseButtonEvent info, double dragX, double dragY) {
|
||||
return ForgeEventFactoryClient.onScreenMouseDragPre(screen, info.x(), info.y(), info.button(), dragX, dragY)
|
||||
|| screen.mouseDragged(info, dragX, dragY)
|
||||
|| ForgeEventFactoryClient.onScreenMouseDragPost(screen, info.x(), info.y(), info.button(), dragX, dragY);
|
||||
}
|
||||
|
||||
public static @Nullable UnbakedGeometry deserializeBlockModelGeometry(JsonObject json, JsonDeserializationContext context) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.mojang.blaze3d.textures.TextureFormat;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import net.minecraft.client.renderer.RenderStateShard.TextureStateShard;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
@@ -42,8 +41,7 @@ public enum ForgeRenderTypes {
|
||||
ITEM_LAYERED_TRANSLUCENT(()-> getItemLayeredTranslucent(blockAtlas())),
|
||||
ITEM_UNSORTED_TRANSLUCENT(()-> getUnsortedTranslucent(blockAtlas())),
|
||||
ITEM_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(blockAtlas())),
|
||||
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(blockAtlas(), false)),
|
||||
TRANSLUCENT_ON_PARTICLES_TARGET(() -> getTranslucentParticlesTarget(blockAtlas()));
|
||||
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(blockAtlas(), false));
|
||||
|
||||
/**
|
||||
* Controls the texture filtering state for certain {@link RenderType Render Types}.
|
||||
@@ -175,16 +173,6 @@ public enum ForgeRenderTypes {
|
||||
return Internal.TEXT_INTENSITY_SEE_THROUGH.apply(locationIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #enableTextTextureLinearFiltering
|
||||
*
|
||||
* @return A variation of {@link RenderType#translucent()} that uses {@link RenderStateShard.OutputStateShard#PARTICLES_TARGET}
|
||||
*/
|
||||
public static RenderType getTranslucentParticlesTarget(ResourceLocation locationIn) {
|
||||
return Internal.TRANSLUCENT_PARTICLES_TARGET.apply(locationIn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render type for rendering the early loading screen, not for modder consumption.
|
||||
*
|
||||
@@ -428,22 +416,6 @@ public enum ForgeRenderTypes {
|
||||
);
|
||||
}
|
||||
|
||||
public static Function<ResourceLocation, RenderType> TRANSLUCENT_PARTICLES_TARGET = Util.memoize(Internal::getTranslucentParticlesTarget);
|
||||
private static RenderType getTranslucentParticlesTarget(ResourceLocation locationIn) {
|
||||
return create(
|
||||
"forge_translucent_particles_target",
|
||||
TRANSIENT_BUFFER_SIZE,
|
||||
true,
|
||||
true,
|
||||
RenderPipelines.TRANSLUCENT_PARTICLE,
|
||||
CompositeState.builder()
|
||||
.setTextureState(new TextureStateShard(locationIn, false))
|
||||
.setOutputState(PARTICLES_TARGET)
|
||||
.setLightmapState(LIGHTMAP)
|
||||
.createCompositeState(true)
|
||||
);
|
||||
}
|
||||
|
||||
private static final RenderPipeline LOADING_PIPELINE = RenderPipeline.builder(RenderPipelines.GUI_TEXTURED_SNIPPET)
|
||||
.withLocation("pipeline/forge/loading_overlay")
|
||||
.withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE))
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class ItemDecoratorHandler {
|
||||
public static void init() {
|
||||
var decorators = new HashMap<Item, List<IItemDecorator>>();
|
||||
var event = new RegisterItemDecorationsEvent(decorators);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
var builder = new ImmutableMap.Builder<Item, ItemDecoratorHandler>();
|
||||
for (var entry : decorators.entrySet()) {
|
||||
Item item = entry.getKey();
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class NamedRenderTypeManager {
|
||||
var renderTypes = new HashMap<ResourceLocation, RenderTypeGroup>();
|
||||
preRegisterVanillaRenderTypes(renderTypes);
|
||||
var event = new RegisterNamedRenderTypesEvent(renderTypes);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
RENDER_TYPES = ImmutableMap.copyOf(renderTypes);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class PresetEditorManager {
|
||||
|
||||
// Gather mods' entries
|
||||
RegisterPresetEditorsEvent event = new RegisterPresetEditorsEvent(gatheredEditors);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
|
||||
editors = Map.copyOf(gatheredEditors);
|
||||
}
|
||||
|
||||
@@ -18,17 +18,22 @@ import org.jspecify.annotations.NullMarked;
|
||||
* Fired when the {@linkplain ForgeLayeredDraw#VANILLA_ROOT}'s order is resolved during{@link ForgeLayeredDraw#resolveLayers().
|
||||
* This can be used to add additional or move gui layers and entire layer stacks as needed.
|
||||
*
|
||||
* <p> This event is fired on the {@linkplain IModBusEvent mod event bus},
|
||||
* only on the {@linkplain net.minecraftforge.fml.LogicalSide logical client}.</p>
|
||||
* <p>This event is fired only on the {@linkplain net.minecraftforge.fml.LogicalSide logical client}.</p>
|
||||
*
|
||||
* @param getLayedDraw The provided {@linkplain ForgeLayeredDraw#instance}. By default will be {@linkplain ForgeLayeredDraw#VANILLA_ROOT}.
|
||||
*/
|
||||
@NullMarked
|
||||
public record AddGuiOverlayLayersEvent(ForgeLayeredDraw getLayeredDraw) implements IModBusEvent, SelfDestructing, RecordEvent {
|
||||
public record AddGuiOverlayLayersEvent(ForgeLayeredDraw getLayeredDraw) implements SelfDestructing, RecordEvent {
|
||||
public static final EventBus<AddGuiOverlayLayersEvent> BUS = EventBus.create(AddGuiOverlayLayersEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public AddGuiOverlayLayersEvent {}
|
||||
|
||||
/**
|
||||
* @deprecated {@link AddGuiOverlayLayersEvent} is no longer an {@link IModBusEvent}, so use {@link #BUS} directly.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.9")
|
||||
public static EventBus<AddGuiOverlayLayersEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, AddGuiOverlayLayersEvent.class);
|
||||
return BUS;
|
||||
}
|
||||
}
|
||||
@@ -5,71 +5,48 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
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 net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when pause is about to change
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* <p>These events are fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @see ClientPauseChangeEvent.Pre
|
||||
* @see ClientPauseChangeEvent.Post
|
||||
*/
|
||||
public abstract sealed class ClientPauseChangeEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<ClientPauseChangeEvent> BUS = EventBus.create(ClientPauseChangeEvent.class);
|
||||
public sealed interface ClientPauseChangeEvent extends InheritableEvent {
|
||||
EventBus<ClientPauseChangeEvent> BUS = EventBus.create(ClientPauseChangeEvent.class);
|
||||
|
||||
private final boolean pause;
|
||||
|
||||
public ClientPauseChangeEvent(boolean pause) {
|
||||
this.pause = pause;
|
||||
}
|
||||
/**
|
||||
* {@return whether the game is paused}
|
||||
*/
|
||||
boolean isPaused();
|
||||
|
||||
/**
|
||||
* Fired when {@linkplain Minecraft#pause pause} is going to change
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.</p>
|
||||
* Cancelling this event will prevent the game change pause state even if the conditions match
|
||||
*
|
||||
* <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>
|
||||
*/
|
||||
public static final class Pre extends ClientPauseChangeEvent implements Cancellable {
|
||||
record Pre(boolean isPaused) implements Cancellable, RecordEvent, ClientPauseChangeEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
public Pre(boolean pause) {
|
||||
super(pause);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when {@linkplain Minecraft#pause pause} is already changed
|
||||
*
|
||||
* <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 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>
|
||||
*/
|
||||
public static final class Post extends ClientPauseChangeEvent {
|
||||
record Post(boolean isPaused) implements RecordEvent, ClientPauseChangeEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(boolean pause) {
|
||||
super(pause);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return game is paused}
|
||||
*/
|
||||
public boolean isPaused() {
|
||||
return pause;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@ import net.minecraft.network.Connection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Fired for different client connectivity events.
|
||||
@@ -27,75 +27,57 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @see LoggingOut
|
||||
* @see Clone
|
||||
**/
|
||||
public abstract sealed class ClientPlayerNetworkEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<ClientPlayerNetworkEvent> BUS = EventBus.create(ClientPlayerNetworkEvent.class);
|
||||
|
||||
private final MultiPlayerGameMode multiPlayerGameMode;
|
||||
private final LocalPlayer player;
|
||||
private final Connection connection;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected ClientPlayerNetworkEvent(final MultiPlayerGameMode multiPlayerGameMode, final LocalPlayer player, final Connection connection) {
|
||||
this.multiPlayerGameMode = multiPlayerGameMode;
|
||||
this.player = player;
|
||||
this.connection = connection;
|
||||
}
|
||||
public sealed interface ClientPlayerNetworkEvent extends InheritableEvent {
|
||||
EventBus<ClientPlayerNetworkEvent> BUS = EventBus.create(ClientPlayerNetworkEvent.class);
|
||||
|
||||
/**
|
||||
* {@return the multiplayer game mode controller for the player}
|
||||
*/
|
||||
public MultiPlayerGameMode getMultiPlayerGameMode() {
|
||||
return multiPlayerGameMode;
|
||||
}
|
||||
MultiPlayerGameMode getMultiPlayerGameMode();
|
||||
|
||||
/**
|
||||
* {@return the player instance}
|
||||
*/
|
||||
public LocalPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
LocalPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* {@return the network connection for the player}
|
||||
*/
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
Connection getConnection();
|
||||
|
||||
/**
|
||||
* Fired when the client player logs in to the server. The player should be initialized.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class LoggingIn extends ClientPlayerNetworkEvent {
|
||||
@NullMarked
|
||||
record LoggingIn(MultiPlayerGameMode getMultiPlayerGameMode, LocalPlayer getPlayer, Connection getConnection)
|
||||
implements ClientPlayerNetworkEvent {
|
||||
public static final EventBus<LoggingIn> BUS = EventBus.create(LoggingIn.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LoggingIn(final MultiPlayerGameMode controller, final LocalPlayer player, final Connection networkManager) {
|
||||
super(controller, player, networkManager);
|
||||
}
|
||||
public LoggingIn {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the client player logs out. This event may also fire when a new integrated server is being created.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
// Shush IntelliJ, we override non-nullables as nullables in this specific event; see later comment
|
||||
public static final class LoggingOut extends ClientPlayerNetworkEvent {
|
||||
record LoggingOut(
|
||||
@Nullable MultiPlayerGameMode getMultiPlayerGameMode,
|
||||
@Nullable LocalPlayer getPlayer,
|
||||
@Nullable Connection getConnection
|
||||
) implements ClientPlayerNetworkEvent {
|
||||
public static final EventBus<LoggingOut> BUS = EventBus.create(LoggingOut.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LoggingOut(@Nullable final MultiPlayerGameMode controller, @Nullable final LocalPlayer player, @Nullable final Connection networkManager) {
|
||||
public LoggingOut {
|
||||
//noinspection ConstantConditions we know these are nullable, but we don't want to annotate the super as nullable since this is the only event with nullables
|
||||
super(controller, player, networkManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +88,7 @@ public abstract sealed class ClientPlayerNetworkEvent extends MutableEvent imple
|
||||
@Nullable
|
||||
@Override
|
||||
public MultiPlayerGameMode getMultiPlayerGameMode() {
|
||||
return super.getMultiPlayerGameMode();
|
||||
return getMultiPlayerGameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +99,7 @@ public abstract sealed class ClientPlayerNetworkEvent extends MutableEvent imple
|
||||
@Nullable
|
||||
@Override
|
||||
public LocalPlayer getPlayer() {
|
||||
return super.getPlayer();
|
||||
return getPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,42 +110,30 @@ public abstract sealed class ClientPlayerNetworkEvent extends MutableEvent imple
|
||||
@Nullable
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return super.getConnection();
|
||||
return getConnection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the client player respawns, creating a new player instance to replace the old player instance.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getOldPlayer the previous player instance
|
||||
* @param getNewPlayer the newly created player instance
|
||||
*/
|
||||
public static final class Clone extends ClientPlayerNetworkEvent {
|
||||
@NullMarked
|
||||
record Clone(
|
||||
MultiPlayerGameMode getMultiPlayerGameMode,
|
||||
LocalPlayer getOldPlayer,
|
||||
LocalPlayer getNewPlayer,
|
||||
Connection getConnection
|
||||
) implements ClientPlayerNetworkEvent {
|
||||
public static final EventBus<Clone> BUS = EventBus.create(Clone.class);
|
||||
|
||||
private final LocalPlayer oldPlayer;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Clone(final MultiPlayerGameMode pc, final LocalPlayer oldPlayer, final LocalPlayer newPlayer, final Connection networkManager) {
|
||||
super(pc, newPlayer, networkManager);
|
||||
this.oldPlayer = oldPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the previous player instance}
|
||||
*/
|
||||
public LocalPlayer getOldPlayer() {
|
||||
return oldPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the newly created player instance}
|
||||
*/
|
||||
public LocalPlayer getNewPlayer() {
|
||||
return super.getPlayer();
|
||||
}
|
||||
public Clone {}
|
||||
|
||||
/**
|
||||
* {@return the newly created player instance}
|
||||
@@ -172,7 +142,7 @@ public abstract sealed class ClientPlayerNetworkEvent extends MutableEvent imple
|
||||
*/
|
||||
@Override
|
||||
public LocalPlayer getPlayer() {
|
||||
return super.getPlayer();
|
||||
return getNewPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -24,22 +23,11 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* @see Render.Foreground
|
||||
* @see Render.Background
|
||||
*/
|
||||
public abstract sealed class ContainerScreenEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<ContainerScreenEvent> BUS = EventBus.create(ContainerScreenEvent.class);
|
||||
|
||||
private final AbstractContainerScreen<?> containerScreen;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected ContainerScreenEvent(AbstractContainerScreen<?> containerScreen) {
|
||||
this.containerScreen = containerScreen;
|
||||
}
|
||||
|
||||
public sealed interface ContainerScreenEvent {
|
||||
/**
|
||||
* {@return the container screen}
|
||||
*/
|
||||
public AbstractContainerScreen<?> getContainerScreen() {
|
||||
return containerScreen;
|
||||
}
|
||||
AbstractContainerScreen<?> getContainerScreen();
|
||||
|
||||
/**
|
||||
* Fired every time an {@link AbstractContainerScreen} renders.
|
||||
@@ -51,41 +39,21 @@ public abstract sealed class ContainerScreenEvent extends MutableEvent implement
|
||||
* @see Foreground
|
||||
* @see Background
|
||||
*/
|
||||
public static abstract sealed class Render extends ContainerScreenEvent {
|
||||
public static final EventBus<Render> BUS = EventBus.create(Render.class);
|
||||
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final int mouseX;
|
||||
private final int mouseY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected Render(AbstractContainerScreen<?> guiContainer, GuiGraphics guiGraphics, int mouseX, int mouseY) {
|
||||
super(guiContainer);
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
sealed interface Render extends ContainerScreenEvent {
|
||||
/**
|
||||
* {@return the gui graphics used for rendering}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
GuiGraphics getGuiGraphics();
|
||||
|
||||
/**
|
||||
* {@return the X coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
int getMouseX();
|
||||
|
||||
/**
|
||||
* {@return the Y coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
int getMouseY();
|
||||
|
||||
/**
|
||||
* Fired after the container screen's foreground layer and elements are drawn, but
|
||||
@@ -99,13 +67,16 @@ public abstract sealed class ContainerScreenEvent extends MutableEvent implement
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Foreground extends Render {
|
||||
record Foreground(
|
||||
AbstractContainerScreen<?> getContainerScreen,
|
||||
GuiGraphics getGuiGraphics,
|
||||
int getMouseX,
|
||||
int getMouseY
|
||||
) implements RecordEvent, Render {
|
||||
public static final EventBus<Foreground> BUS = EventBus.create(Foreground.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Foreground(AbstractContainerScreen<?> guiContainer, GuiGraphics guiGraphics, int mouseX, int mouseY) {
|
||||
super(guiContainer, guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
public Foreground {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,13 +88,16 @@ public abstract sealed class ContainerScreenEvent extends MutableEvent implement
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Background extends Render {
|
||||
record Background(
|
||||
AbstractContainerScreen<?> getContainerScreen,
|
||||
GuiGraphics getGuiGraphics,
|
||||
int getMouseX,
|
||||
int getMouseY
|
||||
) implements RecordEvent, Render {
|
||||
public static final EventBus<Background> BUS = EventBus.create(Background.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Background(AbstractContainerScreen<?> guiContainer, GuiGraphics guiGraphics, int mouseX, int mouseY) {
|
||||
super(guiContainer, guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
public Background {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,9 @@ import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
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;
|
||||
@@ -25,44 +26,28 @@ import java.util.List;
|
||||
* @see DebugText
|
||||
* @see Chat
|
||||
*/
|
||||
public abstract sealed class CustomizeGuiOverlayEvent extends MutableEvent implements Cancellable, InheritableEvent {
|
||||
public static final CancellableEventBus<CustomizeGuiOverlayEvent> BUS = CancellableEventBus.create(CustomizeGuiOverlayEvent.class);
|
||||
public sealed interface CustomizeGuiOverlayEvent {
|
||||
Window getWindow();
|
||||
|
||||
private final Window window;
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final float partialTick;
|
||||
GuiGraphics getGuiGraphics();
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected CustomizeGuiOverlayEvent(Window window, GuiGraphics guiGraphics, float partialTick) {
|
||||
this.window = window;
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.partialTick = partialTick;
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
float getPartialTick();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> a boss health bar is rendered to the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.
|
||||
* Cancelling this event will prevent the given bar from rendering.</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>
|
||||
*/
|
||||
public static final class BossEventProgress extends CustomizeGuiOverlayEvent {
|
||||
final class BossEventProgress implements Cancellable, CustomizeGuiOverlayEvent, RecordEvent {
|
||||
public static final CancellableEventBus<BossEventProgress> BUS = CancellableEventBus.create(BossEventProgress.class);
|
||||
|
||||
private final Window window;
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final float partialTick;
|
||||
private final LerpingBossEvent bossEvent;
|
||||
private final int x;
|
||||
private final int y;
|
||||
@@ -70,13 +55,30 @@ public abstract sealed class CustomizeGuiOverlayEvent extends MutableEvent imple
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BossEventProgress(Window window, GuiGraphics guiGraphics, float partialTick, LerpingBossEvent bossEvent, int x, int y, int increment) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.window = window;
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.partialTick = partialTick;
|
||||
this.bossEvent = bossEvent;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.increment = increment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the boss health bar currently being rendered
|
||||
*/
|
||||
@@ -119,38 +121,23 @@ public abstract sealed class CustomizeGuiOverlayEvent extends MutableEvent imple
|
||||
* Fired <b>before</b> textual information is rendered to the debug screen.
|
||||
* This can be used to add or remove text information.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getText the modifiable list of text to render on the side
|
||||
* @param getSide the side of the text getting rendered
|
||||
*/
|
||||
public static final class DebugText extends CustomizeGuiOverlayEvent {
|
||||
public static final CancellableEventBus<DebugText> BUS = CancellableEventBus.create(DebugText.class);
|
||||
|
||||
private final List<String> text;
|
||||
|
||||
private final Side side;
|
||||
record DebugText(
|
||||
Window getWindow,
|
||||
GuiGraphics getGuiGraphics,
|
||||
float getPartialTick,
|
||||
List<String> getText,
|
||||
Side getSide
|
||||
) implements RecordEvent, CustomizeGuiOverlayEvent {
|
||||
public static final EventBus<DebugText> BUS = EventBus.create(DebugText.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public DebugText(Window window, GuiGraphics guiGraphics, float partialTick, List<String> text, Side side) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.text = text;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the modifiable list of text to render on the side
|
||||
*/
|
||||
public List<String> getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the side of the text getting rendered.
|
||||
*/
|
||||
public Side getSide() {
|
||||
return this.side;
|
||||
}
|
||||
public DebugText {}
|
||||
|
||||
public enum Side {
|
||||
Left,
|
||||
@@ -161,24 +148,42 @@ public abstract sealed class CustomizeGuiOverlayEvent extends MutableEvent imple
|
||||
/**
|
||||
* Fired <b>before</b> the chat messages overlay is rendered to the screen.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Chat extends CustomizeGuiOverlayEvent {
|
||||
public static final CancellableEventBus<Chat> BUS = CancellableEventBus.create(Chat.class);
|
||||
final class Chat extends MutableEvent implements CustomizeGuiOverlayEvent {
|
||||
public static final EventBus<Chat> BUS = EventBus.create(Chat.class);
|
||||
|
||||
private final Window window;
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final float partialTick;
|
||||
private int posX;
|
||||
private int posY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Chat(Window window, GuiGraphics guiGraphics, float partialTick, int posX, int posY) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.window = window;
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.partialTick = partialTick;
|
||||
this.setPosX(posX);
|
||||
this.setPosY(posY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the X position of the chat messages overlay
|
||||
*/
|
||||
|
||||
@@ -6,24 +6,28 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.client.entity.ClientMannequin;
|
||||
import net.minecraft.client.model.SkullModel;
|
||||
import net.minecraft.client.model.SkullModelBase;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.client.renderer.entity.player.AvatarRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.resources.PlayerSkin;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.PlayerModelType;
|
||||
import net.minecraft.world.level.block.SkullBlock;
|
||||
import net.minecraft.world.level.block.SkullBlock.Type;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -118,7 +122,7 @@ public abstract sealed class EntityRenderersEvent implements IModBusEvent {
|
||||
* @param blockEntityType the block entity type to register a renderer for
|
||||
* @param blockEntityRendererProvider the renderer provider
|
||||
*/
|
||||
public <T extends BlockEntity> void registerBlockEntityRenderer(BlockEntityType<? extends T> blockEntityType, BlockEntityRendererProvider<T> blockEntityRendererProvider) {
|
||||
public <T extends BlockEntity, S extends BlockEntityRenderState> void registerBlockEntityRenderer(BlockEntityType<? extends T> blockEntityType, BlockEntityRendererProvider<T, S> blockEntityRendererProvider) {
|
||||
BlockEntityRenderers.register(blockEntityType, blockEntityRendererProvider);
|
||||
}
|
||||
}
|
||||
@@ -138,41 +142,54 @@ public abstract sealed class EntityRenderersEvent implements IModBusEvent {
|
||||
}
|
||||
|
||||
private final Map<EntityType<?>, EntityRenderer<?, ?>> renderers;
|
||||
private final Map<PlayerSkin.Model, EntityRenderer<? extends Player, ?>> skinMap;
|
||||
private final Map<PlayerModelType, AvatarRenderer<AbstractClientPlayer>> playerRenderers;
|
||||
private final Map<PlayerModelType, AvatarRenderer<ClientMannequin>> mannequinRenderers;
|
||||
private final EntityRendererProvider.Context context;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public AddLayers(Map<EntityType<?>, EntityRenderer<?, ?>> renderers, Map<PlayerSkin.Model, EntityRenderer<? extends Player, ?>> playerRenderers, EntityRendererProvider.Context context) {
|
||||
public AddLayers(Map<EntityType<?>, EntityRenderer<?, ?>> renderers, Map<PlayerModelType, AvatarRenderer<AbstractClientPlayer>> playerRenderers, Map<PlayerModelType, AvatarRenderer<ClientMannequin>> mannequinRenderers, EntityRendererProvider.Context context) {
|
||||
this.renderers = renderers;
|
||||
this.skinMap = playerRenderers;
|
||||
this.playerRenderers = playerRenderers;
|
||||
this.mannequinRenderers = mannequinRenderers;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the set of player skin names which have a renderer}
|
||||
* {@return the set of player model types which have a renderer}
|
||||
* <p>
|
||||
* Minecraft provides two default skin names: {@code default} for the
|
||||
* Minecraft provides two default types: {@code wide} for the
|
||||
* {@linkplain ModelLayers#PLAYER regular player model} and {@code slim} for the
|
||||
* {@linkplain ModelLayers#PLAYER_SLIM slim player model}.
|
||||
*/
|
||||
public Set<PlayerSkin.Model> getSkins() {
|
||||
return skinMap.keySet();
|
||||
public Set<PlayerModelType> getModelTypes() {
|
||||
return playerRenderers.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a player skin renderer for the given skin name.
|
||||
* Returns a renderer for the given model type used for normal players.
|
||||
*
|
||||
* @param skinName the name of the skin to get the renderer for
|
||||
* @param <R> the type of the skin renderer, usually {@link PlayerRenderer}
|
||||
* @return the skin renderer, or {@code null} if no renderer is registered for that skin name
|
||||
* @see #getSkins()
|
||||
* @param modelType the type to get the renderer for
|
||||
* @param <R> the type of the model renderer, usually {@link AvatarRenderer}
|
||||
* @see #getModelTypes()
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R extends EntityRenderer<? extends Player, ?>> R getPlayerSkin(PlayerSkin.Model skinName) {
|
||||
return (R)skinMap.get(skinName);
|
||||
public <R extends EntityRenderer<? extends Player, ?>> R getPlayerRenderer(PlayerModelType modelType) {
|
||||
return (R)playerRenderers.get(modelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Mannequin renderer for the given model type.
|
||||
*
|
||||
* @param modelType the type to get the renderer for
|
||||
* @param <R> the type of the model renderer, usually {@link AvatarRenderer}
|
||||
* @see #getModelTypes()
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R extends EntityRenderer<? extends ClientMannequin, ?>> R getMannequinRenderer(PlayerModelType modelType) {
|
||||
return (R)mannequinRenderers.get(modelType);
|
||||
}
|
||||
/**
|
||||
* Returns an entity renderer for the given entity type.
|
||||
*
|
||||
|
||||
@@ -5,65 +5,66 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraftforge.client.FramePassManager;
|
||||
import net.minecraftforge.client.gui.overlay.ForgeLayeredDraw;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.ClientRecipeBook;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.entity.ClientAvatarEntity;
|
||||
import net.minecraft.client.entity.ClientMannequin;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.toasts.Toast;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.model.SkullModelBase;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider.Context;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.client.renderer.entity.player.AvatarRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.AvatarRenderState;
|
||||
import net.minecraft.client.renderer.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.renderer.entity.state.ItemFrameRenderState;
|
||||
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
|
||||
import net.minecraft.client.renderer.entity.state.PlayerRenderState;
|
||||
import net.minecraft.client.renderer.special.SpecialModelRenderer;
|
||||
import net.minecraft.client.resources.PlayerSkin.Model;
|
||||
import net.minecraft.client.renderer.state.CameraRenderState;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Avatar;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.PlayerModelType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SkullBlock.Type;
|
||||
@@ -72,37 +73,28 @@ import net.minecraftforge.client.event.sound.PlayStreamingSourceEvent;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class ForgeEventFactoryClient {
|
||||
private static final ModLoader ML = ModLoader.get();
|
||||
|
||||
private ForgeEventFactoryClient() {}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link ModLoader#get()} event bus
|
||||
*/
|
||||
private static <T extends IModBusEvent> T fireModBus(T e) {
|
||||
return ML.postEventWithReturn(e);
|
||||
}
|
||||
|
||||
public static void onGatherLayers(Map<EntityType<?>, EntityRenderer<?, ?>> renderers, Map<Model, EntityRenderer<? extends Player, ?>> playerRenderers, Context context) {
|
||||
public static void onGatherLayers(Map<EntityType<?>, EntityRenderer<?, ?>> renderers, Map<PlayerModelType, AvatarRenderer<AbstractClientPlayer>> playerRenderers, Map<PlayerModelType, AvatarRenderer<ClientMannequin>> mannequinRenderers, Context context) {
|
||||
// TODO: Why is this a ModLoader event...
|
||||
fireModBus(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, context));
|
||||
ModLoader.postEvent(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, mannequinRenderers, context));
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseReleased(Screen screen, double mouseX, double mouseY, int button) {
|
||||
if (ScreenEvent.MouseButtonReleased.Pre.BUS.post(new ScreenEvent.MouseButtonReleased.Pre(screen, mouseX, mouseY, button)))
|
||||
public static boolean onScreenMouseReleased(Screen screen, double mouseX, double mouseY, MouseButtonEvent event) {
|
||||
if (ScreenEvent.MouseButtonReleased.Pre.BUS.post(new ScreenEvent.MouseButtonReleased.Pre(screen, mouseX, mouseY, event.button())))
|
||||
return true;
|
||||
|
||||
var ret = screen.mouseReleased(mouseX, mouseY, button);
|
||||
var result = ScreenEvent.MouseButtonReleased.Post.BUS.fire(new ScreenEvent.MouseButtonReleased.Post(screen, mouseX, mouseY, button, ret)).getResult();
|
||||
var ret = screen.mouseReleased(event);
|
||||
var result = ScreenEvent.MouseButtonReleased.Post.BUS.fire(new ScreenEvent.MouseButtonReleased.Post(screen, mouseX, mouseY, event.button(), ret)).getResult();
|
||||
return result == Result.DEFAULT ? ret : result == Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseClicked(Screen screen, double mouseX, double mouseY, int button) {
|
||||
var ret = ScreenEvent.MouseButtonPressed.Pre.BUS.post(new ScreenEvent.MouseButtonPressed.Pre(screen, mouseX, mouseY, button));
|
||||
public static boolean onScreenMouseClicked(Screen screen, double mouseX, double mouseY, MouseButtonEvent info, boolean repeate) {
|
||||
var ret = ScreenEvent.MouseButtonPressed.Pre.BUS.post(new ScreenEvent.MouseButtonPressed.Pre(screen, mouseX, mouseY, info.button()));
|
||||
if (!ret)
|
||||
ret = screen.mouseClicked(mouseX, mouseY, button);
|
||||
ret = screen.mouseClicked(info, repeate);
|
||||
|
||||
var result = ScreenEvent.MouseButtonPressed.Post.BUS.fire(new ScreenEvent.MouseButtonPressed.Post(screen, mouseX, mouseY, button, ret)).getResult();
|
||||
var result = ScreenEvent.MouseButtonPressed.Post.BUS.fire(new ScreenEvent.MouseButtonPressed.Post(screen, mouseX, mouseY, info.button(), ret)).getResult();
|
||||
return result == Result.DEFAULT ? ret : result == Result.ALLOW;
|
||||
}
|
||||
|
||||
@@ -202,7 +194,7 @@ public final class ForgeEventFactoryClient {
|
||||
ClientPlayerNetworkEvent.Clone.BUS.post(new ClientPlayerNetworkEvent.Clone(pc, oldPlayer, newPlayer, networkManager));
|
||||
}
|
||||
|
||||
public static ViewportEvent.ComputeFov fireComputeFov(GameRenderer renderer, Camera camera, double partialTick, float fov, boolean usedConfiguredFov) {
|
||||
public static ViewportEvent.ComputeFov fireComputeFov(GameRenderer renderer, Camera camera, float partialTick, float fov, boolean usedConfiguredFov) {
|
||||
return ViewportEvent.ComputeFov.BUS.fire(new ViewportEvent.ComputeFov(renderer, camera, partialTick, fov, usedConfiguredFov));
|
||||
}
|
||||
|
||||
@@ -210,32 +202,32 @@ public final class ForgeEventFactoryClient {
|
||||
return ViewportEvent.ComputeCameraAngles.BUS.fire(new ViewportEvent.ComputeCameraAngles(renderer, camera, partial, camera.getYRot(), camera.getXRot(), 0));
|
||||
}
|
||||
|
||||
public static <T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> boolean onRenderLivingPre(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderLivingEvent.Pre.BUS.post(new RenderLivingEvent.Pre<T, S, M>(state, renderer, poseStack, multiBufferSource, packedLight));
|
||||
public static <T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> boolean onRenderLivingPre(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState cameraState) {
|
||||
return RenderLivingEvent.Pre.BUS.post(new RenderLivingEvent.Pre<T, S, M>(state, renderer, poseStack, nodeCollector, cameraState));
|
||||
}
|
||||
|
||||
public static <T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> boolean onRenderLivingPost(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderLivingEvent.Post.BUS.post(new RenderLivingEvent.Post<T, S, M>(state, renderer, poseStack, multiBufferSource, packedLight));
|
||||
public static <T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> boolean onRenderLivingPost(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState cameraState) {
|
||||
return RenderLivingEvent.Post.BUS.post(new RenderLivingEvent.Post<T, S, M>(state, renderer, poseStack, nodeCollector, cameraState));
|
||||
}
|
||||
|
||||
public static boolean onRenderPlayerPre(PlayerRenderState player, PlayerRenderer renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderPlayerEvent.Pre.BUS.post(new RenderPlayerEvent.Pre(player, renderer, poseStack, multiBufferSource, packedLight));
|
||||
public static <AvatarlikeEntity extends Avatar & ClientAvatarEntity> boolean onRenderAvatarPre(AvatarRenderState player, AvatarRenderer<AvatarlikeEntity> renderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState camera) {
|
||||
return RenderAvatarEvent.Pre.BUS.post(new RenderAvatarEvent.Pre(player, renderer, poseStack, nodeCollector, camera));
|
||||
}
|
||||
|
||||
public static boolean onRenderPlayerPost(PlayerRenderState player, PlayerRenderer renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderPlayerEvent.Post.BUS.post(new RenderPlayerEvent.Post(player, renderer, poseStack, multiBufferSource, packedLight));
|
||||
public static <AvatarlikeEntity extends Avatar & ClientAvatarEntity> boolean onRenderAvatarPost(AvatarRenderState player, AvatarRenderer<AvatarlikeEntity> renderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState camera) {
|
||||
return RenderAvatarEvent.Post.BUS.post(new RenderAvatarEvent.Post(player, renderer, poseStack, nodeCollector, camera));
|
||||
}
|
||||
|
||||
public static boolean onRenderArm(PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, HumanoidArm arm) {
|
||||
return RenderArmEvent.BUS.post(new RenderArmEvent(poseStack, multiBufferSource, packedLight, arm));
|
||||
public static boolean onRenderArm(PoseStack poseStack, SubmitNodeCollector nodeCollector, int packedLight, HumanoidArm arm) {
|
||||
return RenderArmEvent.BUS.post(new RenderArmEvent(poseStack, nodeCollector, packedLight, arm));
|
||||
}
|
||||
|
||||
public static boolean onRenderItemInFrame(ItemFrameRenderState state, ItemFrameRenderer<?> renderItemFrame, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderItemInFrameEvent.BUS.post(new RenderItemInFrameEvent(state, renderItemFrame, poseStack, multiBufferSource, packedLight));
|
||||
public static boolean onRenderItemInFrame(ItemFrameRenderState state, ItemFrameRenderer<?> renderItemFrame, PoseStack poseStack, SubmitNodeCollector nodeCollector, int packedLight) {
|
||||
return RenderItemInFrameEvent.BUS.post(new RenderItemInFrameEvent(state, renderItemFrame, poseStack, nodeCollector, packedLight));
|
||||
}
|
||||
|
||||
public static RenderNameTagEvent fireRenderNameTagEvent(EntityRenderState state, Component content, EntityRenderer<?, ?> entityRenderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
return RenderNameTagEvent.BUS.fire(new RenderNameTagEvent(state, content, entityRenderer, poseStack, multiBufferSource, packedLight));
|
||||
public static RenderNameTagEvent fireRenderNameTagEvent(EntityRenderState state, Component content, EntityRenderer<?, ?> entityRenderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState cameraState) {
|
||||
return RenderNameTagEvent.BUS.fire(new RenderNameTagEvent(state, content, entityRenderer, poseStack, nodeCollector, cameraState));
|
||||
}
|
||||
|
||||
public static void onRenderScreenBackground(Screen screen, GuiGraphics guiGraphics) {
|
||||
@@ -277,13 +269,13 @@ public final class ForgeEventFactoryClient {
|
||||
|
||||
public static Map<Type, Function<EntityModelSet, SkullModelBase>> onCreateSkullModels() {
|
||||
var builder = ImmutableMap.<Type, Function<EntityModelSet, SkullModelBase>>builder();
|
||||
fireModBus(new EntityRenderersEvent.CreateSkullModels(builder));
|
||||
ModLoader.postEvent(new EntityRenderersEvent.CreateSkullModels(builder));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static ModelEvent.RegisterModelStateDefinitions onRegisterModeStateDefinitions() {
|
||||
// This is on the mod bus because it happens during the initial texture reload, which is while the Forge bus is shut down.
|
||||
return fireModBus(new ModelEvent.RegisterModelStateDefinitions());
|
||||
return ModLoader.postEventWithReturn(new ModelEvent.RegisterModelStateDefinitions());
|
||||
}
|
||||
|
||||
public static void onInitLevelRenderer() {
|
||||
@@ -291,6 +283,6 @@ public final class ForgeEventFactoryClient {
|
||||
}
|
||||
|
||||
public static void onComputeLayerOrder(ForgeLayeredDraw layeredDraw) {
|
||||
fireModBus(new AddGuiOverlayLayersEvent(layeredDraw));
|
||||
AddGuiOverlayLayersEvent.BUS.post(new AddGuiOverlayLayersEvent(layeredDraw));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.server.packs.metadata.MetadataSectionType;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Fired when an Atlas is being loaded.
|
||||
* This allows you to add custom metadata sections that will be loaded from the sprite's .mcmeta file.
|
||||
*/
|
||||
public final class GatherAtlasMetadataSectionsEvent extends MutableEvent {
|
||||
public static final EventBus<GatherAtlasMetadataSectionsEvent> BUS = EventBus.create(GatherAtlasMetadataSectionsEvent.class);
|
||||
|
||||
private final Set<MetadataSectionType<?>> types;
|
||||
|
||||
public GatherAtlasMetadataSectionsEvent(Set<MetadataSectionType<?>> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public void addType(MetadataSectionType<?> definition) {
|
||||
this.types.add(definition);
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
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 net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -26,12 +26,7 @@ import org.lwjgl.glfw.GLFW;
|
||||
* @see Key
|
||||
* @see InteractionKeyMappingTriggered
|
||||
*/
|
||||
public abstract sealed class InputEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<InputEvent> BUS = EventBus.create(InputEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected InputEvent() {}
|
||||
|
||||
public sealed interface InputEvent {
|
||||
/**
|
||||
* Fired when a mouse button is pressed/released. Sub-events get fired {@link Pre before} and {@link Post after} this happens.
|
||||
*
|
||||
@@ -41,29 +36,14 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see Pre
|
||||
* @see Post
|
||||
*/
|
||||
public static abstract sealed class MouseButton extends InputEvent {
|
||||
public static final EventBus<MouseButton> BUS = EventBus.create(MouseButton.class);
|
||||
|
||||
private final int button;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MouseButton(int button, int action, int modifiers) {
|
||||
this.button = button;
|
||||
this.action = action;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
sealed interface MouseButton extends InputEvent {
|
||||
/**
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with 'GLFW_MOUSE_BUTTON_'
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getButton() {
|
||||
return this.button;
|
||||
}
|
||||
int getButton();
|
||||
|
||||
/**
|
||||
* {@return the mouse button's action}
|
||||
@@ -71,9 +51,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see InputConstants#PRESS
|
||||
* @see InputConstants#RELEASE
|
||||
*/
|
||||
public int getAction() {
|
||||
return this.action;
|
||||
}
|
||||
int getAction();
|
||||
|
||||
/**
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
@@ -86,9 +64,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers() {
|
||||
return this.modifiers;
|
||||
}
|
||||
int getModifiers();
|
||||
|
||||
/**
|
||||
* Fired when a mouse button is pressed/released, <b>before</b> being processed by vanilla.
|
||||
@@ -99,13 +75,11 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public static final class Pre extends MouseButton implements Cancellable {
|
||||
record Pre(int getButton, int getAction, int getModifiers) implements Cancellable, MouseButton, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(int button, int action, int modifiers) {
|
||||
super(button, action, modifiers);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,13 +89,11 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public static final class Post extends MouseButton {
|
||||
record Post(int getButton, int getAction, int getModifiers) implements MouseButton, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(int button, int action, int modifiers) {
|
||||
super(button, action, modifiers);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,77 +106,28 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*
|
||||
* @param getDeltaX the amount of change / delta of the mouse scroll in the vertical direction
|
||||
* @param getDeltaY the amount of change / delta of the mouse scroll in the horizontal direction
|
||||
* @param isLeftDown {@code true} if the left mouse button is pressed
|
||||
* @param isMiddleDown {@code true} if the middle mouse button is pressed
|
||||
* @param isRightDown {@code true} if the right mouse button is pressed
|
||||
* @param getMouseX the X position of the mouse cursor
|
||||
* @param getMouseY the Y position of the mouse cursor
|
||||
*/
|
||||
public static final class MouseScrollingEvent extends InputEvent implements Cancellable {
|
||||
record MouseScrollingEvent(
|
||||
double getDeltaX,
|
||||
double getDeltaY,
|
||||
boolean isLeftDown,
|
||||
boolean isMiddleDown,
|
||||
boolean isRightDown,
|
||||
double getMouseX,
|
||||
double getMouseY
|
||||
) implements Cancellable, InputEvent, RecordEvent {
|
||||
public static final CancellableEventBus<MouseScrollingEvent> BUS = CancellableEventBus.create(MouseScrollingEvent.class);
|
||||
|
||||
private final double deltaX;
|
||||
private final double deltaY;
|
||||
private final double mouseX;
|
||||
private final double mouseY;
|
||||
private final boolean leftDown;
|
||||
private final boolean middleDown;
|
||||
private final boolean rightDown;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseScrollingEvent(double deltaX, double deltaY, boolean leftDown, boolean middleDown, boolean rightDown, double mouseX, double mouseY) {
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
this.leftDown = leftDown;
|
||||
this.middleDown = middleDown;
|
||||
this.rightDown = rightDown;
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the vertical direction}
|
||||
*/
|
||||
public double getDeltaX() {
|
||||
return this.deltaX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the horizontal direction}
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return this.deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the left mouse button is pressed}
|
||||
*/
|
||||
public boolean isLeftDown() {
|
||||
return this.leftDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the right mouse button is pressed}
|
||||
*/
|
||||
public boolean isRightDown() {
|
||||
return this.rightDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the middle mouse button is pressed}
|
||||
*/
|
||||
public boolean isMiddleDown() {
|
||||
return this.middleDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseX() {
|
||||
return this.mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseY() {
|
||||
return this.mouseY;
|
||||
}
|
||||
public MouseScrollingEvent {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,21 +135,11 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
*
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Key extends InputEvent {
|
||||
record Key(int getKey, int getScanCode, int getAction, int getModifiers) implements RecordEvent, InputEvent {
|
||||
public static final EventBus<Key> BUS = EventBus.create(Key.class);
|
||||
|
||||
private final int key;
|
||||
private final int scanCode;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Key(int key, int scanCode, int action, int modifiers) {
|
||||
this.key = key;
|
||||
this.scanCode = scanCode;
|
||||
this.action = action;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
public Key {}
|
||||
|
||||
/**
|
||||
* {@return the {@code GLFW} (platform-agnostic) key code}
|
||||
@@ -236,7 +149,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__keys.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getKey() {
|
||||
return this.key;
|
||||
return getKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +162,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see InputConstants#getKey(int, int)
|
||||
*/
|
||||
public int getScanCode() {
|
||||
return this.scanCode;
|
||||
return getScanCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +173,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see InputConstants#REPEAT
|
||||
*/
|
||||
public int getAction() {
|
||||
return this.action;
|
||||
return getAction;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,7 +188,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers() {
|
||||
return this.modifiers;
|
||||
return getModifiers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +208,7 @@ public abstract sealed class InputEvent extends MutableEvent implements Inherita
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
// TODO: Change the 'button' to sub events. - Lex 0422202
|
||||
public static final class InteractionKeyMappingTriggered extends InputEvent implements Cancellable {
|
||||
final class InteractionKeyMappingTriggered extends MutableEvent implements Cancellable, InputEvent {
|
||||
public static final CancellableEventBus<InteractionKeyMappingTriggered> BUS = CancellableEventBus.create(InteractionKeyMappingTriggered.class);
|
||||
|
||||
private final int button;
|
||||
|
||||
@@ -18,7 +18,6 @@ import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -28,10 +27,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Houses events related to models.
|
||||
*/
|
||||
public abstract sealed class ModelEvent {
|
||||
@ApiStatus.Internal
|
||||
protected ModelEvent() {}
|
||||
|
||||
public sealed interface ModelEvent {
|
||||
/**
|
||||
* Fired while the {@link ModelManager} is reloading models, after the model registry is set up, but before it's
|
||||
* passed to the {@link net.minecraft.client.renderer.block.BlockModelShaper} for caching.
|
||||
@@ -43,38 +39,19 @@ public abstract sealed class ModelEvent {
|
||||
* must therefore not be accessed in this event.
|
||||
* </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* @param getModelBakery the model loader
|
||||
* @param getResults the modifiable registry map of models and their model names
|
||||
*/
|
||||
public static final class ModifyBakingResult extends ModelEvent implements IModBusEvent {
|
||||
record ModifyBakingResult(ModelBakery getModelBakery, ModelBakery.BakingResult getResults)
|
||||
implements IModBusEvent, ModelEvent {
|
||||
public static EventBus<ModifyBakingResult> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, ModifyBakingResult.class);
|
||||
}
|
||||
|
||||
private final ModelBakery modelBakery;
|
||||
private final ModelBakery.BakingResult results;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ModifyBakingResult(ModelBakery modelBakery, ModelBakery.BakingResult results) {
|
||||
this.modelBakery = modelBakery;
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the modifiable registry map of models and their model names
|
||||
*/
|
||||
public ModelBakery.BakingResult getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the model loader
|
||||
*/
|
||||
public ModelBakery getModelBakery() {
|
||||
return modelBakery;
|
||||
}
|
||||
public ModifyBakingResult {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,38 +60,19 @@ public abstract sealed class ModelEvent {
|
||||
* The model registry given by this event is unmodifiable. To modify the model registry, use
|
||||
* {@link ModelEvent.ModifyBakingResult} instead.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* @param getModelManager the model manager
|
||||
* @param getModelBakery the model loader
|
||||
*/
|
||||
public static final class BakingCompleted extends ModelEvent implements IModBusEvent {
|
||||
record BakingCompleted(ModelManager getModelManager, ModelBakery getModelBakery)
|
||||
implements IModBusEvent, ModelEvent {
|
||||
public static EventBus<BakingCompleted> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, BakingCompleted.class);
|
||||
}
|
||||
|
||||
private final ModelManager modelManager;
|
||||
private final ModelBakery modelBakery;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BakingCompleted(ModelManager modelManager, ModelBakery modelBakery) {
|
||||
this.modelManager = modelManager;
|
||||
this.modelBakery = modelBakery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the model manager
|
||||
*/
|
||||
public ModelManager getModelManager() {
|
||||
return modelManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the model loader
|
||||
*/
|
||||
public ModelBakery getModelBakery() {
|
||||
return modelBakery;
|
||||
}
|
||||
public BakingCompleted {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,10 +81,9 @@ public abstract sealed class ModelEvent {
|
||||
* This is designed to allow for extra models to be loaded in connection with a blockstates json file. This is not intended to allow
|
||||
* overriding or modification of StateDefinitions from registered Blocks
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific 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>
|
||||
*/
|
||||
public static final class RegisterModelStateDefinitions extends ModelEvent implements IModBusEvent {
|
||||
final class RegisterModelStateDefinitions implements IModBusEvent, ModelEvent {
|
||||
public static EventBus<RegisterModelStateDefinitions> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterModelStateDefinitions.class);
|
||||
}
|
||||
@@ -155,12 +112,9 @@ public abstract sealed class ModelEvent {
|
||||
/**
|
||||
* Allows users to register their own {@link IGeometryLoader geometry loaders} for use in block/item models.
|
||||
*
|
||||
* <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>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class RegisterGeometryLoaders extends ModelEvent implements IModBusEvent {
|
||||
final class RegisterGeometryLoaders implements IModBusEvent, ModelEvent {
|
||||
public static EventBus<RegisterGeometryLoaders> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterGeometryLoaders.class);
|
||||
}
|
||||
|
||||
@@ -7,35 +7,21 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.player.ClientInput;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* <p>Fired after the player's movement inputs are updated.</p>
|
||||
* Fired after the player's movement inputs are updated.
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
* @param getInput the player's movement inputs
|
||||
*/
|
||||
public final class MovementInputUpdateEvent extends PlayerEvent {
|
||||
public record MovementInputUpdateEvent(Player getEntity, ClientInput getInput) implements RecordEvent, PlayerEvent {
|
||||
public static final EventBus<MovementInputUpdateEvent> BUS = EventBus.create(MovementInputUpdateEvent.class);
|
||||
|
||||
private final ClientInput input;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MovementInputUpdateEvent(Player player, ClientInput input) {
|
||||
super(player);
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player's movement inputs}
|
||||
*/
|
||||
public ClientInput getInput() {
|
||||
return input;
|
||||
}
|
||||
public MovementInputUpdateEvent {}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -31,10 +30,7 @@ import java.util.ArrayList;
|
||||
* @see RegisterColorHandlersEvent.Block
|
||||
* @see RegisterColorHandlersEvent.ColorResolvers
|
||||
*/
|
||||
public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent {
|
||||
@ApiStatus.Internal
|
||||
protected RegisterColorHandlersEvent() {}
|
||||
|
||||
public sealed interface RegisterColorHandlersEvent extends IModBusEvent {
|
||||
/**
|
||||
* Fired for registering block color handlers.
|
||||
*
|
||||
@@ -43,17 +39,13 @@ public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent
|
||||
* <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 Block extends RegisterColorHandlersEvent {
|
||||
record Block(BlockColors getBlockColors) implements RegisterColorHandlersEvent {
|
||||
public static EventBus<Block> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, Block.class);
|
||||
}
|
||||
|
||||
private final BlockColors blockColors;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Block(BlockColors blockColors) {
|
||||
this.blockColors = blockColors;
|
||||
}
|
||||
public Block {}
|
||||
|
||||
/**
|
||||
* {@return the block colors registry}
|
||||
@@ -61,7 +53,7 @@ public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent
|
||||
* @see BlockColors#register(BlockColor, net.minecraft.world.level.block.Block...)
|
||||
*/
|
||||
public BlockColors getBlockColors() {
|
||||
return blockColors;
|
||||
return getBlockColors;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +64,7 @@ public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void register(BlockColor blockColor, net.minecraft.world.level.block.Block... blocks) {
|
||||
blockColors.register(blockColor, blocks);
|
||||
getBlockColors.register(blockColor, blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +73,7 @@ public abstract sealed class RegisterColorHandlersEvent implements IModBusEvent
|
||||
* {@link net.minecraft.world.level.BlockAndTintGetter#getBlockTint(BlockPos, ColorResolver)}.
|
||||
*/
|
||||
@NullMarked
|
||||
public static final class ColorResolvers extends RegisterColorHandlersEvent implements SelfDestructing {
|
||||
final class ColorResolvers implements RegisterColorHandlersEvent, SelfDestructing {
|
||||
public static EventBus<ColorResolvers> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, ColorResolvers.class);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.particle.ParticleProvider;
|
||||
import net.minecraft.client.particle.TextureSheetParticle;
|
||||
import net.minecraft.client.particle.ParticleResources;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.core.particles.ParticleType;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
@@ -34,11 +33,11 @@ public final class RegisterParticleProvidersEvent implements IModBusEvent {
|
||||
return IModBusEvent.getBus(modBusGroup, RegisterParticleProvidersEvent.class);
|
||||
}
|
||||
|
||||
private final ParticleEngine particleEngine;
|
||||
private final ParticleResources particles;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RegisterParticleProvidersEvent(ParticleEngine particleEngine) {
|
||||
this.particleEngine = particleEngine;
|
||||
public RegisterParticleProvidersEvent(ParticleResources particles) {
|
||||
this.particles = particles;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,23 +53,7 @@ public final class RegisterParticleProvidersEvent implements IModBusEvent {
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void registerSpecial(ParticleType<T> type, ParticleProvider<T> provider) {
|
||||
particleEngine.register(type, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Registers a ParticleProvider for a json-based ParticleType with a single texture;
|
||||
* the resulting {@link TextureSheetParticle}s will use that texture when created.</p>
|
||||
*
|
||||
* <p>A particle json with an ID matching the ParticleType <strong>must exist</strong> in the <code>particles</code> asset folder,
|
||||
* or a missing texture list error will occur when particle jsons load.</p>
|
||||
*
|
||||
* @param <T> ParticleOptions used by the ParticleType and Sprite function.
|
||||
* @param type ParticleType to register a ParticleProvider for.
|
||||
* @param sprite Sprite function responsible for providing that ParticleType's particles.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void registerSprite(ParticleType<T> type, ParticleProvider.Sprite<T> sprite) {
|
||||
particleEngine.register(type, sprite);
|
||||
particles.register(type, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +68,7 @@ public final class RegisterParticleProvidersEvent implements IModBusEvent {
|
||||
* @param registration SpriteParticleRegistration function responsible for providing that ParticleType's particles.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void registerSpriteSet(ParticleType<T> type, ParticleEngine.SpriteParticleRegistration<T> registration) {
|
||||
particleEngine.register(type, registration);
|
||||
public <T extends ParticleOptions> void registerSpriteSet(ParticleType<T> type, ParticleResources.SpriteParticleRegistration<T> registration) {
|
||||
particles.register(type, registration);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
@@ -23,14 +23,10 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* <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 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 record RenderArmEvent(
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
int getPackedLight,
|
||||
HumanoidArm getArm
|
||||
) implements Cancellable, RecordEvent {
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.entity.ClientAvatarEntity;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.player.AvatarRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.AvatarRenderState;
|
||||
import net.minecraft.client.renderer.state.CameraRenderState;
|
||||
import net.minecraft.world.entity.Avatar;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Fired when a Avatar is being rendered, typically a player or a mannequin.
|
||||
* See the two subclasses for listening for before and after rendering.
|
||||
*
|
||||
* @see RenderAvatarEvent.Pre
|
||||
* @see RenderAvatarEvent.Post
|
||||
* @see AvatarRenderer
|
||||
*/
|
||||
public sealed interface RenderAvatarEvent {
|
||||
AvatarRenderState getState();
|
||||
|
||||
/**
|
||||
* {@return the player entity renderer}
|
||||
*/
|
||||
AvatarRenderer<?> getRenderer();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AvatarlikeEntity extends Avatar & ClientAvatarEntity> AvatarRenderer<AvatarlikeEntity> getRendererTyped() {
|
||||
return (AvatarRenderer<AvatarlikeEntity>) getRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
PoseStack getPoseStack();
|
||||
|
||||
/**
|
||||
* {@return the collector you should render to}
|
||||
*/
|
||||
SubmitNodeCollector getNodeCollector();
|
||||
|
||||
/**
|
||||
* {@return State related to the current camera}
|
||||
*
|
||||
*/
|
||||
CameraRenderState getCameraState();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the player is rendered.
|
||||
* This can be used for rendering additional effects or suppressing rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.
|
||||
* If this event is cancelled, then the player will not be rendered and the corresponding
|
||||
* {@link RenderAvatarEvent.Post} will not be fired.</p>
|
||||
*
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
record Pre(
|
||||
AvatarRenderState getState,
|
||||
AvatarRenderer<?> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
CameraRenderState getCameraState
|
||||
) implements Cancellable, RecordEvent, RenderAvatarEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the player is rendered, if the corresponding {@link RenderAvatarEvent.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
record Post(
|
||||
AvatarRenderState getState,
|
||||
AvatarRenderer<?> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
CameraRenderState getCameraState
|
||||
) implements RecordEvent, RenderAvatarEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
public record RenderHandEvent(
|
||||
InteractionHand getHand,
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
int getPackedLight,
|
||||
float getPartialTick,
|
||||
float getInterpolatedPitch,
|
||||
|
||||
@@ -8,102 +8,102 @@ package net.minecraftforge.client.event;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.MultiBufferSource.BufferSource;
|
||||
import net.minecraft.client.renderer.state.LevelRenderState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Fired before a selection highlight is rendered.
|
||||
* You should extract your custom data here so that you can use it in the render callback without effecting world state.
|
||||
*
|
||||
* See the two subclasses to listen for blocks or entities.
|
||||
*
|
||||
* @see Block
|
||||
* @see Entity
|
||||
*/
|
||||
public abstract sealed class RenderHighlightEvent extends MutableEvent implements Cancellable, InheritableEvent {
|
||||
public static final CancellableEventBus<RenderHighlightEvent> BUS = CancellableEventBus.create(RenderHighlightEvent.class);
|
||||
public sealed abstract class RenderHighlightEvent extends MutableEvent implements Cancellable, InheritableEvent permits RenderHighlightEvent.Block, RenderHighlightEvent.Entity {
|
||||
CancellableEventBus<RenderHighlightEvent> BUS = CancellableEventBus.create(RenderHighlightEvent.class);
|
||||
|
||||
private final LevelRenderer levelRenderer;
|
||||
private final Camera camera;
|
||||
private final HitResult target;
|
||||
private final float partialTick;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final LevelRenderState levelRenderState;
|
||||
private Callback customRenderer;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected RenderHighlightEvent(LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource) {
|
||||
private RenderHighlightEvent(LevelRenderer levelRenderer, Camera camera, LevelRenderState levelRenderState) {
|
||||
this.levelRenderer = levelRenderer;
|
||||
this.camera = camera;
|
||||
this.target = target;
|
||||
this.partialTick = partialTick;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.levelRenderState = levelRenderState;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer}
|
||||
*/
|
||||
public LevelRenderer getLevelRenderer() {
|
||||
return levelRenderer;
|
||||
return this.levelRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer state}
|
||||
*/
|
||||
public LevelRenderState getLevelRenderState() {
|
||||
return this.levelRenderState;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the camera information}
|
||||
*/
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
return this.camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the hit result which triggered the selection highlight}
|
||||
*/
|
||||
public HitResult getTarget() {
|
||||
return target;
|
||||
abstract HitResult getTarget();
|
||||
|
||||
/**
|
||||
* {@return the custom renderer that an event listener has set}
|
||||
*/
|
||||
@Nullable
|
||||
public Callback getCustomRenderer() {
|
||||
return this.customRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
* Set a custom renderer to render the selection highlight.
|
||||
* May be null to clear a previously set custom renderer.
|
||||
*
|
||||
* If the callback is set, it will be invoked instead of the vanilla rendering.
|
||||
*/
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
public void setCustomRenderer(@Nullable Callback value) {
|
||||
this.customRenderer = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired before a block's selection highlight is rendered.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.
|
||||
* If the event is cancelled, then the selection highlight 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>
|
||||
*/
|
||||
public static final class Block extends RenderHighlightEvent {
|
||||
public static final CancellableEventBus<Block> BUS = CancellableEventBus.create(Block.class);
|
||||
private final BlockHitResult target;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Block(LevelRenderer levelRenderer, Camera camera, BlockHitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource) {
|
||||
super(levelRenderer, camera, target, partialTick, poseStack, bufferSource);
|
||||
public Block(LevelRenderer levelRenderer, Camera camera, LevelRenderState levelRenderState, BlockHitResult target) {
|
||||
super(levelRenderer, camera, levelRenderState);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,24 +111,25 @@ public abstract sealed class RenderHighlightEvent extends MutableEvent implement
|
||||
*/
|
||||
@Override
|
||||
public BlockHitResult getTarget() {
|
||||
return (BlockHitResult) super.target;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired before an entity's selection highlight is rendered.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}.</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>
|
||||
*/
|
||||
public static final class Entity extends RenderHighlightEvent {
|
||||
public static final CancellableEventBus<Entity> BUS = CancellableEventBus.create(Entity.class);
|
||||
private final EntityHitResult target;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Entity(LevelRenderer levelRenderer, Camera camera, EntityHitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource) {
|
||||
super(levelRenderer, camera, target, partialTick, poseStack, bufferSource);
|
||||
public Entity(LevelRenderer levelRenderer, Camera camera, LevelRenderState levelRenderState, EntityHitResult target) {
|
||||
super(levelRenderer, camera, levelRenderState);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +137,11 @@ public abstract sealed class RenderHighlightEvent extends MutableEvent implement
|
||||
*/
|
||||
@Override
|
||||
public EntityHitResult getTarget() {
|
||||
return (EntityHitResult) super.target;
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void render(BufferSource source, PoseStack stack, boolean translucent, LevelRenderState state);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.ItemFrameRenderState;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
@@ -24,18 +24,13 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
*
|
||||
* <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 record RenderItemInFrameEvent(
|
||||
ItemFrameRenderState getItemFrameState,
|
||||
ItemFrameRenderer<?> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
MultiBufferSource getMultiBufferSource,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
int getPackedLight
|
||||
) implements Cancellable, RecordEvent {
|
||||
public static final CancellableEventBus<RenderItemInFrameEvent> BUS = CancellableEventBus.create(RenderItemInFrameEvent.class);
|
||||
|
||||
@@ -8,15 +8,15 @@ package net.minecraftforge.client.event;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
|
||||
import net.minecraft.client.renderer.state.CameraRenderState;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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 net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -32,69 +32,40 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* @param <M> the model for the living entity
|
||||
* @see RenderLivingEvent.Pre
|
||||
* @see RenderLivingEvent.Post
|
||||
* @see RenderPlayerEvent
|
||||
* @see RenderAvatarEvent
|
||||
* @see LivingEntityRenderer
|
||||
*/
|
||||
public abstract sealed class RenderLivingEvent<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<RenderLivingEvent> BUS = EventBus.create(RenderLivingEvent.class);
|
||||
|
||||
private final S state;
|
||||
private final LivingEntityRenderer<T, S, M> renderer;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected RenderLivingEvent(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
this.state = state;
|
||||
this.renderer = renderer;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
public sealed interface RenderLivingEvent<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> {
|
||||
/**
|
||||
* @return the living entity being rendered
|
||||
*/
|
||||
public S getState() {
|
||||
return state;
|
||||
}
|
||||
S getState();
|
||||
|
||||
/**
|
||||
* @return the renderer for the living entity
|
||||
*/
|
||||
public LivingEntityRenderer<T, S, M> getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
LivingEntityRenderer<T, S, M> getRenderer();
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
PoseStack getPoseStack();
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
* {@return The render buffer that is collecting the model data. So that things can be batched}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
SubmitNodeCollector getNodeCollector();
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
* {@return Various state infomration about the camera}
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
}
|
||||
CameraRenderState getCameraState();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> an entity is rendered.
|
||||
* This can be used to render additional effects or suppress rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancelable}.
|
||||
* If this event is cancelled, then the entity will not be rendered and the corresponding
|
||||
* {@link RenderLivingEvent.Post} will not be fired.</p>
|
||||
*
|
||||
@@ -104,32 +75,38 @@ public abstract sealed class RenderLivingEvent<T extends LivingEntity, S extends
|
||||
* @param <T> the living entity that is being rendered
|
||||
* @param <M> the model for the living entity
|
||||
*/
|
||||
public static final class Pre<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> extends RenderLivingEvent<T, S, M> implements Cancellable {
|
||||
record Pre<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>>(
|
||||
S getState,
|
||||
LivingEntityRenderer<T, S, M> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
CameraRenderState getCameraState
|
||||
) implements Cancellable, RenderLivingEvent<T, S, M>, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(state, renderer, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> an entity is rendered, if the corresponding {@link RenderLivingEvent.Post} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}.</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 <T> the living entity that was rendered
|
||||
* @param <M> the model for the living entity
|
||||
*/
|
||||
public static final class Post<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>> extends RenderLivingEvent<T, S, M> {
|
||||
record Post<T extends LivingEntity, S extends LivingEntityRenderState, M extends EntityModel<? super S>>(
|
||||
S getState,
|
||||
LivingEntityRenderer<T, S, M> getRenderer,
|
||||
PoseStack getPoseStack,
|
||||
SubmitNodeCollector getNodeCollector,
|
||||
CameraRenderState getCameraState
|
||||
) implements RecordEvent, RenderLivingEvent<T, S, M> {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(S state, LivingEntityRenderer<T, S, M> renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(state, renderer, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.renderer.state.CameraRenderState;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
@@ -28,8 +28,7 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* <li>{@link Result#DENY} - the nameplate will not be rendered.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <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>
|
||||
*
|
||||
* @see EntityRenderer
|
||||
*/
|
||||
@@ -41,19 +40,19 @@ public final class RenderNameTagEvent extends MutableEvent implements HasResult
|
||||
private final Component originalContent;
|
||||
private final EntityRenderer<?, ?> entityRenderer;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
private final SubmitNodeCollector nodeCollector;
|
||||
private final CameraRenderState cameraState;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderNameTagEvent(EntityRenderState state, Component content, EntityRenderer<?, ?> entityRenderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
public RenderNameTagEvent(EntityRenderState state, Component content, EntityRenderer<?, ?> entityRenderer, PoseStack poseStack, SubmitNodeCollector nodeCollector, CameraRenderState cameraState) {
|
||||
this.state = state;
|
||||
this.originalContent = content;
|
||||
this.setContent(this.originalContent);
|
||||
this.entityRenderer = entityRenderer;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
this.nodeCollector = nodeCollector;
|
||||
this.cameraState = cameraState;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -99,19 +98,17 @@ public final class RenderNameTagEvent extends MutableEvent implements HasResult
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
* {@return the node collector that you should render to}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return this.multiBufferSource;
|
||||
public SubmitNodeCollector getNodeCollector() {
|
||||
return this.nodeCollector;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see net.minecraft.client.renderer.LightTexture
|
||||
* {@return CameraState for the current render frame}
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return this.packedLight;
|
||||
public CameraRenderState getCameraState() {
|
||||
return this.cameraState;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.client.renderer.entity.state.PlayerRenderState;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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 net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Fired when a player is being rendered.
|
||||
* See the two subclasses for listening for before and after rendering.
|
||||
*
|
||||
* @see RenderPlayerEvent.Pre
|
||||
* @see RenderPlayerEvent.Post
|
||||
* @see PlayerRenderer
|
||||
*/
|
||||
public abstract sealed class RenderPlayerEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<RenderPlayerEvent> BUS = EventBus.create(RenderPlayerEvent.class);
|
||||
|
||||
private final PlayerRenderState state;
|
||||
private final PlayerRenderer renderer;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected RenderPlayerEvent(PlayerRenderState state, PlayerRenderer renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
this.state = state;
|
||||
this.renderer = renderer;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
public PlayerRenderState getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player entity renderer}
|
||||
*/
|
||||
public PlayerRenderer 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the player is rendered.
|
||||
* This can be used for rendering additional effects or suppressing rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the player will not be rendered and the corresponding
|
||||
* {@link RenderPlayerEvent.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends RenderPlayerEvent implements Cancellable {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(PlayerRenderState state, PlayerRenderer renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(state, renderer, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the player is rendered, if the corresponding {@link RenderPlayerEvent.Pre} is not cancelled.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Post extends RenderPlayerEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(PlayerRenderState state, PlayerRenderer renderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(state, renderer, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ 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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -37,10 +37,10 @@ import java.util.List;
|
||||
* @see RenderTooltipEvent.Pre
|
||||
* @see RenderTooltipEvent.Background
|
||||
*/
|
||||
@NullMarked
|
||||
public abstract sealed class RenderTooltipEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<RenderTooltipEvent> BUS = EventBus.create(RenderTooltipEvent.class);
|
||||
|
||||
@NotNull
|
||||
protected final ItemStack itemStack;
|
||||
protected final GuiGraphics graphics;
|
||||
protected int x;
|
||||
@@ -49,8 +49,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
protected final List<ClientTooltipComponent> components;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected RenderTooltipEvent(@NotNull ItemStack itemStack, GuiGraphics graphics, int x, int y, @NotNull Font font, @NotNull List<ClientTooltipComponent> components)
|
||||
{
|
||||
protected RenderTooltipEvent(ItemStack itemStack, GuiGraphics graphics, int x, int y, Font font, List<ClientTooltipComponent> components) {
|
||||
this.itemStack = itemStack;
|
||||
this.graphics = graphics;
|
||||
this.components = Collections.unmodifiableList(components);
|
||||
@@ -63,18 +62,23 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* {@return the item stack which the tooltip is being rendered for, or an {@linkplain ItemStack#isEmpty() empty
|
||||
* item stack} if there is no associated item stack}
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gui graphics helper for the gui}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return graphics;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the graphics helper for the gui}
|
||||
*/
|
||||
public GuiGraphics getGraphics()
|
||||
{
|
||||
return this.graphics;
|
||||
public GuiGraphics getGraphics() {
|
||||
return graphics;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,34 +86,28 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
*
|
||||
* <p>Use {@link ItemTooltipEvent} or {@link GatherComponents} to modify tooltip contents or components.</p>
|
||||
*/
|
||||
@NotNull
|
||||
public List<ClientTooltipComponent> getComponents()
|
||||
{
|
||||
public List<ClientTooltipComponent> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the tooltip box} By default, this is the mouse X position.
|
||||
*/
|
||||
public int getX()
|
||||
{
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the tooltip box} By default, this is the mouse Y position.
|
||||
*/
|
||||
public int getY()
|
||||
{
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return The font used to render the text}
|
||||
*/
|
||||
@NotNull
|
||||
public Font getFont()
|
||||
{
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
@@ -117,7 +115,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* Fired when a tooltip gathers the {@link TooltipComponent}s to be rendered, before any text wrapping or processing.
|
||||
* The list of components and the maximum width of the tooltip can be modified through this event.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.
|
||||
* If this event is cancelled, then the list of components will be empty, causing the tooltip to not be rendered and
|
||||
* the corresponding {@link RenderTooltipEvent.Pre} and {@link RenderTooltipEvent.Background} to not be fired.</p>
|
||||
*
|
||||
@@ -134,8 +132,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
private int maxWidth;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public GatherComponents(ItemStack itemStack, int screenWidth, int screenHeight, List<Either<FormattedText, TooltipComponent>> tooltipElements, int maxWidth)
|
||||
{
|
||||
public GatherComponents(ItemStack itemStack, int screenWidth, int screenHeight, List<Either<FormattedText, TooltipComponent>> tooltipElements, int maxWidth) {
|
||||
this.itemStack = itemStack;
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
@@ -147,8 +144,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* {@return the item stack which the tooltip is being rendered for, or an {@linkplain ItemStack#isEmpty() empty
|
||||
* item stack} if there is no associated item stack}
|
||||
*/
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -157,8 +153,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself
|
||||
* is moved to be within the screen width.
|
||||
*/
|
||||
public int getScreenWidth()
|
||||
{
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
@@ -166,8 +161,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* {@return the height of the screen}
|
||||
* The tooltip box is moved to be within the screen height.
|
||||
*/
|
||||
public int getScreenHeight()
|
||||
{
|
||||
public int getScreenHeight() {
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
@@ -175,8 +169,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* {@return the modifiable list of elements to be rendered on the tooltip} These elements can be either
|
||||
* formatted text or custom tooltip components.
|
||||
*/
|
||||
public List<Either<FormattedText, TooltipComponent>> getTooltipElements()
|
||||
{
|
||||
public List<Either<FormattedText, TooltipComponent>> getTooltipElements() {
|
||||
return tooltipElements;
|
||||
}
|
||||
|
||||
@@ -186,8 +179,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* <p>A value of {@code -1} means an unlimited maximum width. However, an unlimited maximum width will still
|
||||
* be wrapped to be within the screen bounds.</p>
|
||||
*/
|
||||
public int getMaxWidth()
|
||||
{
|
||||
public int getMaxWidth() {
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
@@ -196,8 +188,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
*
|
||||
* @param maxWidth the new maximum width
|
||||
*/
|
||||
public void setMaxWidth(int maxWidth)
|
||||
{
|
||||
public void setMaxWidth(int maxWidth) {
|
||||
this.maxWidth = maxWidth;
|
||||
}
|
||||
}
|
||||
@@ -206,7 +197,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* Fired <b>before</b> the tooltip is rendered.
|
||||
* This can be used to modify the positioning and font of the tooltip.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}.
|
||||
* If this event is cancelled, then the tooltip will not be rendered and the corresponding
|
||||
* {@link RenderTooltipEvent.Background} will not be fired.</p>
|
||||
*
|
||||
@@ -221,8 +212,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
private final ClientTooltipPositioner positioner;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(@NotNull ItemStack stack, GuiGraphics graphics, int x, int y, int screenWidth, int screenHeight, @NotNull Font font, @NotNull List<ClientTooltipComponent> components, @NotNull ClientTooltipPositioner positioner)
|
||||
{
|
||||
public Pre(ItemStack stack, GuiGraphics graphics, int x, int y, int screenWidth, int screenHeight, Font font, List<ClientTooltipComponent> components, ClientTooltipPositioner positioner) {
|
||||
super(stack, graphics, x, y, font, components);
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
@@ -234,8 +224,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself
|
||||
* is moved to be within the screen width.
|
||||
*/
|
||||
public int getScreenWidth()
|
||||
{
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
@@ -243,13 +232,11 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* {@return the height of the screen}
|
||||
* The tooltip box is moved to be within the screen height.
|
||||
*/
|
||||
public int getScreenHeight()
|
||||
{
|
||||
public int getScreenHeight() {
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
public ClientTooltipPositioner getTooltipPositioner()
|
||||
{
|
||||
public ClientTooltipPositioner getTooltipPositioner() {
|
||||
return positioner;
|
||||
}
|
||||
|
||||
@@ -258,8 +245,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
*
|
||||
* @param fr the new font
|
||||
*/
|
||||
public void setFont(@NotNull Font fr)
|
||||
{
|
||||
public void setFont(Font fr) {
|
||||
this.font = fr;
|
||||
}
|
||||
|
||||
@@ -268,8 +254,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
*
|
||||
* @param x the new X origin
|
||||
*/
|
||||
public void setX(int x)
|
||||
{
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
@@ -278,8 +263,7 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
*
|
||||
* @param y the new Y origin
|
||||
*/
|
||||
public void setY(int y)
|
||||
{
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
@@ -288,19 +272,17 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
* Fired when the tooltip background prefix is determined.
|
||||
* This can be used to modify the textures to be used for the tooltip background.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Background extends RenderTooltipEvent {
|
||||
public static final EventBus<Background> BUS = EventBus.create(Background.class);
|
||||
|
||||
private final ResourceLocation originalBackground;
|
||||
private ResourceLocation background;
|
||||
private final @Nullable ResourceLocation originalBackground;
|
||||
private @Nullable ResourceLocation background;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Background(@NotNull ItemStack stack, GuiGraphics graphics, int x, int y, @NotNull Font fr, @NotNull List<ClientTooltipComponent> components, @Nullable ResourceLocation background) {
|
||||
public Background(ItemStack stack, GuiGraphics graphics, int x, int y, Font fr, List<ClientTooltipComponent> components, @Nullable ResourceLocation background) {
|
||||
super(stack, graphics, x, y, fr, components);
|
||||
this.originalBackground = background;
|
||||
this.background = background;
|
||||
@@ -309,21 +291,21 @@ public abstract sealed class RenderTooltipEvent extends MutableEvent implements
|
||||
/**
|
||||
* Sets the new prefix for the background texture
|
||||
*/
|
||||
public void setBackground(ResourceLocation background) {
|
||||
public void setBackground(@Nullable ResourceLocation background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the potentially modified background's prefix, can be null for default
|
||||
*/
|
||||
public ResourceLocation getBackground() {
|
||||
public @Nullable ResourceLocation getBackground() {
|
||||
return this.background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the original tooltip background's prefix, can be null for default
|
||||
*/
|
||||
public ResourceLocation getOriginalBackground() {
|
||||
public @Nullable ResourceLocation getOriginalBackground() {
|
||||
return originalBackground;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,16 @@ 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.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -39,22 +40,12 @@ import java.util.function.Consumer;
|
||||
* @see MouseInput
|
||||
* @see KeyInput
|
||||
*/
|
||||
public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
public static final EventBus<ScreenEvent> BUS = EventBus.create(ScreenEvent.class);
|
||||
|
||||
private final Screen screen;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected ScreenEvent(Screen screen) {
|
||||
this.screen = Objects.requireNonNull(screen);
|
||||
}
|
||||
|
||||
public sealed interface ScreenEvent {
|
||||
/**
|
||||
* {@return the screen that caused this event}
|
||||
*/
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
@NonNull
|
||||
Screen getScreen();
|
||||
|
||||
/**
|
||||
* Fired when a screen is being initialized.
|
||||
@@ -67,7 +58,9 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see Init.Pre
|
||||
* @see Init.Post
|
||||
*/
|
||||
public static abstract sealed class Init extends ScreenEvent {
|
||||
abstract sealed class Init extends MutableEvent implements ScreenEvent {
|
||||
private final Screen screen;
|
||||
|
||||
private final Consumer<GuiEventListener> add;
|
||||
private final Consumer<GuiEventListener> remove;
|
||||
|
||||
@@ -75,12 +68,17 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected Init(Screen screen, List<GuiEventListener> listenerList, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove) {
|
||||
super(screen);
|
||||
this.screen = screen;
|
||||
this.listenerList = Collections.unmodifiableList(listenerList);
|
||||
this.add = add;
|
||||
this.remove = remove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return unmodifiable view of list of event listeners on the screen}
|
||||
*/
|
||||
@@ -109,7 +107,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
/**
|
||||
* Fired <b>before</b> the screen's overridable initialization method is fired.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the initialization method will not be called, and the widgets and children lists
|
||||
* will not be cleared.</p>
|
||||
*
|
||||
@@ -128,7 +126,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
/**
|
||||
* Fired <b>after</b> the screen's overridable initialization method is called.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.</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>
|
||||
@@ -150,82 +148,58 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see Render.Pre
|
||||
* @see Render.Post
|
||||
*/
|
||||
public static abstract sealed class Render extends ScreenEvent {
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final int mouseX;
|
||||
private final int mouseY;
|
||||
private final float partialTick;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected Render(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen);
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
this.partialTick = partialTick;
|
||||
}
|
||||
|
||||
sealed interface Render extends ScreenEvent {
|
||||
/**
|
||||
* {@return the gui graphics used for rendering}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
GuiGraphics getGuiGraphics();
|
||||
|
||||
/**
|
||||
* {@return the X coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
int getMouseX();
|
||||
|
||||
/**
|
||||
* {@return the Y coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
int getMouseY();
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
float getPartialTick();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the screen is drawn.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen will not be drawn.</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>
|
||||
*/
|
||||
public static final class Pre extends Render implements Cancellable {
|
||||
record Pre(Screen getScreen, GuiGraphics getGuiGraphics, int getMouseX, int getMouseY, float getPartialTick)
|
||||
implements Cancellable, Render, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen, guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the screen is drawn.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.</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>
|
||||
*/
|
||||
public static final class Post extends Render {
|
||||
record Post(Screen getScreen, GuiGraphics getGuiGraphics, int getMouseX, int getMouseY, float getPartialTick)
|
||||
implements Render, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen, guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,28 +207,16 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* Fired directly after the background of the screen is drawn.
|
||||
* Can be used for drawing above the background but below the tooltips.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @param getGuiGraphics the gui graphics used for rendering
|
||||
*/
|
||||
public static final class BackgroundRendered extends ScreenEvent {
|
||||
record BackgroundRendered(Screen getScreen, GuiGraphics getGuiGraphics) implements RecordEvent, ScreenEvent {
|
||||
public static final EventBus<BackgroundRendered> BUS = EventBus.create(BackgroundRendered.class);
|
||||
|
||||
private final GuiGraphics guiGraphics;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BackgroundRendered(Screen screen, GuiGraphics guiGraphics) {
|
||||
super(screen);
|
||||
this.guiGraphics = guiGraphics;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gui graphics used for rendering}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
public BackgroundRendered {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,27 +224,32 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* Can be used to select the size of the effects display (full or compact) or even hide or replace vanilla's rendering entirely.
|
||||
* This event can also be used to modify the horizontal position of the stack of effects being rendered.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
|
||||
* Cancelling this event will prevent vanilla rendering.</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}. Cancelling this event will prevent vanilla rendering.</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>
|
||||
*/
|
||||
public static final class RenderInventoryMobEffects extends ScreenEvent implements Cancellable {
|
||||
final class RenderInventoryMobEffects extends MutableEvent implements Cancellable, ScreenEvent {
|
||||
public static final CancellableEventBus<RenderInventoryMobEffects> BUS = CancellableEventBus.create(RenderInventoryMobEffects.class);
|
||||
|
||||
private final Screen screen;
|
||||
private final int availableSpace;
|
||||
private boolean compact;
|
||||
private int horizontalOffset;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderInventoryMobEffects(Screen screen, int availableSpace, boolean compact, int horizontalOffset) {
|
||||
super(screen);
|
||||
this.screen = screen;
|
||||
this.availableSpace = availableSpace;
|
||||
this.compact = compact;
|
||||
this.horizontalOffset = horizontalOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* The available space to the right of the inventory.
|
||||
*/
|
||||
@@ -335,30 +302,16 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see MouseDragged
|
||||
* @see MouseScrolled
|
||||
*/
|
||||
private static abstract sealed class MouseInput extends ScreenEvent {
|
||||
private final double mouseX;
|
||||
private final double mouseY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MouseInput(Screen screen, double mouseX, double mouseY) {
|
||||
super(screen);
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
sealed interface MouseInput extends ScreenEvent {
|
||||
/**
|
||||
* {@return the X position of the mouse cursor, relative to the screen}
|
||||
*/
|
||||
public double getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
double getMouseX();
|
||||
|
||||
/**
|
||||
* {@return the Y position of the mouse cursor, relative to the screen}
|
||||
*/
|
||||
public double getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
double getMouseY();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,49 +321,38 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see MouseButtonPressed.Pre
|
||||
* @see MouseButtonPressed.Post
|
||||
*/
|
||||
public static abstract sealed class MouseButtonPressed extends MouseInput {
|
||||
private final int button;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseButtonPressed(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
sealed interface MouseButtonPressed extends MouseInput {
|
||||
/**
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with 'GLFW_MOUSE_BUTTON_'
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
int getButton();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the mouse click is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's mouse click handler will be bypassed
|
||||
* and the corresponding {@link MouseButtonPressed.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends MouseButtonPressed implements Cancellable {
|
||||
record Pre(Screen getScreen, double getMouseX, double getMouseY, int getButton)
|
||||
implements Cancellable, MouseButtonPressed, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the mouse click is handled, if the corresponding {@link MouseButtonPressed.Pre} was not
|
||||
* cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, {@linkplain HasResult has a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, {@linkplain HasResult has a result}.</p>
|
||||
* <ul>
|
||||
* <li>{@link Result#ALLOW} - forcibly sets the mouse click as handled</li>
|
||||
* <li>{@link Result#DEFAULT} - defaults to the return value of
|
||||
@@ -421,33 +363,26 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Post extends MouseButtonPressed implements HasResult {
|
||||
record Post(
|
||||
Screen getScreen,
|
||||
double getMouseX,
|
||||
double getMouseY,
|
||||
int getButton,
|
||||
boolean wasHandled,
|
||||
Result.Holder resultHolder
|
||||
) implements HasResult.Record, MouseButtonPressed, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
private final boolean handled;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
this(screen, mouseX, mouseY, button, handled, new Result.Holder());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse click was already handled by its screen}
|
||||
*/
|
||||
public boolean wasHandled() {
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
return wasHandled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -459,49 +394,38 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see MouseButtonReleased.Pre
|
||||
* @see MouseButtonReleased.Post
|
||||
*/
|
||||
public static abstract sealed class MouseButtonReleased extends MouseInput {
|
||||
private final int button;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseButtonReleased(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
sealed interface MouseButtonReleased extends MouseInput {
|
||||
/**
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with 'GLFW_MOUSE_BUTTON_'
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
int getButton();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the mouse release is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's mouse release handler will be bypassed
|
||||
* and the corresponding {@link MouseButtonReleased.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends MouseButtonReleased implements Cancellable {
|
||||
record Pre(Screen getScreen, double getMouseX, double getMouseY, int getButton)
|
||||
implements Cancellable, MouseButtonReleased, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the mouse release is handled, if the corresponding {@link MouseButtonReleased.Pre} was
|
||||
* not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, {@linkplain HasResult has a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, {@linkplain HasResult has a result}.</p>
|
||||
* <ul>
|
||||
* <li>{@link Result#ALLOW} - forcibly sets the mouse release as handled</li>
|
||||
* <li>{@link Result#DEFAULT} - defaults to the return value of
|
||||
@@ -512,33 +436,26 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Post extends MouseButtonReleased implements HasResult {
|
||||
record Post(
|
||||
Screen getScreen,
|
||||
double getMouseX,
|
||||
double getMouseY,
|
||||
int getButton,
|
||||
boolean wasHandled,
|
||||
Result.Holder resultHolder
|
||||
) implements MouseButtonReleased, RecordEvent, HasResult.Record {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
private final boolean handled;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
this(screen, mouseX, mouseY, button, handled, new Result.Holder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the mouse release was already handled by its screen
|
||||
*/
|
||||
public boolean wasHandled() {
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
return wasHandled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -550,79 +467,71 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see MouseDragged.Pre
|
||||
* @see MouseDragged.Post
|
||||
*/
|
||||
public static abstract sealed class MouseDragged extends MouseInput {
|
||||
private final int mouseButton;
|
||||
private final double dragX;
|
||||
private final double dragY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseDragged(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.mouseButton = mouseButton;
|
||||
this.dragX = dragX;
|
||||
this.dragY = dragY;
|
||||
}
|
||||
|
||||
sealed interface MouseDragged extends MouseInput {
|
||||
/**
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with 'GLFW_MOUSE_BUTTON_'
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getMouseButton() {
|
||||
return mouseButton;
|
||||
}
|
||||
int getMouseButton();
|
||||
|
||||
/**
|
||||
* {@return amount of mouse drag along the X axis}
|
||||
*/
|
||||
public double getDragX() {
|
||||
return dragX;
|
||||
}
|
||||
double getDragX();
|
||||
|
||||
/**
|
||||
* {@return amount of mouse drag along the Y axis}
|
||||
*/
|
||||
public double getDragY() {
|
||||
return dragY;
|
||||
}
|
||||
double getDragY();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the mouse drag is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's mouse drag handler will be bypassed
|
||||
* and the corresponding {@link MouseDragged.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends MouseDragged implements Cancellable {
|
||||
record Pre(
|
||||
Screen getScreen,
|
||||
double getMouseX,
|
||||
double getMouseY,
|
||||
int getMouseButton,
|
||||
double getDragX,
|
||||
double getDragY
|
||||
) implements Cancellable, MouseDragged, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the mouse drag is handled, if not handled by the screen
|
||||
* and the corresponding {@link MouseDragged.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the mouse drag will be set as handled.</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>
|
||||
*/
|
||||
public static final class Post extends MouseDragged {
|
||||
record Post(
|
||||
Screen getScreen,
|
||||
double getMouseX,
|
||||
double getMouseY,
|
||||
int getMouseButton,
|
||||
double getDragX,
|
||||
double getDragY
|
||||
) implements MouseDragged, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,67 +542,51 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see MouseScrolled.Pre
|
||||
* @see MouseScrolled.Post
|
||||
*/
|
||||
public static abstract sealed class MouseScrolled extends MouseInput {
|
||||
private final double deltaX;
|
||||
private final double deltaY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseScrolled(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
}
|
||||
|
||||
sealed interface MouseScrolled extends MouseInput {
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the vertical direction}
|
||||
*/
|
||||
public double getDeltaX() {
|
||||
return deltaX;
|
||||
}
|
||||
double getDeltaX();
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the horizontal direction}
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return deltaY;
|
||||
}
|
||||
double getDeltaY();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the mouse scroll is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's mouse scroll handler will be bypassed
|
||||
* and the corresponding {@link MouseScrolled.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends MouseScrolled implements Cancellable {
|
||||
record Pre(Screen getScreen, double getMouseX, double getMouseY, double getDeltaX, double getDeltaY)
|
||||
implements Cancellable, MouseScrolled, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY, deltaX, deltaY);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the mouse scroll is handled, if not handled by the screen
|
||||
* and the corresponding {@link MouseScrolled.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the mouse scroll will be set as handled.</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>
|
||||
*/
|
||||
public static final class Post extends MouseScrolled {
|
||||
record Post(Screen getScreen, double getMouseX, double getMouseY, double getDeltaX, double getDeltaY)
|
||||
implements MouseScrolled, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY, deltaX, deltaY);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,19 +599,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see InputConstants
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_key" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
private static abstract sealed class KeyInput extends ScreenEvent {
|
||||
private final int keyCode;
|
||||
private final int scanCode;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected KeyInput(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen);
|
||||
this.keyCode = keyCode;
|
||||
this.scanCode = scanCode;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
sealed interface KeyInput extends ScreenEvent {
|
||||
/**
|
||||
* {@return the {@code GLFW} (platform-agnostic) key code}
|
||||
*
|
||||
@@ -726,9 +607,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see GLFW key constants starting with {@code GLFW_KEY_}
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__keys.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getKeyCode() {
|
||||
return keyCode;
|
||||
}
|
||||
int getKeyCode();
|
||||
|
||||
/**
|
||||
* {@return the platform-specific scan code}
|
||||
@@ -739,9 +618,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
*
|
||||
* @see InputConstants#getKey(int, int)
|
||||
*/
|
||||
public int getScanCode() {
|
||||
return scanCode;
|
||||
}
|
||||
int getScanCode();
|
||||
|
||||
/**
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
@@ -754,9 +631,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
int getModifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,48 +641,41 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see KeyPressed.Pre
|
||||
* @see KeyPressed.Post
|
||||
*/
|
||||
public static abstract sealed class KeyPressed extends KeyInput {
|
||||
@ApiStatus.Internal
|
||||
public KeyPressed(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
sealed interface KeyPressed extends KeyInput {
|
||||
/**
|
||||
* Fired <b>before</b> the key press is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable} and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's key press handler will be bypassed
|
||||
* and the corresponding {@link KeyPressed.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends KeyPressed implements Cancellable {
|
||||
record Pre(Screen getScreen, int getKeyCode, int getScanCode, int getModifiers)
|
||||
implements Cancellable, KeyPressed, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the key press is handled, if not handled by the screen
|
||||
* and the corresponding {@link KeyPressed.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the key press will be set as handled.</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>
|
||||
*/
|
||||
public static final class Post extends KeyPressed implements Cancellable {
|
||||
record Post(Screen getScreen, int getKeyCode, int getScanCode, int getModifiers)
|
||||
implements Cancellable, KeyPressed, RecordEvent {
|
||||
public static final CancellableEventBus<Post> BUS = CancellableEventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,48 +686,41 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see KeyReleased.Pre
|
||||
* @see KeyReleased.Post
|
||||
*/
|
||||
public static abstract sealed class KeyReleased extends KeyInput {
|
||||
@ApiStatus.Internal
|
||||
public KeyReleased(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
sealed interface KeyReleased extends KeyInput {
|
||||
/**
|
||||
* Fired <b>before</b> the key release is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's key release handler will be bypassed
|
||||
* and the corresponding {@link KeyReleased.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends KeyReleased implements Cancellable {
|
||||
record Pre(Screen getScreen, int getKeyCode, int getScanCode, int getModifiers)
|
||||
implements Cancellable, KeyReleased, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the key release is handled, if not handled by the screen
|
||||
* and the corresponding {@link KeyReleased.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the key release will be set as handled.</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>
|
||||
*/
|
||||
public static final class Post extends KeyReleased implements Cancellable {
|
||||
record Post(Screen getScreen, int getKeyCode, int getScanCode, int getModifiers)
|
||||
implements Cancellable, KeyReleased, RecordEvent {
|
||||
public static final CancellableEventBus<Post> BUS = CancellableEventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -871,23 +732,11 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see CharacterTyped.Post
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_char" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public static sealed class CharacterTyped extends ScreenEvent {
|
||||
private final char codePoint;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public CharacterTyped(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen);
|
||||
this.codePoint = codePoint;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
sealed interface CharacterTyped extends ScreenEvent {
|
||||
/**
|
||||
* {@return the character code point}
|
||||
*/
|
||||
public char getCodePoint() {
|
||||
return codePoint;
|
||||
}
|
||||
char getCodePoint();
|
||||
|
||||
/**
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
@@ -900,46 +749,41 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
int getModifiers();
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the character input is handled by the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the screen's character input handler will be bypassed
|
||||
* and the corresponding {@link CharacterTyped.Post} will not be fired.</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>
|
||||
*/
|
||||
public static final class Pre extends CharacterTyped implements Cancellable {
|
||||
record Pre(Screen getScreen, char getCodePoint, int getModifiers)
|
||||
implements Cancellable, CharacterTyped, RecordEvent {
|
||||
public static final CancellableEventBus<Pre> BUS = CancellableEventBus.create(Pre.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen, codePoint, modifiers);
|
||||
}
|
||||
public Pre {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the character input is handled, if not handled by the screen
|
||||
* and the corresponding {@link CharacterTyped.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the character input will be set as handled.</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>
|
||||
*/
|
||||
public static final class Post extends CharacterTyped {
|
||||
record Post(Screen getScreen, char getCodePoint, int getModifiers) implements CharacterTyped, RecordEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen, codePoint, modifiers);
|
||||
}
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,7 +791,7 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* Fired before any {@link Screen} is opened, to allow changing it or preventing it from being opened.
|
||||
* All screen layers on the screen are closed before this event is fired.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* <p>This event is {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the {@code Screen} shall be prevented from opening and any previous screen
|
||||
* will remain open. However, cancelling this event will not prevent the closing of screen layers which happened before
|
||||
* this event fired.</p>
|
||||
@@ -955,20 +799,25 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Opening extends ScreenEvent implements Cancellable {
|
||||
final class Opening extends MutableEvent implements Cancellable, ScreenEvent {
|
||||
public static final CancellableEventBus<Opening> BUS = CancellableEventBus.create(Opening.class);
|
||||
|
||||
@Nullable
|
||||
private final Screen currentScreen;
|
||||
private final Screen screen;
|
||||
private final @Nullable Screen currentScreen;
|
||||
private Screen newScreen;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Opening(@Nullable Screen currentScreen, Screen screen) {
|
||||
super(screen);
|
||||
this.screen = screen;
|
||||
this.currentScreen = currentScreen;
|
||||
this.newScreen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently open screen at the time of the event being fired.
|
||||
* <p>
|
||||
@@ -999,17 +848,15 @@ public abstract sealed class ScreenEvent extends MutableEvent {
|
||||
* Fired before a {@link Screen} is closed.
|
||||
* All screen layers on the screen are closed before this event is fired.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.</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>
|
||||
*/
|
||||
public static final class Closing extends ScreenEvent {
|
||||
record Closing(Screen getScreen) implements ScreenEvent, RecordEvent {
|
||||
public static final EventBus<Closing> BUS = EventBus.create(Closing.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Closing(Screen screen) {
|
||||
super(screen);
|
||||
}
|
||||
public Closing {}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
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;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Fired after a texture atlas is stitched together.
|
||||
@@ -19,38 +19,26 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* @see TextureStitchEvent.Post
|
||||
* @see TextureAtlas
|
||||
*/
|
||||
public sealed class TextureStitchEvent extends MutableEvent implements IModBusEvent, InheritableEvent {
|
||||
private final TextureAtlas atlas;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public TextureStitchEvent(TextureAtlas atlas) {
|
||||
this.atlas = atlas;
|
||||
}
|
||||
|
||||
@NullMarked
|
||||
public sealed interface TextureStitchEvent {
|
||||
/**
|
||||
* {@return the texture atlas}
|
||||
*/
|
||||
public TextureAtlas getAtlas() {
|
||||
return atlas;
|
||||
}
|
||||
TextureAtlas getAtlas();
|
||||
|
||||
// Use atlas info JSON files instead
|
||||
// /**
|
||||
// * <p>Fired <b>before</b> a texture atlas is stitched together.
|
||||
// * This can be used to add custom sprites to be stitched into the atlas.</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 static class Pre extends TextureStitchEvent
|
||||
// {
|
||||
// public static class Pre extends TextureStitchEvent {
|
||||
// private final Set<ResourceLocation> sprites;
|
||||
//
|
||||
// @ApiStatus.Internal
|
||||
// public Pre(TextureAtlas map, Set<ResourceLocation> sprites)
|
||||
// {
|
||||
// public Pre(TextureAtlas map, Set<ResourceLocation> sprites) {
|
||||
// super(map);
|
||||
// this.sprites = sprites;
|
||||
// }
|
||||
@@ -63,8 +51,7 @@ public sealed class TextureStitchEvent extends MutableEvent implements IModBusEv
|
||||
// *
|
||||
// * @param sprite the location of the sprite
|
||||
// */
|
||||
// public boolean addSprite(ResourceLocation sprite)
|
||||
// {
|
||||
// public boolean addSprite(ResourceLocation sprite) {
|
||||
// return this.sprites.add(sprite);
|
||||
// }
|
||||
// }
|
||||
@@ -72,15 +59,14 @@ public sealed class TextureStitchEvent extends MutableEvent implements IModBusEv
|
||||
/**
|
||||
* Fired <b>after</b> a texture atlas is stitched together and all textures therein has been loaded.
|
||||
*
|
||||
* <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>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class Post extends TextureStitchEvent {
|
||||
@ApiStatus.Internal
|
||||
public Post(TextureAtlas map) {
|
||||
super(map);
|
||||
record Post(TextureAtlas getAtlas) implements TextureStitchEvent, IModBusEvent {
|
||||
public static EventBus<Post> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, Post.class);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post {}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.world.level.material.FogType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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 net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -33,40 +33,21 @@ import org.joml.Vector4f;
|
||||
* @see ComputeCameraAngles
|
||||
* @see ComputeFov
|
||||
*/
|
||||
public abstract sealed class ViewportEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<ViewportEvent> BUS = EventBus.create(ViewportEvent.class);
|
||||
|
||||
private final GameRenderer renderer;
|
||||
private final Camera camera;
|
||||
private final double partialTick;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ViewportEvent(GameRenderer renderer, Camera camera, double partialTick) {
|
||||
this.renderer = renderer;
|
||||
this.camera = camera;
|
||||
this.partialTick = partialTick;
|
||||
}
|
||||
|
||||
public sealed interface ViewportEvent {
|
||||
/**
|
||||
* {@return the game renderer}
|
||||
*/
|
||||
public GameRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
GameRenderer getRenderer();
|
||||
|
||||
/**
|
||||
* {@return the camera information}
|
||||
*/
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
Camera getCamera();
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public double getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
float getPartialTick();
|
||||
|
||||
/**
|
||||
* Fired for <b>rendering</b> custom fog. The plane distances are based on the player's render distance.
|
||||
@@ -77,35 +58,30 @@ public abstract sealed class ViewportEvent extends MutableEvent implements Inher
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class RenderFog extends ViewportEvent implements Cancellable {
|
||||
record RenderFog(
|
||||
GameRenderer getRenderer,
|
||||
Camera getCamera,
|
||||
float getPartialTick,
|
||||
FogType getType,
|
||||
FogData getData,
|
||||
Vector4f getColor
|
||||
) implements Cancellable, ViewportEvent, RecordEvent {
|
||||
public static final CancellableEventBus<RenderFog> BUS = CancellableEventBus.create(RenderFog.class);
|
||||
|
||||
private final FogType type;
|
||||
private final FogData data;
|
||||
private final Vector4f color;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@ApiStatus.Internal
|
||||
public RenderFog(FogType type, Camera camera, float partialTicks, FogData data, Vector4f color) {
|
||||
super(Minecraft.getInstance().gameRenderer, camera, partialTicks);
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
this.color = color;
|
||||
this(Minecraft.getInstance().gameRenderer, camera, partialTicks, type, data, color);
|
||||
}
|
||||
|
||||
public FogData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public Vector4f getColor() {
|
||||
return color;
|
||||
}
|
||||
@ApiStatus.Internal
|
||||
public RenderFog {}
|
||||
|
||||
/**
|
||||
* {@return the type of fog being rendered}
|
||||
*/
|
||||
public FogType getType() {
|
||||
return type;
|
||||
return getType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,9 +145,12 @@ public abstract sealed class ViewportEvent extends MutableEvent implements Inher
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class ComputeFogColor extends ViewportEvent {
|
||||
final class ComputeFogColor extends MutableEvent implements ViewportEvent {
|
||||
public static final EventBus<ComputeFogColor> BUS = EventBus.create(ComputeFogColor.class);
|
||||
|
||||
private final GameRenderer renderer;
|
||||
private final Camera camera;
|
||||
private final float partialTicks;
|
||||
private float red;
|
||||
private float green;
|
||||
private float blue;
|
||||
@@ -179,12 +158,29 @@ public abstract sealed class ViewportEvent extends MutableEvent implements Inher
|
||||
@SuppressWarnings("resource")
|
||||
@ApiStatus.Internal
|
||||
public ComputeFogColor(Camera camera, float partialTicks, float red, float green, float blue) {
|
||||
super(Minecraft.getInstance().gameRenderer, camera, partialTicks);
|
||||
this.renderer = Minecraft.getInstance().gameRenderer;
|
||||
this.camera = camera;
|
||||
this.partialTicks = partialTicks;
|
||||
this.setRed(red);
|
||||
this.setGreen(green);
|
||||
this.setBlue(blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPartialTick() {
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the red color value of the fog}
|
||||
*/
|
||||
@@ -243,21 +239,41 @@ public abstract sealed class ViewportEvent extends MutableEvent implements Inher
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static final class ComputeCameraAngles extends ViewportEvent {
|
||||
final class ComputeCameraAngles extends MutableEvent implements ViewportEvent {
|
||||
public static final EventBus<ComputeCameraAngles> BUS = EventBus.create(ComputeCameraAngles.class);
|
||||
|
||||
private final GameRenderer renderer;
|
||||
private final Camera camera;
|
||||
private final float partialTicks;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ComputeCameraAngles(GameRenderer renderer, Camera camera, double renderPartialTicks, float yaw, float pitch, float roll) {
|
||||
super(renderer, camera, renderPartialTicks);
|
||||
public ComputeCameraAngles(GameRenderer renderer, Camera camera, float renderPartialTicks, float yaw, float pitch, float roll) {
|
||||
this.renderer = renderer;
|
||||
this.camera = camera;
|
||||
this.partialTicks = renderPartialTicks;
|
||||
this.setYaw(yaw);
|
||||
this.setPitch(pitch);
|
||||
this.setRoll(roll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPartialTick() {
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the yaw of the player's camera}
|
||||
*/
|
||||
@@ -318,19 +334,39 @@ public abstract sealed class ViewportEvent extends MutableEvent implements Inher
|
||||
*
|
||||
* @see ComputeFovModifierEvent
|
||||
*/
|
||||
public static final class ComputeFov extends ViewportEvent {
|
||||
final class ComputeFov extends MutableEvent implements ViewportEvent {
|
||||
public static final EventBus<ComputeFov> BUS = EventBus.create(ComputeFov.class);
|
||||
|
||||
private final GameRenderer renderer;
|
||||
private final Camera camera;
|
||||
private final float partialTicks;
|
||||
private final boolean usedConfiguredFov;
|
||||
private float fov;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ComputeFov(GameRenderer renderer, Camera camera, double renderPartialTicks, float fov, boolean usedConfiguredFov) {
|
||||
super(renderer, camera, renderPartialTicks);
|
||||
public ComputeFov(GameRenderer renderer, Camera camera, float renderPartialTicks, float fov, boolean usedConfiguredFov) {
|
||||
this.renderer = renderer;
|
||||
this.camera = camera;
|
||||
this.partialTicks = renderPartialTicks;
|
||||
this.usedConfiguredFov = usedConfiguredFov;
|
||||
this.setFOV(fov);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPartialTick() {
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the raw field of view value}
|
||||
*/
|
||||
|
||||
@@ -7,8 +7,8 @@ package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
@@ -19,29 +19,32 @@ import org.jspecify.annotations.Nullable;
|
||||
* others). This can be used to change or prevent (by passing {@code null)} a sound from being played through
|
||||
* {@link #setSound(SoundInstance)}).
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancellable cancellable}, and does not {@linkplain HasResult have a result}.</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>
|
||||
*
|
||||
* @see PlaySoundSourceEvent
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public final class PlaySoundEvent extends SoundEvent {
|
||||
public final class PlaySoundEvent extends MutableEvent implements SoundEvent {
|
||||
public static final EventBus<PlaySoundEvent> BUS = EventBus.create(PlaySoundEvent.class);
|
||||
|
||||
private final SoundEngine manager;
|
||||
private final String name;
|
||||
private final SoundInstance originalSound;
|
||||
private @Nullable SoundInstance sound;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlaySoundEvent(SoundEngine manager, SoundInstance sound) {
|
||||
super(manager);
|
||||
this.manager = manager;
|
||||
this.originalSound = sound;
|
||||
this.name = sound.getLocation().getPath();
|
||||
this.setSound(sound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEngine getEngine() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the name of the original sound} This is equivalent to the path of the location of the original sound.
|
||||
*/
|
||||
|
||||
@@ -19,18 +19,20 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* in a buffer before being played, and used for most sounds of short length such as sound effects for clicking
|
||||
* buttons.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public final class PlaySoundSourceEvent extends SoundSourceEvent {
|
||||
public record PlaySoundSourceEvent(SoundEngine getEngine, SoundInstance getSound, Channel getChannel, String getName)
|
||||
implements SoundSourceEvent {
|
||||
public static final EventBus<PlaySoundSourceEvent> BUS = EventBus.create(PlaySoundSourceEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlaySoundSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel) {
|
||||
super(engine, sound, channel);
|
||||
this(engine, sound, channel, sound.getLocation().getPath());
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlaySoundSourceEvent {}
|
||||
}
|
||||
@@ -19,18 +19,20 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* (such as a file), and used for sounds of long length which are unsuitable to keep fully loaded in-memory in a buffer
|
||||
* (as is done for regular non-streaming sounds), such as background music or music discs.
|
||||
*
|
||||
* <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 MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public final class PlayStreamingSourceEvent extends SoundSourceEvent {
|
||||
public record PlayStreamingSourceEvent(SoundEngine getEngine, SoundInstance getSound, Channel getChannel, String getName)
|
||||
implements SoundSourceEvent {
|
||||
public static final EventBus<PlayStreamingSourceEvent> BUS = EventBus.create(PlayStreamingSourceEvent.class);
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayStreamingSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel) {
|
||||
super(engine, sound, channel);
|
||||
this(engine, sound, channel, sound.getLocation().getPath());
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayStreamingSourceEvent {}
|
||||
}
|
||||
@@ -6,31 +6,23 @@
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Fired when the {@link SoundEngine} is constructed or (re)loaded, such as during game initialization or when the sound
|
||||
* output device is changed.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancellable 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>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public final class SoundEngineLoadEvent extends SoundEvent implements IModBusEvent {
|
||||
public record SoundEngineLoadEvent(SoundEngine getEngine) implements IModBusEvent, SoundEvent {
|
||||
public static EventBus<SoundEngineLoadEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, SoundEngineLoadEvent.class);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public SoundEngineLoadEvent(SoundEngine manager) {
|
||||
super(manager);
|
||||
}
|
||||
public SoundEngineLoadEvent {}
|
||||
}
|
||||
@@ -25,22 +25,11 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* @see PlaySoundEvent
|
||||
* @see SoundEngineLoadEvent
|
||||
*/
|
||||
public abstract class SoundEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<SoundEvent> BUS = EventBus.create(SoundEvent.class);
|
||||
|
||||
private final SoundEngine engine;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected SoundEvent(SoundEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public sealed interface SoundEvent permits PlaySoundEvent, SoundEngineLoadEvent, SoundEvent.SoundSourceEvent {
|
||||
/**
|
||||
* {@return the sound engine}
|
||||
*/
|
||||
public SoundEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
SoundEngine getEngine();
|
||||
|
||||
/**
|
||||
* Superclass for when a sound has started to play on an audio channel.
|
||||
@@ -51,40 +40,22 @@ public abstract class SoundEvent extends MutableEvent implements InheritableEven
|
||||
* @see PlaySoundSourceEvent
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public static abstract class SoundSourceEvent extends SoundEvent {
|
||||
public static final EventBus<SoundSourceEvent> BUS = EventBus.create(SoundSourceEvent.class);
|
||||
|
||||
private final SoundInstance sound;
|
||||
private final Channel channel;
|
||||
private final String name;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected SoundSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel) {
|
||||
super(engine);
|
||||
this.name = sound.getLocation().getPath();
|
||||
this.sound = sound;
|
||||
this.channel = channel;
|
||||
}
|
||||
sealed interface SoundSourceEvent extends SoundEvent, InheritableEvent permits PlaySoundSourceEvent, PlayStreamingSourceEvent {
|
||||
EventBus<SoundSourceEvent> BUS = EventBus.create(SoundSourceEvent.class);
|
||||
|
||||
/**
|
||||
* {@return the sound being played}
|
||||
*/
|
||||
public SoundInstance getSound() {
|
||||
return sound;
|
||||
}
|
||||
SoundInstance getSound();
|
||||
|
||||
/**
|
||||
* {@return the audio channel on which the sound is playing on}
|
||||
*/
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
Channel getChannel();
|
||||
|
||||
/**
|
||||
* {@return the name of the sound being played} This is equivalent to the path of the location of the original sound.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
String getName();
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,7 @@
|
||||
/**
|
||||
* Client-only events relating to sounds.
|
||||
*/
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
@NullMarked
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.FieldsAreNonnullByDefault;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -25,7 +25,11 @@ public interface IForgeKeyMapping {
|
||||
* {@return true if the key conflict context and modifier are active and the keyCode matches this binding, false otherwise}
|
||||
*/
|
||||
default boolean isActiveAndMatches(InputConstants.Key keyCode) {
|
||||
return keyCode != InputConstants.UNKNOWN && keyCode.equals(getKey()) && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
return keyCode != InputConstants.UNKNOWN && keyCode.equals(getKey()) && isActive();
|
||||
}
|
||||
|
||||
default boolean isActive() {
|
||||
return getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
}
|
||||
|
||||
default void setToDefault() {
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.IArmPoseTransformer;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -119,7 +118,7 @@ public interface IClientItemExtensions {
|
||||
default Model getGenericArmorModel(HumanoidRenderState state, ItemStack itemStack, EquipmentSlot equipmentSlot, HumanoidModel<?> original) {
|
||||
HumanoidModel<?> replacement = getHumanoidArmorModel(state, itemStack, equipmentSlot, original);
|
||||
if (replacement != original) {
|
||||
ForgeHooksClient.copyModelProperties(original, replacement);
|
||||
//ForgeHooksClient.copyModelProperties(original, replacement);
|
||||
return replacement;
|
||||
}
|
||||
return original;
|
||||
|
||||
@@ -40,7 +40,7 @@ public final class ClientTooltipComponentManager {
|
||||
public static void init() {
|
||||
var factories = new HashMap<Class<? extends TooltipComponent>, Function<TooltipComponent, ClientTooltipComponent>>();
|
||||
var event = new RegisterClientTooltipComponentFactoriesEvent(factories);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
FACTORIES = ImmutableMap.copyOf(factories);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,9 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean p_194999_5_, final float partialTick) {
|
||||
public void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
|
||||
int top = this.getContentY();
|
||||
int left = this.getContentX();
|
||||
var mc = Minecraft.getInstance();
|
||||
Font font = mc.font;
|
||||
var strings = font.split(message, LoadingEntryList.this.width - 20);
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
@@ -203,13 +204,13 @@ public class ModListScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(final double mouseX, final double mouseY, final int button) {
|
||||
final Style component = findTextLine((int) mouseX, (int) mouseY);
|
||||
public boolean mouseClicked(MouseButtonEvent info, boolean recent) {
|
||||
final Style component = findTextLine((int)info.x(), (int)info.y());
|
||||
if (component != null) {
|
||||
ModListScreen.this.handleComponentClicked(component);
|
||||
return true;
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
return super.mouseClicked(info, recent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.MultiLineLabel;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
@@ -101,7 +102,7 @@ public class ModMismatchDisconnectedScreen extends Screen {
|
||||
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
int textYOffset = hasMismatches ? 18 : 0;
|
||||
guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, (this.height - this.listHeight - this.textHeight) / 2 - textYOffset - 9 * 2, 0xAAAAAA);
|
||||
this.message.renderCentered(guiGraphics, this.width / 2, (this.height - this.listHeight - this.textHeight) / 2 - textYOffset);
|
||||
this.message.render(guiGraphics, MultiLineLabel.Align.CENTER, this.width / 2, (this.height - this.listHeight - this.textHeight) / 2 - textYOffset, 9, true, -1);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@@ -293,13 +294,13 @@ public class ModMismatchDisconnectedScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(final double mouseX, final double mouseY, final int button) {
|
||||
Style style = getComponentStyleAt(mouseX, mouseY);
|
||||
public boolean mouseClicked(MouseButtonEvent info, boolean recent) {
|
||||
Style style = getComponentStyleAt(info.x(), info.y());
|
||||
if (style != null) {
|
||||
handleComponentClicked(style);
|
||||
return true;
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
return super.mouseClicked(info, recent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -394,17 +394,20 @@ public final class ForgeLayeredDraw implements ForgeLayer {
|
||||
.add(BOSS_OVERLAY, gui::renderBossOverlay);
|
||||
var postSleepDraw = new ForgeLayeredDraw(POST_SLEEP_STACK)
|
||||
.add(DEMO_OVERLAY, gui::renderDemoOverlay)
|
||||
.add(DEBUG_OVERLAY, gui::renderDebugOverlay)
|
||||
.add(SCOREBOARD, gui::renderScoreboardSidebar)
|
||||
.add(HOTBAR_MESSAGE, gui::renderOverlayMessage)
|
||||
.add(TITLE_OVERLAY, gui::renderTitle)
|
||||
.add(CHAT_OVERLAY, gui::renderChat)
|
||||
.add(TAB_LIST, gui::renderTabList)
|
||||
.add(SUBTITLE_OVERLAY, gui::renderSubtitleOverlay);
|
||||
.add(SUBTITLE_OVERLAY, (gfx, delta) -> gui.renderSubtitleOverlay(gfx, minecraft.screen != null && minecraft.screen.isInGameUi()));
|
||||
instance
|
||||
.add(PRE_SLEEP_STACK, preSleepDraw, () -> !minecraft.options.hideGui)
|
||||
.add(SLEEP_OVERLAY, gui::renderSleepOverlay)
|
||||
.add(POST_SLEEP_STACK, postSleepDraw, () -> !minecraft.options.hideGui);
|
||||
.add(POST_SLEEP_STACK, postSleepDraw, () -> !minecraft.options.hideGui)
|
||||
.add(SUBTITLE_OVERLAY, (gfx, delta) -> {
|
||||
if (minecraft.options.hideGui && minecraft.screen != null && minecraft.screen.isInGameUi())
|
||||
gui.renderSubtitleOverlay(gfx, true);
|
||||
});
|
||||
instance.resolveLayers();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ package net.minecraftforge.client.gui.widget;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||
import net.minecraft.client.input.KeyEvent;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
@@ -121,20 +123,20 @@ public class ForgeSlider extends AbstractSliderButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
this.setValueFromMouse(mouseX);
|
||||
public void onClick(MouseButtonEvent info, boolean recent) {
|
||||
this.setValueFromMouse(info.x());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) {
|
||||
super.onDrag(mouseX, mouseY, dragX, dragY);
|
||||
this.setValueFromMouse(mouseX);
|
||||
protected void onDrag(MouseButtonEvent info, double dragX, double dragY) {
|
||||
super.onDrag(info, dragX, dragY);
|
||||
this.setValueFromMouse(info.x());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
boolean flag = keyCode == GLFW.GLFW_KEY_LEFT;
|
||||
if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||
public boolean keyPressed(KeyEvent info) {
|
||||
boolean flag = info.key() == GLFW.GLFW_KEY_LEFT;
|
||||
if (flag || info.key() == GLFW.GLFW_KEY_RIGHT) {
|
||||
if (this.minValue > this.maxValue)
|
||||
flag = !flag;
|
||||
float f = flag ? -1F : 1F;
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.client.gui.widget;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -44,12 +45,14 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderSelection(GuiGraphics gui, int top, int rowWidth, int height, int borderColor, int backgroundColor) {
|
||||
int barOffset = this.scrollbarVisible() ? 6 : 0;
|
||||
int left = this.getX() + (this.width - rowWidth) / 2;
|
||||
int right = this.getX() + (this.width + rowWidth) / 2 - barOffset;
|
||||
gui.fill(left, top - 2, right, top + height + 2, borderColor);
|
||||
gui.fill(left + 1, top - 1, right - 1, top + height + 1, backgroundColor);
|
||||
protected void renderSelection(GuiGraphics gui, ModListWidget.ModEntry entry, int color) {
|
||||
int widthOffset = this.scrollbarVisible() ? 11 : 4;
|
||||
int top = entry.getContentY();
|
||||
int left = entry.getContentX();
|
||||
int right = left + entry.getWidth() - widthOffset;
|
||||
int bottom = top + entry.getHeight();
|
||||
gui.fill(left, top - 2, right, bottom + 2, color);
|
||||
gui.fill(left + 1, top - 1, right - 1, bottom + 1, /*backgroundColor*/ 0xFF000000);
|
||||
}
|
||||
|
||||
public void refreshList() {
|
||||
@@ -72,7 +75,11 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
|
||||
public void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, boolean isMouseOver, float partialTick) {
|
||||
int top = this.getContentY();
|
||||
int left = this.getContentX();
|
||||
int entryHeight = this.getContentBottom();
|
||||
|
||||
Component name = Component.literal(stripControlCodes(modInfo.getDisplayName()));
|
||||
Component version = Component.literal(stripControlCodes(MavenVersionStringHelper.artifactVersionToString(modInfo.getVersion())));
|
||||
VersionChecker.CheckResult vercheck = VersionChecker.getResult(modInfo);
|
||||
@@ -90,7 +97,7 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
|
||||
public boolean mouseClicked(MouseButtonEvent info, boolean recent) {
|
||||
parent.setSelected(this);
|
||||
ModListWidget.this.setSelected(this);
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
import net.minecraft.client.input.MouseButtonEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -196,23 +197,23 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (super.mouseClicked(mouseX, mouseY, button))
|
||||
public boolean mouseClicked(MouseButtonEvent info, boolean recent) {
|
||||
if (super.mouseClicked(info, recent))
|
||||
return true;
|
||||
|
||||
this.scrolling = button == 0 && mouseX >= barLeft && mouseX < barLeft + barWidth;
|
||||
this.scrolling = info.button() == 0 && info.x() >= barLeft && info.x() < barLeft + barWidth;
|
||||
if (this.scrolling)
|
||||
return true;
|
||||
|
||||
int mouseListY = ((int)mouseY) - this.top - this.getContentHeight() + (int)this.scrollDistance - border;
|
||||
if (mouseX >= left && mouseX <= right && mouseListY < 0)
|
||||
return this.clickPanel(mouseX - left, mouseY - this.top + (int)this.scrollDistance - border, button);
|
||||
int mouseListY = ((int)info.y()) - this.top - this.getContentHeight() + (int)this.scrollDistance - border;
|
||||
if (info.x() >= left && info.x() <= right && mouseListY < 0)
|
||||
return this.clickPanel(info.x() - left, info.y() - this.top + (int)this.scrollDistance - border, info.button());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (super.mouseReleased(mouseX, mouseY, button))
|
||||
public boolean mouseReleased(MouseButtonEvent info) {
|
||||
if (super.mouseReleased(info))
|
||||
return true;
|
||||
|
||||
boolean ret = this.scrolling;
|
||||
@@ -232,7 +233,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
public boolean mouseDragged(MouseButtonEvent info, double deltaX, double deltaY) {
|
||||
if (this.scrolling) {
|
||||
int maxScroll = height - getBarHeight();
|
||||
double moved = deltaY / maxScroll;
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.*;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener.SharedState;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraftforge.event.AddPackFindersEvent;
|
||||
@@ -26,7 +26,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.client.gui.LoadingErrorScreen;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
import net.minecraftforge.server.LanguageHook;
|
||||
@@ -49,14 +48,14 @@ public class ClientModLoader {
|
||||
createRunnableWithCatch(()->ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ImmediateWindowHandler::renderTick)).run();
|
||||
if (error == null) {
|
||||
ResourcePackLoader.loadResourcePacks(defaultResourcePacks, true);
|
||||
ModLoader.get().postEvent(new AddPackFindersEvent(PackType.CLIENT_RESOURCES, defaultResourcePacks::addPackFinder));
|
||||
ModLoader.postEvent(new AddPackFindersEvent(PackType.CLIENT_RESOURCES, defaultResourcePacks::addPackFinder));
|
||||
DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getPackNames());
|
||||
mcResourceManager.registerReloadListener(ClientModLoader::onResourceReload);
|
||||
mcResourceManager.registerReloadListener(BrandingControl.resourceManagerReloadListener());
|
||||
}
|
||||
}
|
||||
|
||||
private static CompletableFuture<Void> onResourceReload(final PreparableReloadListener.PreparationBarrier stage, final ResourceManager resourceManager, final Executor asyncExecutor, final Executor syncExecutor) {
|
||||
private static CompletableFuture<Void> onResourceReload(SharedState state, final Executor asyncExecutor, final PreparableReloadListener.PreparationBarrier stage, final Executor syncExecutor) {
|
||||
return CompletableFuture.runAsync(createRunnableWithCatch(() -> startModLoading(ModWorkManager.wrappedExecutor(syncExecutor), asyncExecutor)), ModWorkManager.parallelExecutor())
|
||||
.thenCompose(stage::wait)
|
||||
.thenRunAsync(() -> finishModLoading(ModWorkManager.wrappedExecutor(syncExecutor), asyncExecutor), ModWorkManager.parallelExecutor());
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ModelDataManager {
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(ChunkPos pos) {
|
||||
Preconditions.checkArgument(level.isClientSide, "Cannot request model data for server level");
|
||||
Preconditions.checkArgument(level.isClientSide(), "Cannot request model data for server level");
|
||||
refreshAt(pos);
|
||||
return modelDataCache.getOrDefault(pos, Collections.emptyMap());
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class GeometryLoaderManager {
|
||||
public static void init() {
|
||||
var loaders = new HashMap<ResourceLocation, IGeometryLoader>();
|
||||
var event = new ModelEvent.RegisterGeometryLoaders(loaders);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
LOADERS = ImmutableMap.copyOf(loaders);
|
||||
LOADER_LIST = loaders.keySet().stream().map(ResourceLocation::toString).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.input.InputQuirks;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -20,21 +21,17 @@ public enum KeyModifier {
|
||||
CONTROL {
|
||||
@Override
|
||||
public boolean matches(InputConstants.Key key) {
|
||||
int keyCode = key.getValue();
|
||||
if (Minecraft.ON_OSX)
|
||||
return keyCode == GLFW.GLFW_KEY_LEFT_SUPER || keyCode == GLFW.GLFW_KEY_RIGHT_SUPER;
|
||||
else
|
||||
return keyCode == GLFW.GLFW_KEY_LEFT_CONTROL || keyCode == GLFW.GLFW_KEY_RIGHT_CONTROL;
|
||||
return key.getValue() == InputQuirks.EDIT_SHORTCUT_KEY_LEFT || key.getValue() == InputQuirks.EDIT_SHORTCUT_KEY_RIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext) {
|
||||
return Screen.hasControlDown();
|
||||
return Minecraft.getInstance().hasControlDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getCombinedName(InputConstants.Key key, Supplier<Component> defaultLogic) {
|
||||
String localizationFormatKey = Minecraft.ON_OSX ? "forge.controlsgui.control.mac" : "forge.controlsgui.control";
|
||||
String localizationFormatKey = InputQuirks.REPLACE_CTRL_KEY_WITH_CMD_KEY ? "forge.controlsgui.control.mac" : "forge.controlsgui.control";
|
||||
return Component.translatable(localizationFormatKey, defaultLogic.get());
|
||||
}
|
||||
},
|
||||
@@ -46,7 +43,7 @@ public enum KeyModifier {
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext) {
|
||||
return Screen.hasShiftDown();
|
||||
return Minecraft.getInstance().hasShiftDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +59,7 @@ public enum KeyModifier {
|
||||
|
||||
@Override
|
||||
public boolean isActive(@Nullable IKeyConflictContext conflictContext) {
|
||||
return Screen.hasAltDown();
|
||||
return Minecraft.getInstance().hasAltDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,9 +10,12 @@ import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.metadata.MetadataSectionType;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
import net.minecraftforge.client.event.RegisterTextureAtlasSpriteLoadersEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -30,7 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @see RegisterTextureAtlasSpriteLoadersEvent
|
||||
*/
|
||||
public interface ITextureAtlasSpriteLoader {
|
||||
SpriteContents loadContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, ResourceMetadata animationMeta, ForgeTextureMetadata forgeMeta);
|
||||
SpriteContents loadContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, List<MetadataSectionType.WithValue<?>> metadata);
|
||||
|
||||
/**
|
||||
* Creates a {@link TextureAtlasSprite} from the given {@link SpriteContents}.
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public final class TextureAtlasSpriteLoaderManager {
|
||||
public static void init() {
|
||||
var loaders = HashBiMap.<ResourceLocation, ITextureAtlasSpriteLoader>create();
|
||||
var event = new RegisterTextureAtlasSpriteLoadersEvent(loaders);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
ModLoader.postEventWrapContainerInModOrder(event);
|
||||
LOADERS = ImmutableBiMap.copyOf(loaders);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
|
||||
/**
|
||||
* A helper sprite with UVs spanning the entire texture.
|
||||
@@ -22,7 +21,7 @@ public class UnitTextureAtlasSprite extends TextureAtlasSprite {
|
||||
public static final UnitTextureAtlasSprite INSTANCE = new UnitTextureAtlasSprite();
|
||||
|
||||
private UnitTextureAtlasSprite() {
|
||||
super(LOCATION, new SpriteContents(LOCATION, new FrameSize(1, 1), new NativeImage(1, 1, false), ResourceMetadata.EMPTY, null), 1, 1, 0, 0);
|
||||
super(LOCATION, new SpriteContents(LOCATION, new FrameSize(1, 1), new NativeImage(1, 1, false)), 1, 1, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FarmlandWaterManager
|
||||
@SuppressWarnings("unchecked")
|
||||
public static<T extends SimpleTicket<Vec3>> T addCustomTicket(Level level, T ticket, ChunkPos masterChunk, ChunkPos... additionalChunks)
|
||||
{
|
||||
Preconditions.checkArgument(!level.isClientSide, "Water region is only determined server-side");
|
||||
Preconditions.checkArgument(!level.isClientSide(), "Water region is only determined server-side");
|
||||
Map<ChunkPos, ChunkTicketManager<Vec3>> ticketMap = customWaterHandler.computeIfAbsent(level, id -> new MapMaker().weakValues().makeMap());
|
||||
ChunkTicketManager<Vec3>[] additionalTickets = new ChunkTicketManager[additionalChunks.length];
|
||||
for (int i = 0; i < additionalChunks.length; i++)
|
||||
|
||||
@@ -102,7 +102,6 @@ import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
@@ -322,14 +321,14 @@ public final class ForgeHooks {
|
||||
if (ItemTossEvent.BUS.post(event))
|
||||
return null;
|
||||
|
||||
if (!player.level().isClientSide)
|
||||
if (!player.level().isClientSide())
|
||||
player.level().addFreshEntity(event.getEntity());
|
||||
return event.getEntity();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatSubmittedEvent(ServerPlayer player, Component message) {
|
||||
var plain = message.getContents() instanceof LiteralContents literalContents ? literalContents.text() : "";
|
||||
var plain = message.getContents() instanceof LiteralContents(String text) ? text : "";
|
||||
var event = new ServerChatEvent(player, plain, message);
|
||||
return ServerChatEvent.BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
@@ -694,10 +693,13 @@ public final class ForgeHooks {
|
||||
var potion = itemStack.get(DataComponents.POTION_CONTENTS).potion().orElse(null);
|
||||
if (potion != null && potion.unwrapKey().isPresent())
|
||||
return potion.unwrapKey().get().location().getNamespace();
|
||||
} else if (item instanceof SpawnEggItem egg) {
|
||||
var resourceLocation = EntityType.getKey(egg.getDefaultType());
|
||||
if (resourceLocation != null)
|
||||
return resourceLocation.getNamespace();
|
||||
} else if (item instanceof SpawnEggItem) {
|
||||
var data = item.components().get(DataComponents.ENTITY_DATA);
|
||||
if (data != null && data.type() != null) {
|
||||
var resourceLocation = EntityType.getKey(data.type());
|
||||
if (resourceLocation != null)
|
||||
return resourceLocation.getNamespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return modId;
|
||||
@@ -788,9 +790,9 @@ public final class ForgeHooks {
|
||||
|
||||
@Deprecated
|
||||
public static void modifyAttributes() {
|
||||
ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
|
||||
ModLoader.postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
|
||||
Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> finalMap = new HashMap<>();
|
||||
ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
|
||||
ModLoader.postEvent(new EntityAttributeModificationEvent(finalMap));
|
||||
|
||||
finalMap.forEach((k, v) -> {
|
||||
AttributeSupplier supplier = DefaultAttributes.getSupplier(k);
|
||||
@@ -858,7 +860,7 @@ public final class ForgeHooks {
|
||||
}
|
||||
|
||||
final var mismatchEvent = new ModMismatchEvent(levelDirectory, mismatchedVersions, missingVersions);
|
||||
ModLoader.get().postEvent(mismatchEvent);
|
||||
ModLoader.postEvent(mismatchEvent);
|
||||
|
||||
StringBuilder resolved = new StringBuilder("The following mods have version differences that were marked resolved:");
|
||||
StringBuilder unresolved = new StringBuilder("The following mods have version differences that were not resolved:");
|
||||
@@ -1043,7 +1045,7 @@ public final class ForgeHooks {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAir && !entity.level().isClientSide && entity.isPassenger() && entity.getVehicle() != null && !entity.getVehicle().canBeRiddenUnderFluidType(entity.getEyeInFluidType(), entity)) {
|
||||
if (!isAir && !entity.level().isClientSide() && entity.isPassenger() && entity.getVehicle() != null && !entity.getVehicle().canBeRiddenUnderFluidType(entity.getEyeInFluidType(), entity)) {
|
||||
entity.stopRiding();
|
||||
}
|
||||
}
|
||||
@@ -1064,7 +1066,7 @@ public final class ForgeHooks {
|
||||
entries.put(stack, vis);
|
||||
});
|
||||
|
||||
ModLoader.get().postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
|
||||
ModLoader.postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
|
||||
|
||||
for (var entry : entries)
|
||||
output.accept(entry.getKey(), entry.getValue());
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class ForgeInternalHandler {
|
||||
if (newEntity != null) {
|
||||
entity.discard();
|
||||
@SuppressWarnings("resource")
|
||||
var executor = LogicalSidedProvider.WORKQUEUE.get(event.getLevel().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER);
|
||||
var executor = LogicalSidedProvider.WORKQUEUE.get(event.getLevel().isClientSide() ? LogicalSide.CLIENT : LogicalSide.SERVER);
|
||||
executor.schedule(new TickTask(0, () -> event.getLevel().addFreshEntity(newEntity)));
|
||||
return true;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public final class ForgeInternalHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
static void playerLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
UsernameCache.setUsername(event.getEntity().getUUID(), event.getEntity().getGameProfile().getName());
|
||||
UsernameCache.setUsername(event.getEntity().getUUID(), event.getEntity().getGameProfile().name());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraft.DetectedVersion;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
@@ -441,10 +442,9 @@ public class ForgeMod {
|
||||
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
gen.addProvider(true, new PackMetadataGenerator(packOutput)
|
||||
.add(PackMetadataSection.TYPE, new PackMetadataSection(
|
||||
.add(PackMetadataSection.SERVER_TYPE, new PackMetadataSection(
|
||||
Component.translatable("pack.forge.description"),
|
||||
SharedConstants.getCurrentVersion().packVersion(PackType.SERVER_DATA),
|
||||
Optional.empty() //Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion))
|
||||
DetectedVersion.BUILT_IN.packVersion(PackType.SERVER_DATA).minorRange()
|
||||
))
|
||||
);
|
||||
ForgeBlockTagsProvider blockTags = new ForgeBlockTagsProvider(packOutput, lookupProvider, existingFileHelper);
|
||||
|
||||
@@ -14,13 +14,11 @@ import net.minecraftforge.fml.ModLoadingState;
|
||||
import net.minecraftforge.fml.core.ModStateProvider;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.ObjectHolderRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
|
||||
public class ForgeStatesProvider implements IModStateProvider {
|
||||
public static final ModLoadingState CREATE_REGISTRIES = gather("CREATE_REGISTRIES", ModStateProvider.CONSTRUCT, RegistryManager::postNewRegistryEvent);
|
||||
public static final ModLoadingState OBJECT_HOLDERS = gather("OBJECT_HOLDERS", CREATE_REGISTRIES, ObjectHolderRegistry::findObjectHolders);
|
||||
public static final ModLoadingState INJECT_CAPABILITIES = gather("INJECT_CAPABILITIES", OBJECT_HOLDERS).withInline(CapabilityManager::injectCapabilities);
|
||||
public static final ModLoadingState INJECT_CAPABILITIES = gather("INJECT_CAPABILITIES", CREATE_REGISTRIES).withInline(CapabilityManager::injectCapabilities);
|
||||
public static final ModLoadingState UNFREEZE_DATA = gather("UNFREEZE_DATA", INJECT_CAPABILITIES, GameData::unfreezeData);
|
||||
public static final ModLoadingState LOAD_REGISTRIES = gather("LOAD_REGISTRIES", UNFREEZE_DATA, GameData::postRegisterEvents);
|
||||
public static final ModLoadingState FREEZE_DATA = complete("FREEZE_DATA", ModStateProvider.COMPLETE, GameData::freezeData);
|
||||
@@ -44,6 +42,6 @@ public class ForgeStatesProvider implements IModStateProvider {
|
||||
|
||||
@Override
|
||||
public List<IModLoadingState> getAllStates() {
|
||||
return List.of(CREATE_REGISTRIES, OBJECT_HOLDERS, INJECT_CAPABILITIES, UNFREEZE_DATA, LOAD_REGISTRIES, FREEZE_DATA, NETWORK_LOCK);
|
||||
return List.of(CREATE_REGISTRIES, INJECT_CAPABILITIES, UNFREEZE_DATA, LOAD_REGISTRIES, FREEZE_DATA, NETWORK_LOCK);
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,7 @@ import java.util.function.Supplier;
|
||||
* require the method:
|
||||
*
|
||||
* <pre>
|
||||
* public static MyEnum create(String name, Object foo)
|
||||
* {
|
||||
* public static MyEnum create(String name, Object foo) {
|
||||
* throw new IllegalStateException("Enum not extended");
|
||||
* }
|
||||
* </pre>
|
||||
|
||||
@@ -103,7 +103,7 @@ public final class CapabilityManager {
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
var event = new RegisterCapabilitiesEvent();
|
||||
ModLoader.get().postEvent(event);
|
||||
ModLoader.postEvent(event);
|
||||
}
|
||||
|
||||
private static void error(String message) {
|
||||
|
||||
@@ -41,7 +41,8 @@ public abstract class ForgeBlockItemTagsProvider extends BlockItemTagsProvider {
|
||||
.add(Blocks.MEDIUM_AMETHYST_BUD)
|
||||
.add(Blocks.LARGE_AMETHYST_BUD);
|
||||
tag(Tags.Blocks.CHAINS, Tags.Items.CHAINS)
|
||||
.add(Blocks.CHAIN);
|
||||
.add(Blocks.IRON_CHAIN)
|
||||
.addAll(Blocks.COPPER_CHAIN.asList());
|
||||
tag(Tags.Blocks.CHESTS, Tags.Items.CHESTS)
|
||||
.addTags(
|
||||
Tags.Blocks.CHESTS_ENDER,
|
||||
|
||||
@@ -182,7 +182,7 @@ public interface IForgeBlock {
|
||||
*/
|
||||
default boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
|
||||
self().playerWillDestroy(level, pos, state, player);
|
||||
return level.setBlock(pos, fluid.createLegacyBlock(), level.isClientSide ? 11 : 3);
|
||||
return level.setBlock(pos, fluid.createLegacyBlock(), level.isClientSide() ? 11 : 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -713,7 +713,7 @@ public interface IForgeBlock {
|
||||
// Logic copied from HoeItem#TILLABLES; needs to be kept in sync during updating
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.ROOTED_DIRT) {
|
||||
if (!simulate && !context.getLevel().isClientSide) {
|
||||
if (!simulate && !context.getLevel().isClientSide()) {
|
||||
Block.popResourceFromFace(context.getLevel(), context.getClickedPos(), context.getClickedFace(), new ItemStack(Items.HANGING_ROOTS));
|
||||
}
|
||||
return Blocks.DIRT.defaultBlockState();
|
||||
|
||||
@@ -114,7 +114,7 @@ public interface IForgeBlockEntity extends ICapabilityProvider {
|
||||
default void requestModelDataUpdate() {
|
||||
BlockEntity te = self();
|
||||
Level level = te.getLevel();
|
||||
if (level != null && level.isClientSide) {
|
||||
if (level != null && level.isClientSide()) {
|
||||
var modelDataManager = level.getModelDataManager();
|
||||
if (modelDataManager != null) {
|
||||
modelDataManager.requestRefresh(te);
|
||||
@@ -136,10 +136,9 @@ public interface IForgeBlockEntity extends ICapabilityProvider {
|
||||
/**
|
||||
* Returns whether this {@link BlockEntity} has custom outline rendering behavior.
|
||||
*
|
||||
* @param player the local player currently viewing this {@code BlockEntity}
|
||||
* @return {@code true} to enable outline processing
|
||||
*/
|
||||
default boolean hasCustomOutlineRendering(Player player) {
|
||||
default boolean hasCustomOutlineRendering() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import net.minecraft.network.protocol.game.GameProtocols;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||
@@ -50,6 +51,8 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
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;
|
||||
|
||||
public interface IForgeGameTestHelper {
|
||||
private GameTestHelper self() {
|
||||
@@ -144,22 +147,24 @@ public interface IForgeGameTestHelper {
|
||||
return this.self().getLevel().registryAccess().lookupOrThrow(registryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock server player in creative mode
|
||||
*/
|
||||
default ServerPlayer makeMockServerPlayer() {
|
||||
return makeMockServerPlayer(true);
|
||||
return makeMockServerPlayer(GameType.CREATIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock server player in creative mode
|
||||
*/
|
||||
default ServerPlayer makeMockServerPlayer(boolean creative) {
|
||||
return makeMockServerPlayer(creative ? GameType.CREATIVE : GameType.SURVIVAL);
|
||||
}
|
||||
|
||||
default ServerPlayer makeMockServerPlayer(GameType type) {
|
||||
var level = self().getLevel();
|
||||
var cookie = CommonListenerCookie.createInitial(new GameProfile(UUID.randomUUID(), "test-mock-player"), false);
|
||||
var player = new ServerPlayer(level.getServer(), level, cookie.gameProfile(), cookie.clientInformation()) {
|
||||
public boolean isSpectator() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCreative() {
|
||||
return creative;
|
||||
}
|
||||
};
|
||||
var player = new ServerPlayer(level.getServer(), level, cookie.gameProfile(), cookie.clientInformation());
|
||||
var connection = new Connection(PacketFlow.SERVERBOUND);
|
||||
@SuppressWarnings("unused") // The constructor has side effects
|
||||
var channel = new EmbeddedChannel(connection);
|
||||
@@ -168,6 +173,7 @@ public interface IForgeGameTestHelper {
|
||||
var listener = new ServerGamePacketListenerImpl(server, connection, player, cookie);
|
||||
var info = GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(server.registryAccess()), listener);
|
||||
connection.setupInboundProtocol(info, listener);
|
||||
player.setGameMode(type);
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -179,6 +185,22 @@ public interface IForgeGameTestHelper {
|
||||
self().addCleanup(success -> bus.removeListener(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event listener that will be unregistered when the test is finished running.
|
||||
*/
|
||||
default <E extends MutableEvent> void addMutableListener(EventBus<E> bus, Consumer<E> consumer) {
|
||||
var key = bus.addListener(consumer);
|
||||
self().addCleanup(success -> bus.removeListener(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event listener that will be unregistered when the test is finished running.
|
||||
*/
|
||||
default <E extends RecordEvent> void addRecordListener(EventBus<E> bus, Consumer<E> consumer) {
|
||||
var key = bus.addListener(consumer);
|
||||
self().addCleanup(success -> bus.removeListener(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event listener that will be unregistered when the test is finished running.
|
||||
*/
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface IForgeServerPlayer {
|
||||
@SuppressWarnings("resource")
|
||||
default void openMenu(MenuProvider containerSupplier, Consumer<FriendlyByteBuf> extraDataWriter) {
|
||||
var player = self();
|
||||
if (player.level().isClientSide) return;
|
||||
if (player.level().isClientSide()) return;
|
||||
player.doCloseContainer();
|
||||
player.nextContainerCounter();
|
||||
int openContainerId = player.containerCounter;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class DatagenModLoader {
|
||||
}
|
||||
|
||||
existingFileHelper = new ExistingFileHelper(existingPacks, existingMods, validate, assetIndex, assetsDir);
|
||||
ModLoader.get().runEventGenerator(mc -> new GatherDataEvent(
|
||||
ModLoader.runEventGenerator(mc -> new GatherDataEvent(
|
||||
mc,
|
||||
config.makeGenerator(
|
||||
p -> config.isFlat() ? p : p.resolve(mc.getModId()),
|
||||
|
||||
@@ -16,32 +16,20 @@ import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fired on {@link PackRepository} creation to allow mods to add new pack finders.
|
||||
*
|
||||
* @param getPackType the {@link PackType} of the pack repository being constructed.
|
||||
*/
|
||||
public final class AddPackFindersEvent implements IModBusEvent {
|
||||
public record AddPackFindersEvent(PackType getPackType, Consumer<RepositorySource> sourceAdder) implements IModBusEvent {
|
||||
public static EventBus<AddPackFindersEvent> getBus(BusGroup modBusGroup) {
|
||||
return IModBusEvent.getBus(modBusGroup, AddPackFindersEvent.class);
|
||||
}
|
||||
|
||||
private final PackType packType;
|
||||
private final Consumer<RepositorySource> sources;
|
||||
|
||||
public AddPackFindersEvent(PackType packType, Consumer<RepositorySource> sources) {
|
||||
this.packType = packType;
|
||||
this.sources = sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new source to the list of pack finders.
|
||||
*
|
||||
* @param source the pack finder
|
||||
*/
|
||||
public void addRepositorySource(RepositorySource source) {
|
||||
sources.accept(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link PackType} of the pack repository being constructed.
|
||||
*/
|
||||
public PackType getPackType() {
|
||||
return packType;
|
||||
sourceAdder.accept(source);
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,14 @@
|
||||
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.LayeredRegistryAccess;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.server.RegistryLayer;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
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.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,10 +21,9 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* The main ResourceManager is recreated on each reload, just after {@link ReloadableServerResources}'s creation.
|
||||
*
|
||||
* 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}
|
||||
* <p>The event is fired on each reload and lets modders add their own ReloadListeners, for server-side resources.</p>
|
||||
*/
|
||||
@NullMarked
|
||||
public final class AddReloadListenerEvent extends MutableEvent {
|
||||
public static final EventBus<AddReloadListenerEvent> BUS = EventBus.create(AddReloadListenerEvent.class);
|
||||
|
||||
@@ -37,30 +31,10 @@ public final class AddReloadListenerEvent extends MutableEvent {
|
||||
private final ReloadableServerResources serverResources;
|
||||
|
||||
private final HolderLookup.Provider registries;
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
private final RegistryAccess registryAccess;
|
||||
|
||||
/** @deprecated Does not provide additional context. Use {@link #AddReloadListenerEvent(ReloadableServerResources, HolderLookup.Provider, RegistryAccess)} instead. */
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
public AddReloadListenerEvent(
|
||||
ReloadableServerResources serverResources,
|
||||
RegistryAccess registryAccess
|
||||
) {
|
||||
this(
|
||||
serverResources,
|
||||
registryAccess,
|
||||
registryAccess
|
||||
);
|
||||
}
|
||||
|
||||
public AddReloadListenerEvent(
|
||||
ReloadableServerResources serverResources,
|
||||
HolderLookup.Provider registries,
|
||||
@Deprecated(forRemoval = true, since = "1.21.4") RegistryAccess registryAccess
|
||||
) {
|
||||
public AddReloadListenerEvent(ReloadableServerResources serverResources, HolderLookup.Provider registries) {
|
||||
this.serverResources = serverResources;
|
||||
this.registries = registries;
|
||||
this.registryAccess = registryAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +45,7 @@ public final class AddReloadListenerEvent extends MutableEvent {
|
||||
}
|
||||
|
||||
public List<PreparableReloadListener> getListeners() {
|
||||
return ImmutableList.copyOf(listeners);
|
||||
return List.copyOf(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,23 +72,12 @@ public final class AddReloadListenerEvent extends MutableEvent {
|
||||
return registries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the loaded registries associated with these server resources.
|
||||
* All built-in and dynamic registries are loaded and frozen by this point.
|
||||
* @return The RegistryAccess context for the currently active reload.
|
||||
* @deprecated Does not contain updated tags. Use {@link #getRegistries()} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
public RegistryAccess getRegistryAccess() {
|
||||
return registryAccess;
|
||||
}
|
||||
|
||||
private record WrappedStateAwareListener(PreparableReloadListener wrapped) implements PreparableReloadListener {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> reload(final PreparationBarrier stage, final ResourceManager resourceManager, final Executor backgroundExecutor, final Executor gameExecutor) {
|
||||
public CompletableFuture<Void> reload(SharedState state, Executor backgroundExecutor, PreparationBarrier stage, Executor gameExecutor) {
|
||||
if (ModLoader.isLoadingStateValid())
|
||||
return wrapped.reload(stage, resourceManager, backgroundExecutor, gameExecutor);
|
||||
return wrapped.reload(state, backgroundExecutor, stage, gameExecutor);
|
||||
else
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ import java.util.function.Supplier;
|
||||
* Fired when the contents of a specific creative mode tab are being populated.
|
||||
* This event may be fired multiple times if the operator status of the local player or enabled feature flags changes.
|
||||
* <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}.
|
||||
* This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.
|
||||
*/
|
||||
public final class BuildCreativeModeTabContentsEvent implements IModBusEvent, CreativeModeTab.Output {
|
||||
public static EventBus<BuildCreativeModeTabContentsEvent> getBus(BusGroup modBusGroup) {
|
||||
|
||||
@@ -8,29 +8,27 @@ package net.minecraftforge.event;
|
||||
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.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;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* CommandEvent is fired after a command is parsed, but before it is executed.
|
||||
* This event is fired during the invocation of {@link Commands#performCommand(ParseResults, String)}.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the command will not be executed.
|
||||
* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the command will not be executed.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
* This event is fired only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@NullMarked
|
||||
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;
|
||||
private @Nullable Throwable exception;
|
||||
|
||||
public CommandEvent(ParseResults<CommandSourceStack> parse) {
|
||||
this.parse = parse;
|
||||
|
||||
@@ -15,11 +15,7 @@ import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
* DifficultyChangeEvent is fired when difficulty is changing. <br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onDifficultyChange(Difficulty, Difficulty)}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
*/
|
||||
public record DifficultyChangeEvent(Difficulty getDifficulty, Difficulty getOldDifficulty) implements RecordEvent {
|
||||
public static final EventBus<DifficultyChangeEvent> BUS = EventBus.create(DifficultyChangeEvent.class);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
@@ -55,6 +56,7 @@ import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.players.NameAndId;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
@@ -204,17 +206,8 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class ForgeEventFactory {
|
||||
private static final ModLoader ML = ModLoader.get();
|
||||
|
||||
private ForgeEventFactory() {}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link ModLoader#get()} event bus
|
||||
*/
|
||||
private static <T extends IModBusEvent> void postModBus(T e) {
|
||||
ML.postEvent(e);
|
||||
}
|
||||
|
||||
public static boolean onMultiBlockPlace(@Nullable Entity entity, List<BlockSnapshot> blockSnapshots, Direction direction) {
|
||||
var snap = blockSnapshots.getFirst();
|
||||
var placedAgainst = snap.getLevel().getBlockState(snap.getPos().relative(direction.getOpposite()));
|
||||
@@ -240,7 +233,7 @@ public final class ForgeEventFactory {
|
||||
}
|
||||
|
||||
public static void onPlayerDestroyItem(Player player, @NotNull ItemStack stack, @Nullable InteractionHand hand) {
|
||||
onPlayerDestroyItem(player, stack, LivingEntity.getSlotForHand(hand));
|
||||
onPlayerDestroyItem(player, stack, hand.asEquipmentSlot());
|
||||
}
|
||||
|
||||
public static void onPlayerDestroyItem(Player player, @NotNull ItemStack stack, @Nullable EquipmentSlot slot) {
|
||||
@@ -414,10 +407,6 @@ public final class ForgeEventFactory {
|
||||
PlayerEvent.SaveToFile.BUS.post(new PlayerEvent.SaveToFile(player, playerDirectory, uuidString));
|
||||
}
|
||||
|
||||
public static void firePlayerLoadingEvent(Player player, PlayerDataStorage playerFileData, String uuidString) {
|
||||
PlayerEvent.LoadFromFile.BUS.post(new PlayerEvent.LoadFromFile(player, playerFileData.getPlayerDataFolder(), uuidString));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BlockState onToolUse(BlockState originalState, UseOnContext context, ToolAction toolAction, boolean simulate) {
|
||||
var event = new BlockToolModificationEvent(originalState, context, toolAction, simulate);
|
||||
@@ -431,7 +420,7 @@ public final class ForgeEventFactory {
|
||||
var event = new BonemealEvent(player, level, pos, state, stack);
|
||||
if (BonemealEvent.BUS.post(event)) return -1;
|
||||
if (event.getResult() == Result.ALLOW) {
|
||||
if (!level.isClientSide)
|
||||
if (!level.isClientSide())
|
||||
stack.shrink(1);
|
||||
return 1;
|
||||
}
|
||||
@@ -695,20 +684,15 @@ public final class ForgeEventFactory {
|
||||
return SleepFinishedTimeEvent.BUS.fire(new SleepFinishedTimeEvent(level, newTime, minTime)).getNewTime();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, RegistryAccess registryAccess) {
|
||||
return AddReloadListenerEvent.BUS.fire(new AddReloadListenerEvent(serverResources, registryAccess)).getListeners();
|
||||
}
|
||||
|
||||
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, HolderLookup.Provider lookupProvider, @Deprecated(forRemoval = true, since = "1.21.4") RegistryAccess registryAccess) {
|
||||
return AddReloadListenerEvent.BUS.fire(new AddReloadListenerEvent(serverResources, lookupProvider, registryAccess)).getListeners();
|
||||
public static List<PreparableReloadListener> onResourceReload(ReloadableServerResources serverResources, HolderLookup.Provider lookupProvider) {
|
||||
return AddReloadListenerEvent.BUS.fire(new AddReloadListenerEvent(serverResources, lookupProvider)).getListeners();
|
||||
}
|
||||
|
||||
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher, Commands.CommandSelection environment, CommandBuildContext context) {
|
||||
RegisterCommandsEvent.BUS.post(new RegisterCommandsEvent(dispatcher, environment, context));
|
||||
}
|
||||
|
||||
public static boolean canLivingConvert(LivingEntity entity, EntityType<? extends LivingEntity> outcome, Consumer<Integer> timer) {
|
||||
public static boolean canLivingConvert(LivingEntity entity, EntityType<? extends LivingEntity> outcome, IntConsumer timer) {
|
||||
return !LivingConversionEvent.Pre.BUS.post(new LivingConversionEvent.Pre(entity, outcome, timer));
|
||||
}
|
||||
|
||||
@@ -740,9 +724,9 @@ public final class ForgeEventFactory {
|
||||
return EntityTeleportEvent.ChorusFruit.BUS.fire(new EntityTeleportEvent.ChorusFruit(entity, targetX, targetY, targetZ));
|
||||
}
|
||||
|
||||
public static boolean onPermissionChanged(GameProfile gameProfile, int newLevel, PlayerList playerList) {
|
||||
public static boolean onPermissionChanged(NameAndId gameProfile, int newLevel, PlayerList playerList) {
|
||||
var oldLevel = playerList.getServer().getProfilePermissions(gameProfile);
|
||||
var player = playerList.getPlayer(gameProfile.getId());
|
||||
var player = playerList.getPlayer(gameProfile.id());
|
||||
if (newLevel != oldLevel && player != null)
|
||||
return PermissionsChangedEvent.BUS.post(new PermissionsChangedEvent(player, newLevel, oldLevel));
|
||||
return false;
|
||||
@@ -785,11 +769,11 @@ public final class ForgeEventFactory {
|
||||
}
|
||||
|
||||
public static void onPreLevelTick(Level level, BooleanSupplier haveTime) {
|
||||
TickEvent.LevelTickEvent.Pre.BUS.post(new TickEvent.LevelTickEvent.Pre(level.isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER, level, haveTime));
|
||||
TickEvent.LevelTickEvent.Pre.BUS.post(new TickEvent.LevelTickEvent.Pre(level.isClientSide() ? LogicalSide.CLIENT : LogicalSide.SERVER, level, haveTime));
|
||||
}
|
||||
|
||||
public static void onPostLevelTick(Level level, BooleanSupplier haveTime) {
|
||||
TickEvent.LevelTickEvent.Post.BUS.post(new TickEvent.LevelTickEvent.Post(level.isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER, level, haveTime));
|
||||
TickEvent.LevelTickEvent.Post.BUS.post(new TickEvent.LevelTickEvent.Post(level.isClientSide() ? LogicalSide.CLIENT : LogicalSide.SERVER, level, haveTime));
|
||||
}
|
||||
|
||||
public static void onPreClientTick() {
|
||||
@@ -960,7 +944,7 @@ public final class ForgeEventFactory {
|
||||
|
||||
// TODO: Remove from mod bus - Lex 04222024
|
||||
public static void addPackFindersServer(Consumer<RepositorySource> consumer) {
|
||||
postModBus(new AddPackFindersEvent(PackType.SERVER_DATA, consumer));
|
||||
ModLoader.postEvent(new AddPackFindersEvent(PackType.SERVER_DATA, consumer));
|
||||
}
|
||||
|
||||
public static boolean onEntityJoinLevel(Entity entity, Level level) {
|
||||
|
||||
@@ -7,28 +7,28 @@ 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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Fired when a {@link LootTable} is loaded from JSON.
|
||||
* Loot tables loaded from world save datapacks will not fire this event as they are considered user configuration files.
|
||||
* This event is fired whenever server resources are loaded or reloaded.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the loot table will be made empty.</p>
|
||||
* <p>This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the loot table will be made empty.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
*/
|
||||
@NullMarked
|
||||
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;
|
||||
private @Nullable LootTable table;
|
||||
|
||||
public LootTableLoadEvent(ResourceLocation name, LootTable table) {
|
||||
this.name = name;
|
||||
@@ -39,11 +39,12 @@ public final class LootTableLoadEvent extends MutableEvent implements Cancellabl
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LootTable getTable() {
|
||||
return this.table;
|
||||
}
|
||||
|
||||
public void setTable(LootTable table) {
|
||||
public void setTable(@Nullable LootTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,7 @@ import java.util.Objects;
|
||||
* {@link #getNewVolume()} contains the volume the sound will be played at.
|
||||
* {@link #getNewPitch()} contains the pitch the sound will be played at.
|
||||
* <p>
|
||||
* This event is {@link Cancelable cancelable}.
|
||||
* If this event is canceled, the sound is not played.
|
||||
* <p>
|
||||
* This event does not have a result.
|
||||
* <p>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* This event is {@linkplain Cancellable cancellable}. If this event is cancelled, the sound is not played.
|
||||
*/
|
||||
public sealed class PlayLevelSoundEvent extends MutableEvent implements Cancellable, InheritableEvent {
|
||||
public static final CancellableEventBus<PlayLevelSoundEvent> BUS = CancellableEventBus.create(PlayLevelSoundEvent.class);
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -15,7 +14,9 @@ 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 net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Fired for registering structure conversions for pre-1.18.2 worlds. This is used by {@link StructuresBecomeConfiguredFix}
|
||||
@@ -28,14 +29,12 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* <p>This event will only fire if {@link StructuresBecomeConfiguredFix} is used, as a result of converting a
|
||||
* pre-1.18.2 world to the current version.</p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain net.minecraftforge.fml.LogicalSide#SERVER logical server}. </p>
|
||||
* <p>This event is fired only on the {@linkplain LogicalSide#SERVER logical server}. </p>
|
||||
*
|
||||
* @see StructuresBecomeConfiguredFix
|
||||
* @see #register(String, StructuresBecomeConfiguredFix.Conversion)
|
||||
*/
|
||||
@NullMarked
|
||||
public final class RegisterStructureConversionsEvent extends MutableEvent {
|
||||
public static final EventBus<RegisterStructureConversionsEvent> BUS = EventBus.create(RegisterStructureConversionsEvent.class);
|
||||
|
||||
|
||||
@@ -9,23 +9,23 @@ import java.util.Objects;
|
||||
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.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;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* This event is fired whenever a {@link ServerboundChatPacket} is received from a client
|
||||
* who has submitted their chat message.
|
||||
* <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 message will not be sent to clients.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
* This event is fired only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@NullMarked
|
||||
public final class ServerChatEvent extends MutableEvent implements Cancellable {
|
||||
public static final CancellableEventBus<ServerChatEvent> BUS = CancellableEventBus.create(ServerChatEvent.class);
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class ServerChatEvent extends MutableEvent implements Cancellable {
|
||||
@ApiStatus.Internal
|
||||
public ServerChatEvent(ServerPlayer player, String rawText, Component message) {
|
||||
this.player = player;
|
||||
this.username = player.getGameProfile().getName();
|
||||
this.username = player.getGameProfile().name();
|
||||
this.rawText = rawText;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@@ -7,36 +7,21 @@ package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* Fired when tags are updated on either server or client. This event can be used to refresh data that depends on tags.
|
||||
*
|
||||
* @param getRegistryAccess the dynamic registries that have had their tags rebound
|
||||
* @param getUpdateCause the cause for this tag update
|
||||
* @param isIntegratedServer whether this event is being fired on an integrated server
|
||||
*/
|
||||
public final class TagsUpdatedEvent extends MutableEvent {
|
||||
public record TagsUpdatedEvent(RegistryAccess getRegistryAccess, UpdateCause getUpdateCause, boolean isIntegratedServer)
|
||||
implements RecordEvent {
|
||||
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) {
|
||||
this.registryAccess = registryAccess;
|
||||
this.updateCause = fromClientPacket ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD;
|
||||
this.integratedServer = isIntegratedServerConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The dynamic registries that have had their tags rebound.
|
||||
*/
|
||||
public RegistryAccess getRegistryAccess() {
|
||||
return registryAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cause for this tag update
|
||||
*/
|
||||
public UpdateCause getUpdateCause() {
|
||||
return updateCause;
|
||||
this(registryAccess, fromClientPacket ? UpdateCause.CLIENT_PACKET_RECEIVED : UpdateCause.SERVER_DATA_LOAD, isIntegratedServerConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +29,7 @@ public final class TagsUpdatedEvent extends MutableEvent {
|
||||
* result of this event. Effectively this means that in single player only the server-side updates this data.
|
||||
*/
|
||||
public boolean shouldUpdateStaticData() {
|
||||
return updateCause == UpdateCause.SERVER_DATA_LOAD || !integratedServer;
|
||||
return getUpdateCause == UpdateCause.SERVER_DATA_LOAD || !isIntegratedServer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,135 +14,56 @@ import java.util.function.BooleanSupplier;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.fml.LogicalSide;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public enum Phase {
|
||||
START, END
|
||||
}
|
||||
|
||||
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) {
|
||||
this.type = type;
|
||||
this.side = side;
|
||||
this.phase = phase;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
protected ServerTickEvent(BooleanSupplier haveTime, MinecraftServer server, Phase phase) {
|
||||
super(Type.SERVER, LogicalSide.SERVER, phase);
|
||||
this.haveTime = haveTime;
|
||||
this.server = server;
|
||||
}
|
||||
@NullMarked
|
||||
public sealed interface TickEvent {
|
||||
sealed interface ServerTickEvent extends TickEvent {
|
||||
BooleanSupplier haveTimeSupplier();
|
||||
|
||||
/**
|
||||
* @return {@code true} whether the server has enough time to perform any
|
||||
* additional tasks (usually IO related) during the current tick,
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
public boolean haveTime() {
|
||||
return this.haveTime.getAsBoolean();
|
||||
default boolean haveTime() {
|
||||
return haveTimeSupplier().getAsBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the server instance}
|
||||
*/
|
||||
public MinecraftServer getServer() {
|
||||
return server;
|
||||
}
|
||||
MinecraftServer server();
|
||||
|
||||
public static final class Pre extends ServerTickEvent {
|
||||
record Pre(BooleanSupplier haveTimeSupplier, MinecraftServer server) implements RecordEvent, 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 {
|
||||
record Post(BooleanSupplier haveTimeSupplier, MinecraftServer server) implements RecordEvent, ServerTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(BooleanSupplier haveTime, MinecraftServer server) {
|
||||
super(haveTime, server, Phase.END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
sealed interface ClientTickEvent extends TickEvent {
|
||||
record Pre() implements RecordEvent, 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 {
|
||||
record Post() implements RecordEvent, ClientTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
public static final Post INSTANCE = new Post();
|
||||
|
||||
public Post() {
|
||||
super(Phase.END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
sealed interface LevelTickEvent extends TickEvent {
|
||||
LogicalSide side();
|
||||
|
||||
public final Level level;
|
||||
private final BooleanSupplier haveTime;
|
||||
Level level();
|
||||
|
||||
protected LevelTickEvent(LogicalSide side, Level level, BooleanSupplier haveTime, Phase phase) {
|
||||
super(Type.LEVEL, side, phase);
|
||||
this.level = level;
|
||||
this.haveTime = haveTime;
|
||||
}
|
||||
BooleanSupplier haveTimeSupplier();
|
||||
|
||||
/**
|
||||
* @return {@code true} whether the server has enough time to perform any
|
||||
@@ -150,91 +71,46 @@ public sealed class TickEvent extends MutableEvent implements InheritableEvent {
|
||||
* otherwise {@code false}
|
||||
* @see ServerTickEvent#haveTime()
|
||||
*/
|
||||
public boolean haveTime() {
|
||||
return this.haveTime.getAsBoolean();
|
||||
default boolean haveTime() {
|
||||
return haveTimeSupplier().getAsBoolean();
|
||||
}
|
||||
|
||||
public static final class Pre extends LevelTickEvent {
|
||||
record Pre(LogicalSide side, Level level, BooleanSupplier haveTimeSupplier) implements RecordEvent, 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 {
|
||||
record Post(LogicalSide side, Level level, BooleanSupplier haveTimeSupplier) implements RecordEvent, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
sealed interface PlayerTickEvent extends TickEvent {
|
||||
LogicalSide side();
|
||||
|
||||
public final Player player;
|
||||
|
||||
protected PlayerTickEvent(Player player, Phase phase) {
|
||||
super(Type.PLAYER, player instanceof ServerPlayer ? LogicalSide.SERVER : LogicalSide.CLIENT, phase);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static final class Pre extends PlayerTickEvent {
|
||||
record Pre(Player player, LogicalSide side) implements RecordEvent, PlayerTickEvent {
|
||||
public static final EventBus<Pre> BUS = EventBus.create(Pre.class);
|
||||
|
||||
public Pre(Player player) {
|
||||
super(player, Phase.START);
|
||||
this(player, player instanceof ServerPlayer ? LogicalSide.SERVER : LogicalSide.CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Post extends PlayerTickEvent {
|
||||
record Post(Player player, LogicalSide side) implements RecordEvent, PlayerTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(Player player) {
|
||||
super(player, Phase.END);
|
||||
this(player, player instanceof ServerPlayer ? LogicalSide.SERVER : LogicalSide.CLIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
super(Type.RENDER, LogicalSide.CLIENT, phase);
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public DeltaTracker getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
public static final class Pre extends RenderTickEvent {
|
||||
sealed interface RenderTickEvent extends TickEvent {
|
||||
record Pre(DeltaTracker timer) implements RecordEvent, 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 {
|
||||
record Post(DeltaTracker timer) implements RecordEvent, RenderTickEvent {
|
||||
public static final EventBus<Post> BUS = EventBus.create(Post.class);
|
||||
|
||||
public Post(DeltaTracker timer) {
|
||||
super(Phase.END, timer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,26 +9,14 @@ 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;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* This event is called when a player picks up a potion from a brewing stand.
|
||||
* @param getStack The ItemStack of the potion.
|
||||
*/
|
||||
public final class PlayerBrewedPotionEvent extends PlayerEvent {
|
||||
@NullMarked
|
||||
public record PlayerBrewedPotionEvent(Player getEntity, ItemStack getStack) implements RecordEvent, PlayerEvent {
|
||||
public static final EventBus<PlayerBrewedPotionEvent> BUS = EventBus.create(PlayerBrewedPotionEvent.class);
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
public PlayerBrewedPotionEvent(Player player, @NotNull ItemStack stack) {
|
||||
super(player);
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ItemStack of the potion.
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ 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.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public sealed abstract class PotionBrewEvent extends MutableEvent implements InheritableEvent {
|
||||
public static final EventBus<PotionBrewEvent> BUS = EventBus.create(PotionBrewEvent.class);
|
||||
|
||||
@@ -24,13 +25,12 @@ public sealed abstract class PotionBrewEvent extends MutableEvent implements Inh
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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) {
|
||||
public void setItem(int index, ItemStack stack) {
|
||||
if (index < stacks.size()) {
|
||||
stacks.set(index, stack);
|
||||
}
|
||||
|
||||
@@ -7,49 +7,24 @@ 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.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* EntityEvent is fired when an event involving any Entity 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>
|
||||
* {@link #entity} contains the entity that caused this event to occur.<br>
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
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) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
* EntityEvent is fired when an event involving any Entity occurs.
|
||||
*/
|
||||
public interface EntityEvent {
|
||||
/**
|
||||
* @return the entity that caused this event to occur.
|
||||
*/
|
||||
Entity getEntity();
|
||||
|
||||
/**
|
||||
* EntityConstructing is fired when an Entity is being created. <br>
|
||||
* This event is fired within the constructor of the Entity.<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}.<br>
|
||||
* EntityConstructing is fired when an Entity is being created.
|
||||
* <p>This event is fired within the constructor of the Entity.</p>
|
||||
**/
|
||||
public static final class EntityConstructing extends EntityEvent {
|
||||
record EntityConstructing(Entity getEntity) implements RecordEvent, EntityEvent {
|
||||
public static final EventBus<EntityConstructing> BUS = EventBus.create(EntityConstructing.class);
|
||||
|
||||
public EntityConstructing(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,32 +32,18 @@ public class EntityEvent extends MutableEvent implements InheritableEvent {
|
||||
* Sections are 16x16x16 block grids of the world.<br>
|
||||
* This event does not fire when a new entity is spawned, only when an entity moves from one section to another one.
|
||||
* Use {@link EntityJoinLevelEvent} to detect new entities joining the world.
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static final class EnteringSection extends EntityEvent {
|
||||
record EnteringSection(Entity getEntity, long getPackedOldPos, long getPackedNewPos)
|
||||
implements RecordEvent, EntityEvent {
|
||||
public static final EventBus<EnteringSection> BUS = EventBus.create(EnteringSection.class);
|
||||
|
||||
private final long packedOldPos;
|
||||
private final long packedNewPos;
|
||||
|
||||
public EnteringSection(Entity entity, long packedOldPos, long packedNewPos) {
|
||||
super(entity);
|
||||
this.packedOldPos = packedOldPos;
|
||||
this.packedNewPos = packedNewPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* A packed version of the old section's position. This is to be used with the various methods in {@link SectionPos},
|
||||
* such as {@link SectionPos#of(long)} or {@link SectionPos#x(long)} to avoid allocation.
|
||||
* @return the packed position of the old section
|
||||
*/
|
||||
public long getPackedOldPos() {
|
||||
return packedOldPos;
|
||||
return getPackedOldPos;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,21 +52,21 @@ public class EntityEvent extends MutableEvent implements InheritableEvent {
|
||||
* @return the packed position of the new section
|
||||
*/
|
||||
public long getPackedNewPos() {
|
||||
return packedNewPos;
|
||||
return getPackedNewPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the position of the old section
|
||||
*/
|
||||
public SectionPos getOldPos() {
|
||||
return SectionPos.of(packedOldPos);
|
||||
return SectionPos.of(getPackedOldPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the position of the new section
|
||||
*/
|
||||
public SectionPos getNewPos() {
|
||||
return SectionPos.of(packedNewPos);
|
||||
return SectionPos.of(getPackedNewPos);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +74,7 @@ public class EntityEvent extends MutableEvent implements InheritableEvent {
|
||||
* section has changed.
|
||||
*/
|
||||
public boolean didChunkChange() {
|
||||
return SectionPos.x(packedOldPos) != SectionPos.x(packedNewPos) || SectionPos.z(packedOldPos) != SectionPos.z(packedNewPos);
|
||||
return SectionPos.x(getPackedOldPos) != SectionPos.x(getPackedNewPos) || SectionPos.z(getPackedOldPos) != SectionPos.z(getPackedNewPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
@@ -21,33 +22,25 @@ import net.minecraftforge.fml.LogicalSide;
|
||||
* <strong>Note:</strong> This event may be called before the underlying {@link LevelChunk} is promoted to {@link ChunkStatus#FULL}.
|
||||
* You will cause chunk loading deadlocks if you do not delay your world interactions.
|
||||
* <p>
|
||||
* This event is {@linkplain Cancelable cancellable} and does not {@linkplain HasResult have a result}.
|
||||
* This event is {@linkplain Cancellable cancellable}.
|
||||
* If the event is canceled, the entity will not be added to the level.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
**/
|
||||
public final class EntityJoinLevelEvent extends EntityEvent implements Cancellable {
|
||||
public record EntityJoinLevelEvent(Entity getEntity, Level getLevel, boolean loadedFromDisk)
|
||||
implements Cancellable, EntityEvent, RecordEvent {
|
||||
public static final CancellableEventBus<EntityJoinLevelEvent> BUS = CancellableEventBus.create(EntityJoinLevelEvent.class);
|
||||
|
||||
private final Level level;
|
||||
private final boolean loadedFromDisk;
|
||||
|
||||
public EntityJoinLevelEvent(Entity entity, Level level) {
|
||||
this(entity, level, false);
|
||||
}
|
||||
|
||||
public EntityJoinLevelEvent(Entity entity, Level level, boolean loadedFromDisk) {
|
||||
super(entity);
|
||||
this.level = level;
|
||||
this.loadedFromDisk = loadedFromDisk;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level that the entity is set to join}
|
||||
*/
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
return getLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,30 +10,21 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.entity.LevelCallback;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
|
||||
/**
|
||||
* This event is fired whenever an {@link Entity} leaves a {@link Level}.
|
||||
* This event is fired whenever an entity is removed from the level in {@link LevelCallback#onTrackingEnd(Object)}.
|
||||
* <p>
|
||||
* This event is not {@linkplain Cancelable cancellable} and does not {@linkplain net.minecraftforge.eventbus.api.Event.HasResult have a result}.
|
||||
* <p>
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
|
||||
* on both logical sides.
|
||||
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus} on both logical sides.
|
||||
**/
|
||||
public final class EntityLeaveLevelEvent extends EntityEvent {
|
||||
public record EntityLeaveLevelEvent(Entity getEntity, Level getLevel) implements RecordEvent, EntityEvent {
|
||||
public static final EventBus<EntityLeaveLevelEvent> BUS = EventBus.create(EntityLeaveLevelEvent.class);
|
||||
|
||||
private final Level level;
|
||||
|
||||
public EntityLeaveLevelEvent(Entity entity, Level level) {
|
||||
super(entity);
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level the entity is set to leave}
|
||||
*/
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
return getLevel;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,11 @@
|
||||
package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.HasResult;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* EntityMobGriefingEvent is fired when mob griefing is about to occur and allows an event listener to specify whether it should or not.<br>
|
||||
@@ -21,15 +22,21 @@ import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
* <li>{@link Result#DEFAULT} means the {@code mobGriefing} game rule is used to determine the behaviour.</li>
|
||||
* <li>{@link Result#DENY} means this instance of mob griefing is not allowed.</li>
|
||||
* </ul>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public final class EntityMobGriefingEvent extends EntityEvent implements HasResult {
|
||||
@NullMarked
|
||||
public final class EntityMobGriefingEvent extends MutableEvent implements EntityEvent, HasResult {
|
||||
public static final EventBus<EntityMobGriefingEvent> BUS = EventBus.create(EntityMobGriefingEvent.class);
|
||||
|
||||
private final Entity entity;
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
public EntityMobGriefingEvent(Entity entity) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,8 +7,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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
@@ -16,48 +16,23 @@ import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
* <b>entityBeingMounted can be null</b>, be sure to check for that.
|
||||
* <br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If this event is canceled, the entity does not mount/dismount the other entity.<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 {@linkplain Cancellable cancellable}.<br>
|
||||
* If this event is cancelled, the entity does not mount/dismount the other entity.
|
||||
*/
|
||||
public final class EntityMountEvent extends EntityEvent implements Cancellable {
|
||||
public record EntityMountEvent(
|
||||
Entity getEntityMounting,
|
||||
Entity getEntityBeingMounted,
|
||||
Level getLevel,
|
||||
boolean isMounting
|
||||
) implements Cancellable, EntityEvent, RecordEvent {
|
||||
public static final CancellableEventBus<EntityMountEvent> BUS = CancellableEventBus.create(EntityMountEvent.class);
|
||||
|
||||
private final Entity entityMounting;
|
||||
private final Entity entityBeingMounted;
|
||||
private final Level level;
|
||||
|
||||
private final boolean isMounting;
|
||||
|
||||
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, Level level, boolean isMounting) {
|
||||
super(entityMounting);
|
||||
this.entityMounting = entityMounting;
|
||||
this.entityBeingMounted = entityBeingMounted;
|
||||
this.level = level;
|
||||
this.isMounting = isMounting;
|
||||
}
|
||||
|
||||
public boolean isMounting() {
|
||||
return isMounting;
|
||||
@Override
|
||||
public Entity getEntity() {
|
||||
return getEntityMounting;
|
||||
}
|
||||
|
||||
public boolean isDismounting() {
|
||||
return !isMounting;
|
||||
}
|
||||
|
||||
public Entity getEntityMounting() {
|
||||
return entityMounting;
|
||||
}
|
||||
|
||||
public Entity getEntityBeingMounted() {
|
||||
return entityBeingMounted;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -7,36 +7,22 @@ package net.minecraftforge.event.entity;
|
||||
|
||||
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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* EntityStruckByLightningEvent is fired when an Entity is about to be struck by lightening.<br>
|
||||
* EntityStruckByLightningEvent is fired when an Entity is about to be struck by lightning.<br>
|
||||
* This event is fired whenever an EntityLightningBolt is updated to strike an Entity in
|
||||
* {@link LightningBolt#tick()} via {@link ForgeEventFactory#onEntityStruckByLightning(Entity, LightningBolt)}.<br>
|
||||
* <br>
|
||||
* {@link #lightning} contains the instance of EntityLightningBolt attempting to strike an entity.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If this event is canceled, the Entity is not struck by the lightening.<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 final class EntityStruckByLightningEvent extends EntityEvent implements Cancellable {
|
||||
* This event is {@linkplain Cancellable cancellable}.<br>
|
||||
* If this event is cancelled, the Entity is not struck by the lightning.<br>
|
||||
*
|
||||
* @param getLightning the instance of EntityLightningBolt attempting to strike an entity.
|
||||
*/
|
||||
public record EntityStruckByLightningEvent(Entity getEntity, LightningBolt getLightning)
|
||||
implements Cancellable, EntityEvent, RecordEvent {
|
||||
public static final CancellableEventBus<EntityStruckByLightningEvent> BUS = CancellableEventBus.create(EntityStruckByLightningEvent.class);
|
||||
|
||||
private final LightningBolt lightning;
|
||||
|
||||
public EntityStruckByLightningEvent(Entity entity, LightningBolt lightning) {
|
||||
super(entity);
|
||||
this.lightning = lightning;
|
||||
}
|
||||
|
||||
public LightningBolt getLightning() {
|
||||
return lightning;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.InheritableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -20,28 +21,29 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent is fired when an event involving any teleportation of an Entity occurs.<br>
|
||||
* If a method utilizes this {@link Event} as its parameter, the method will
|
||||
* receive every child event of this class.<br>
|
||||
* <br>
|
||||
* {@link #getTarget()} contains the target destination.<br>
|
||||
* {@link #getPrev()} contains the entity's current position.<br>
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public sealed class EntityTeleportEvent extends EntityEvent implements Cancellable {
|
||||
public sealed abstract class EntityTeleportEvent implements Cancellable, EntityEvent, InheritableEvent {
|
||||
public static final CancellableEventBus<EntityTeleportEvent> BUS = CancellableEventBus.create(EntityTeleportEvent.class);
|
||||
|
||||
private final Entity entity;
|
||||
protected double targetX;
|
||||
protected double targetY;
|
||||
protected double targetZ;
|
||||
|
||||
public EntityTeleportEvent(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity);
|
||||
protected EntityTeleportEvent(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
this.entity = entity;
|
||||
this.targetX = targetX;
|
||||
this.targetY = targetY;
|
||||
this.targetZ = targetZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public double getTargetX() { return targetX; }
|
||||
public void setTargetX(double targetX) { this.targetX = targetX; }
|
||||
public double getTargetY() { return targetY; }
|
||||
@@ -58,16 +60,9 @@ public sealed class EntityTeleportEvent extends EntityEvent implements Cancellab
|
||||
* EntityTeleportEvent.TeleportCommand is fired before a living entity is teleported
|
||||
* from use of {@link net.minecraft.server.commands.TeleportCommand}.
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* This event is {@link Cancellable}. If the event is cancelled, the entity will not be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.
|
||||
*/
|
||||
public static final class TeleportCommand extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<TeleportCommand> BUS = CancellableEventBus.create(TeleportCommand.class);
|
||||
@@ -81,16 +76,9 @@ public sealed class EntityTeleportEvent extends EntityEvent implements Cancellab
|
||||
* EntityTeleportEvent.SpreadPlayersCommand is fired before a living entity is teleported
|
||||
* from use of {@link net.minecraft.server.commands.SpreadPlayersCommand}.
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the entity will not be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.
|
||||
*/
|
||||
public static final class SpreadPlayersCommand extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<SpreadPlayersCommand> BUS = CancellableEventBus.create(SpreadPlayersCommand.class);
|
||||
@@ -103,16 +91,9 @@ public sealed class EntityTeleportEvent extends EntityEvent implements Cancellab
|
||||
/**
|
||||
* EntityTeleportEvent.EnderEntity is fired before an Enderman or Shulker randomly teleports.
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* This event is {@linkplain Cancellable cancelable}. If the event is cancelled, the entity will not be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.
|
||||
*/
|
||||
public static final class EnderEntity extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<EnderEntity> BUS = CancellableEventBus.create(EnderEntity.class);
|
||||
@@ -132,16 +113,9 @@ public sealed class EntityTeleportEvent extends EntityEvent implements Cancellab
|
||||
/**
|
||||
* EntityTeleportEvent.EnderPearl is fired before an Entity is teleported from an EnderPearlEntity.
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the entity will not be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.
|
||||
*/
|
||||
public static final class EnderPearl extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<EnderPearl> BUS = CancellableEventBus.create(EnderPearl.class);
|
||||
@@ -185,16 +159,9 @@ public sealed class EntityTeleportEvent extends EntityEvent implements Cancellab
|
||||
/**
|
||||
* EntityTeleportEvent.ChorusFruit is fired before a LivingEntity is teleported due to consuming Chorus Fruit.
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the entity will not be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
* This event is only fired on the {@link LogicalSide#SERVER} side.
|
||||
*/
|
||||
public static final class ChorusFruit extends EntityTeleportEvent {
|
||||
public static final CancellableEventBus<ChorusFruit> BUS = CancellableEventBus.create(ChorusFruit.class);
|
||||
|
||||
@@ -8,33 +8,19 @@ package net.minecraftforge.event.entity;
|
||||
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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* EntityTravelToDimensionEvent is fired before an Entity travels to a dimension.<br>
|
||||
* <br>
|
||||
* {@link #dimension} contains the id of the dimension the entity is traveling to.<br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If this event is canceled, the Entity does not travel to the dimension.<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 final class EntityTravelToDimensionEvent extends EntityEvent implements Cancellable {
|
||||
* This event is {@linkplain Cancellable cancellable}.<br>
|
||||
* If this event is cancelled, the Entity does not travel to the dimension.
|
||||
*
|
||||
* @param getDimension the dimension the entity is travelling to
|
||||
*/
|
||||
public record EntityTravelToDimensionEvent(Entity getEntity, ResourceKey<Level> getDimension)
|
||||
implements Cancellable, EntityEvent, RecordEvent {
|
||||
public static final CancellableEventBus<EntityTravelToDimensionEvent> BUS = CancellableEventBus.create(EntityTravelToDimensionEvent.class);
|
||||
|
||||
private final ResourceKey<Level> dimension;
|
||||
|
||||
public EntityTravelToDimensionEvent(Entity entity, ResourceKey<Level> dimension) {
|
||||
super(entity);
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public ResourceKey<Level> getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,13 @@
|
||||
|
||||
package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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 net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -23,7 +25,7 @@ import java.util.Objects;
|
||||
* You can also directly set the {@link ImpactResult} to change the impact behaviour.
|
||||
* @see #setImpactResult(ImpactResult)
|
||||
*/
|
||||
public final class ProjectileImpactEvent extends EntityEvent {
|
||||
public final class ProjectileImpactEvent extends MutableEvent implements EntityEvent {
|
||||
public static final EventBus<ProjectileImpactEvent> BUS = EventBus.create(ProjectileImpactEvent.class);
|
||||
|
||||
private final HitResult ray;
|
||||
@@ -32,11 +34,15 @@ public final class ProjectileImpactEvent extends EntityEvent {
|
||||
private ImpactResult result = ImpactResult.DEFAULT;
|
||||
|
||||
public ProjectileImpactEvent(Projectile projectile, HitResult ray) {
|
||||
super(projectile);
|
||||
this.ray = ray;
|
||||
this.projectile = projectile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getEntity() {
|
||||
return projectile;
|
||||
}
|
||||
|
||||
public HitResult getRayTraceResult() {
|
||||
return ray;
|
||||
}
|
||||
|
||||
@@ -7,7 +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;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Base class for all {@link ItemEntity} events. Contains a reference to the
|
||||
@@ -15,26 +15,11 @@ import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
* additional useful data from the firing method that isn't already contained
|
||||
* within the ItemEntity instance.
|
||||
*/
|
||||
public sealed class ItemEvent extends EntityEvent permits ItemExpireEvent, ItemTossEvent {
|
||||
public static final EventBus<ItemEvent> BUS = EventBus.create(ItemEvent.class);
|
||||
|
||||
private final ItemEntity itemEntity;
|
||||
|
||||
/**
|
||||
* Creates a new event for an {@link ItemEntity}.
|
||||
*
|
||||
* @param itemEntity The ItemEntity for this event
|
||||
*/
|
||||
public ItemEvent(ItemEntity itemEntity) {
|
||||
super(itemEntity);
|
||||
this.itemEntity = itemEntity;
|
||||
}
|
||||
|
||||
@NullMarked
|
||||
public sealed interface ItemEvent extends EntityEvent permits ItemExpireEvent, ItemTossEvent {
|
||||
/**
|
||||
* The relevant {@link ItemEntity} for this event.
|
||||
*/
|
||||
@Override
|
||||
public ItemEntity getEntity() {
|
||||
return itemEntity;
|
||||
}
|
||||
ItemEntity getEntity();
|
||||
}
|
||||
@@ -7,17 +7,21 @@ package net.minecraftforge.event.entity.item;
|
||||
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Event that is fired when an EntityItem's age has reached its maximum
|
||||
* lifespan. Canceling this event will prevent the EntityItem from being
|
||||
* 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.
|
||||
* lifespan. Cancelling this event will prevent the EntityItem from being
|
||||
* flagged as dead, thus staying its removal from the world.<br>
|
||||
* If cancelled, it will add more time to the entity's life equal to extraLife.
|
||||
*/
|
||||
public final class ItemExpireEvent extends ItemEvent implements Cancellable {
|
||||
@NullMarked
|
||||
public final class ItemExpireEvent extends MutableEvent implements Cancellable, ItemEvent {
|
||||
public static final CancellableEventBus<ItemExpireEvent> BUS = CancellableEventBus.create(ItemExpireEvent.class);
|
||||
|
||||
private final ItemEntity entityItem;
|
||||
private int extraLife;
|
||||
|
||||
/**
|
||||
@@ -27,10 +31,15 @@ public final class ItemExpireEvent extends ItemEvent implements Cancellable {
|
||||
* @param extraLife The amount of time to be added to this entities lifespan if the event is canceled.
|
||||
*/
|
||||
public ItemExpireEvent(ItemEntity entityItem, int extraLife) {
|
||||
super(entityItem);
|
||||
this.entityItem = entityItem;
|
||||
this.setExtraLife(extraLife);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemEntity getEntity() {
|
||||
return entityItem;
|
||||
}
|
||||
|
||||
public int getExtraLife() {
|
||||
return extraLife;
|
||||
}
|
||||
|
||||
@@ -8,34 +8,20 @@ package net.minecraftforge.event.entity.item;
|
||||
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.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Event that is fired whenever a player tosses (Q) an item or drag-n-drops a
|
||||
* stack of items outside the inventory GUI screens. Canceling the event will
|
||||
* stack of items outside the inventory GUI screens. Cancelling the event will
|
||||
* stop the items from entering the world, but will not prevent them being
|
||||
* removed from the inventory - and thus removed from the system.
|
||||
*
|
||||
* @param getEntity The EntityItem being tossed.
|
||||
* @param getPlayer The player tossing the item.
|
||||
*/
|
||||
public final class ItemTossEvent extends ItemEvent implements Cancellable {
|
||||
@NullMarked
|
||||
public record ItemTossEvent(ItemEntity getEntity, Player getPlayer) implements Cancellable, ItemEvent, RecordEvent {
|
||||
public static final CancellableEventBus<ItemTossEvent> BUS = CancellableEventBus.create(ItemTossEvent.class);
|
||||
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Creates a new event for EntityItems tossed by a player.
|
||||
*
|
||||
* @param entityItem The EntityItem being tossed.
|
||||
* @param player The player tossing the item.
|
||||
*/
|
||||
public ItemTossEvent(ItemEntity entityItem, Player player) {
|
||||
super(entityItem);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player tossing the item.
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -5,37 +5,25 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
* This event is fired when an {@link Animal} is tamed. <br>
|
||||
* It is fired via {@link ForgeEventFactory#onAnimalTame(Animal, Player)}.
|
||||
* Forge fires this event for applicable vanilla animals, mods need to fire it themselves.
|
||||
* 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}.
|
||||
* This event is {@linkplain Cancellable cancellable}. If cancelled, taming the animal will fail.
|
||||
*/
|
||||
public final class AnimalTameEvent extends LivingEvent implements Cancellable {
|
||||
public record AnimalTameEvent(Animal getAnimal, Player getTamer) implements Cancellable, LivingEvent, RecordEvent {
|
||||
public static final CancellableEventBus<AnimalTameEvent> BUS = CancellableEventBus.create(AnimalTameEvent.class);
|
||||
|
||||
private final Animal animal;
|
||||
private final Player tamer;
|
||||
|
||||
public AnimalTameEvent(Animal animal, Player tamer) {
|
||||
super(animal);
|
||||
this.animal = animal;
|
||||
this.tamer = tamer;
|
||||
}
|
||||
|
||||
public Animal getAnimal() {
|
||||
return animal;
|
||||
}
|
||||
|
||||
public Player getTamer() {
|
||||
return tamer;
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return getAnimal;
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,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.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
@@ -21,28 +21,13 @@ import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onLivingAttack(LivingEntity, DamageSource, float)}.<br>
|
||||
* <br>
|
||||
* {@link #source} contains the DamageSource of the attack. <br>
|
||||
* {@link #amount} contains the amount of damage dealt to the entity. <br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If this event is canceled, the Entity does not take attack damage.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
*<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public final class LivingAttackEvent extends LivingEvent implements Cancellable {
|
||||
* This event is {@linkplain Cancellable cancellable}.<br>
|
||||
* If this event is canceled, the Entity does not take attack damage.
|
||||
*
|
||||
* @param getSource the source of the attack
|
||||
* @param getAmount the amount of damage dealt to the entity
|
||||
*/
|
||||
public record LivingAttackEvent(LivingEntity getEntity, DamageSource getSource, float getAmount)
|
||||
implements Cancellable, LivingEvent, RecordEvent {
|
||||
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) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public DamageSource getSource() { return source; }
|
||||
public float getAmount() { return amount; }
|
||||
}
|
||||
@@ -6,26 +6,21 @@
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
/**
|
||||
* LivingBreatheEvent is fired whenever a living entity ticks.<br>
|
||||
* <br>
|
||||
* This event is fired via {@link ForgeHooks#onLivingBreathe(LivingEntity, int, int)}.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on {@link MinecraftForge#EVENT_BUS}
|
||||
*/
|
||||
public final class LivingBreatheEvent extends LivingEvent {
|
||||
public final class LivingBreatheEvent extends MutableEvent implements LivingEvent {
|
||||
public static final EventBus<LivingBreatheEvent> BUS = EventBus.create(LivingBreatheEvent.class);
|
||||
|
||||
private final LivingEntity entity;
|
||||
private boolean canBreathe;
|
||||
private boolean canRefillAir;
|
||||
private int consumeAirAmount;
|
||||
@@ -33,13 +28,18 @@ public final class LivingBreatheEvent extends LivingEvent {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public LivingBreatheEvent(LivingEntity entity, boolean canBreathe, int consumeAirAmount, int refillAirAmount, boolean canRefillAir) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
this.canBreathe = canBreathe;
|
||||
this.canRefillAir = canRefillAir;
|
||||
this.consumeAirAmount = Math.max(consumeAirAmount, 0);
|
||||
this.refillAirAmount = Math.max(refillAirAmount, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the entity can breathe and {@link #canRefillAir()} returns true, their air value will be increased by {@link #getRefillAirAmount()}.<br>
|
||||
* If the entity can breathe and {@link #canRefillAir()} returns false, their air value will stay the same.<br>
|
||||
|
||||
@@ -9,8 +9,8 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
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.bus.CancellableEventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
|
||||
/**
|
||||
@@ -25,29 +25,31 @@ import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
|
||||
* The return value can be affected by calling {@link #setNewTarget(LivingEntity)}.<br>
|
||||
* {@link #getTargetType()} returns the target type that caused the change of targets.<br>
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* This event is {@linkplain Cancellable cancellable}.<br>
|
||||
* <br>
|
||||
* If you cancel this event, the target will not be changed and it will stay the same.
|
||||
* Cancelling this event will prevent {@link LivingSetAttackTargetEvent} from being posted.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
*/
|
||||
public final class LivingChangeTargetEvent extends LivingEvent implements Cancellable {
|
||||
public final class LivingChangeTargetEvent extends MutableEvent implements Cancellable, LivingEvent {
|
||||
public static final CancellableEventBus<LivingChangeTargetEvent> BUS = CancellableEventBus.create(LivingChangeTargetEvent.class);
|
||||
|
||||
private final LivingEntity entity;
|
||||
private final ILivingTargetType targetType;
|
||||
private final LivingEntity originalTarget;
|
||||
private LivingEntity newTarget;
|
||||
|
||||
public LivingChangeTargetEvent(LivingEntity entity, LivingEntity originalTarget, ILivingTargetType targetType) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
this.originalTarget = originalTarget;
|
||||
this.newTarget = originalTarget;
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the new target of this entity.}
|
||||
*/
|
||||
|
||||
Loaded 100 of 490 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user