mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Some patch cleanup (#9951)
This commit is contained in:
1 parent
0cad6b14d9
commit
58012bfb17
18 files changed
+233
-113
No files matched your search
@@ -14,7 +14,7 @@ import net.minecraft.client.renderer.RenderType;
|
||||
* be the same as {@code entity}.
|
||||
*/
|
||||
public record RenderTypeGroup(RenderType block, RenderType entity, RenderType entityFabulous) {
|
||||
public static RenderTypeGroup EMPTY = new RenderTypeGroup(null, null, null);
|
||||
public static final RenderTypeGroup EMPTY = new RenderTypeGroup(null, null, null);
|
||||
|
||||
public RenderTypeGroup {
|
||||
if ((block == null) != (entity == null) || (block == null) != (entityFabulous == null))
|
||||
|
||||
@@ -10,6 +10,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
@@ -50,31 +55,46 @@ import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundSourceEvent;
|
||||
import net.minecraftforge.client.event.sound.PlayStreamingSourceEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class ForgeEventFactoryClient {
|
||||
private static final ModLoader ML = ModLoader.get();
|
||||
|
||||
private ForgeEventFactoryClient() {}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link MinecraftForge#EVENT_BUS}
|
||||
* @return true if the event is {@link Cancelable} and has been canceled
|
||||
*/
|
||||
private static boolean post(Event e) {
|
||||
return MinecraftForge.EVENT_BUS.post(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link MinecraftForge#EVENT_BUS}, then return the event object
|
||||
* @return the event object passed in and possibly modified by listeners
|
||||
*/
|
||||
private static <E extends Event> E fire(E e) {
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
post(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link ModLoader#get()} event bus
|
||||
*/
|
||||
private static <T extends Event & IModBusEvent> void postModBus(T e) {
|
||||
ML.postEvent(e);
|
||||
}
|
||||
|
||||
public static void onGatherLayers(Map<EntityType<?>, EntityRenderer<?>> renderers, Map<Model, EntityRenderer<? extends Player>> playerRenderers, Context context) {
|
||||
// TODO: Why is this a ModLoader event...
|
||||
ModLoader.get().postEvent(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, context));
|
||||
postModBus(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, context));
|
||||
}
|
||||
|
||||
public static void onRegisterShaders(ResourceProvider resourceProvider, List<Pair<ShaderInstance, Consumer<ShaderInstance>>> shaderList) {
|
||||
// TODO: Why i this a ModLoader event...
|
||||
ModLoader.get().postEvent(new RegisterShadersEvent(resourceProvider, shaderList));
|
||||
// TODO: Why is this a ModLoader event...
|
||||
postModBus(new RegisterShadersEvent(resourceProvider, shaderList));
|
||||
}
|
||||
|
||||
public static void onScreenMouseReleased(boolean[] state, Screen screen, double mouseX, double mouseY, int button) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import net.minecraft.client.renderer.entity.layers.ElytraLayer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public interface IForgeElytraLayer<T> {
|
||||
/**
|
||||
* Determines if the ElytraLayer should render.
|
||||
* ItemStack and Entity are provided for modder convenience,
|
||||
* For example, using the same ElytraLayer for multiple custom Elytra.
|
||||
*
|
||||
* @param stack The Elytra ItemStack
|
||||
* @param entity The entity being rendered.
|
||||
* @return If the ElytraLayer should render.
|
||||
*/
|
||||
default boolean shouldRender(ItemStack stack, T entity) {
|
||||
return stack.getItem() == Items.ELYTRA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the texture to use with this ElytraLayer.
|
||||
* This assumes the vanilla Elytra model.
|
||||
*
|
||||
* @param stack The Elytra ItemStack.
|
||||
* @param entity The entity being rendered.
|
||||
* @return The texture.
|
||||
*/
|
||||
default ResourceLocation getElytraTexture(ItemStack stack, T entity) {
|
||||
return ElytraLayer.WINGS_LOCATION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link VertexFormat}.
|
||||
*/
|
||||
public interface IForgeVertexFormat {
|
||||
ImmutableList<VertexFormatElement> getElements();
|
||||
|
||||
default boolean hasPosition() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.POSITION);
|
||||
}
|
||||
|
||||
default boolean hasNormal() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.NORMAL);
|
||||
}
|
||||
|
||||
default boolean hasColor() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.COLOR);
|
||||
}
|
||||
|
||||
default boolean hasUV(int which) {
|
||||
for (var e : getElements()) {
|
||||
if (e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == which) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -226,10 +226,6 @@ public final class ForgeHooks {
|
||||
return brainBuilder.makeBrain(dynamic);
|
||||
}
|
||||
|
||||
public static boolean onLivingTick(LivingEntity entity) {
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingTickEvent(entity));
|
||||
}
|
||||
|
||||
public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) {
|
||||
return entity instanceof Player || !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
|
||||
}
|
||||
@@ -252,14 +248,6 @@ public final class ForgeHooks {
|
||||
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.getAmount());
|
||||
}
|
||||
|
||||
public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(entity, src));
|
||||
}
|
||||
|
||||
public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) {
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit));
|
||||
}
|
||||
|
||||
public static int getLootingLevel(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) {
|
||||
int looting = 0;
|
||||
if (killer instanceof LivingEntity living)
|
||||
@@ -778,7 +766,7 @@ public final class ForgeHooks {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static synchronized void updateBurns() {
|
||||
VANILLA_BURNS.clear();
|
||||
FurnaceBlockEntity.getFuel().entrySet().forEach(e -> VANILLA_BURNS.put(ForgeRegistries.ITEMS.getDelegateOrThrow(e.getKey()), e.getValue()));
|
||||
FurnaceBlockEntity.getFuel().forEach((k, v) -> VANILLA_BURNS.put(ForgeRegistries.ITEMS.getDelegateOrThrow(k), v));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1260,4 +1248,19 @@ public final class ForgeHooks {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DyeColor getDyeColorFromItemStack(ItemStack stack) {
|
||||
if (stack.getItem() instanceof DyeItem dye)
|
||||
return dye.getDyeColor();
|
||||
|
||||
for (int x = 0; x < DyeColor.BLACK.getId(); x++) {
|
||||
var color = DyeColor.byId(x);
|
||||
if (stack.is(color.getTag())) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraftforge.common.world.ModifiableBiomeInfo;
|
||||
|
||||
public interface IForgeBiome {
|
||||
/**
|
||||
* {@return Cache of original biome data and biome data modified by biome modifiers}
|
||||
* Modified biome data is set by server after datapacks and serverconfigs load.
|
||||
* Climate and effects field reads are coremodded to redirect to this.
|
||||
**/
|
||||
ModifiableBiomeInfo modifiableBiomeInfo();
|
||||
|
||||
/**
|
||||
* {@return The biome's climate settings, with modifications if called after modifiers are applied in server init.}
|
||||
*/
|
||||
default Biome.ClimateSettings getModifiedClimateSettings() {
|
||||
return modifiableBiomeInfo().get().climateSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return The biome's client effects, with modifications if called after modifiers are applied in server init.}
|
||||
*/
|
||||
default BiomeSpecialEffects getModifiedSpecialEffects() {
|
||||
return modifiableBiomeInfo().get().effects();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -13,6 +14,11 @@ import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
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;
|
||||
@@ -113,7 +119,6 @@ import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
@@ -138,10 +143,13 @@ import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingConversionEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDrownEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHealEvent;
|
||||
@@ -154,7 +162,6 @@ import net.minecraftforge.event.entity.living.MobSpawnEvent.AllowDespawn;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.PositionCheck;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.SpawnPlacementCheck;
|
||||
import net.minecraftforge.event.entity.living.ShieldBlockEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent.ILivingTargetType;
|
||||
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementProgressEvent;
|
||||
@@ -201,27 +208,37 @@ import net.minecraftforge.event.level.SleepFinishedTimeEvent;
|
||||
import net.minecraftforge.event.network.ChannelRegistrationChangeEvent;
|
||||
import net.minecraftforge.event.network.ConnectionStartEvent;
|
||||
import net.minecraftforge.event.network.GatherLoginConfigurationTasksEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class ForgeEventFactory {
|
||||
private static final ModLoader ML = ModLoader.get();
|
||||
|
||||
private ForgeEventFactory() {}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link MinecraftForge#EVENT_BUS}
|
||||
* @return true if the event is {@link Cancelable} and has been canceled
|
||||
*/
|
||||
private static boolean post(Event e) {
|
||||
return MinecraftForge.EVENT_BUS.post(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link MinecraftForge#EVENT_BUS}, then return the event object
|
||||
* @return the event object passed in and possibly modified by listeners
|
||||
*/
|
||||
private static <E extends Event> E fire(E e) {
|
||||
post(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post an event to the {@link ModLoader#get()} event bus
|
||||
*/
|
||||
private static <T extends Event & IModBusEvent> void postModBus(T e) {
|
||||
ModLoader.get().postEvent(e);
|
||||
ML.postEvent(e);
|
||||
}
|
||||
|
||||
public static boolean onMultiBlockPlace(@Nullable Entity entity, List<BlockSnapshot> blockSnapshots, Direction direction) {
|
||||
@@ -912,6 +929,10 @@ public final class ForgeEventFactory {
|
||||
post(new EntityEvent.EnteringSection(entity, packedOldPos, packedNewPos));
|
||||
}
|
||||
|
||||
public static boolean onLivingTick(LivingEntity entity) {
|
||||
return post(new LivingEvent.LivingTickEvent(entity));
|
||||
}
|
||||
|
||||
public static LivingFallEvent onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
|
||||
return fire(new LivingFallEvent(entity, distance, damageMultiplier));
|
||||
}
|
||||
@@ -928,6 +949,14 @@ public final class ForgeEventFactory {
|
||||
return fire(new LivingKnockBackEvent(target, strength, ratioX, ratioZ));
|
||||
}
|
||||
|
||||
public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
|
||||
return post(new LivingDeathEvent(entity, src));
|
||||
}
|
||||
|
||||
public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) {
|
||||
return post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit));
|
||||
}
|
||||
|
||||
public static void onLeftClickEmpty(Player player) {
|
||||
post(new PlayerInteractEvent.LeftClickEmpty(player));
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
* {@link Player#die(DamageSource)}, and
|
||||
* {@link ServerPlayer#die(DamageSource)}. <br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onLivingDeath(LivingEntity, DamageSource)}.<br>
|
||||
* This event is fired via the {@link ForgeEventFactory#onLivingDeath(LivingEntity, DamageSource)}.<br>
|
||||
* <br>
|
||||
* {@link #source} contains the DamageSource that caused the entity to die. <br>
|
||||
* <br>
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.Collection;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired whenever an Entity dies and drops items in
|
||||
* {@link LivingEntity#die(DamageSource)}.<br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onLivingDrops(LivingEntity, DamageSource, Collection, int, boolean)} .<br>
|
||||
* This event is fired via the {@link ForgeEventFactory#onLivingDrops(LivingEntity, DamageSource, Collection, int, boolean)} .<br>
|
||||
* <br>
|
||||
* {@link #source} contains the DamageSource that caused the drop to occur.<br>
|
||||
* {@link #drops} contains the ArrayList of EntityItems that will be dropped.<br>
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.event.entity.living;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
@@ -40,7 +41,7 @@ public class LivingEvent extends EntityEvent
|
||||
/**
|
||||
* LivingUpdateEvent is fired when a LivingEntity is ticked in {@link LivingEntity#tick()}. <br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeHooks#onLivingTick(LivingEntity)}.<br>
|
||||
* This event is fired via the {@link ForgeEventFactory#onLivingTick(LivingEntity)}.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* If this event is canceled, the Entity does not update.<br>
|
||||
|
||||
Reference in new issue
Block a user