mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
1.21 Update
Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Daniel Norris <[email protected]> Co-authored-by: Ven <[email protected]>
This commit is contained in:
941 files changed
+3119
-4266
No files matched your search
@@ -7,28 +7,23 @@ package net.minecraftforge.client;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.searchtree.SearchRegistry;
|
||||
import net.minecraft.client.multiplayer.SessionSearchTrees;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.CreativeModeTabRegistry;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CreativeModeTabSearchRegistry
|
||||
{
|
||||
private static final Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> NAME_SEARCH_KEYS = new IdentityHashMap<>();
|
||||
private static final Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> TAG_SEARCH_KEYS = new IdentityHashMap<>();
|
||||
public class CreativeModeTabSearchRegistry {
|
||||
private static final Map<CreativeModeTab, SessionSearchTrees.Key> NAME_SEARCH_KEYS = new IdentityHashMap<>();
|
||||
private static final Map<CreativeModeTab, SessionSearchTrees.Key> TAG_SEARCH_KEYS = new IdentityHashMap<>();
|
||||
|
||||
public static Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> getNameSearchKeys() {
|
||||
Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> nameSearchKeys = new IdentityHashMap<>();
|
||||
public static Map<CreativeModeTab, SessionSearchTrees.Key> getNameSearchKeys() {
|
||||
Map<CreativeModeTab, SessionSearchTrees.Key> nameSearchKeys = new IdentityHashMap<>();
|
||||
|
||||
nameSearchKeys.put(CreativeModeTabs.searchTab(), getNameSearchKey(CreativeModeTabs.searchTab()));
|
||||
|
||||
for (CreativeModeTab tab : CreativeModeTabRegistry.getSortedCreativeModeTabs())
|
||||
{
|
||||
SearchRegistry.Key<ItemStack> nameSearchKey = getNameSearchKey(tab);
|
||||
for (var tab : CreativeModeTabRegistry.getSortedCreativeModeTabs()) {
|
||||
var nameSearchKey = getNameSearchKey(tab);
|
||||
if (nameSearchKey != null)
|
||||
nameSearchKeys.put(tab, nameSearchKey);
|
||||
}
|
||||
@@ -36,14 +31,13 @@ public class CreativeModeTabSearchRegistry
|
||||
return nameSearchKeys;
|
||||
}
|
||||
|
||||
public static Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> getTagSearchKeys() {
|
||||
Map<CreativeModeTab, SearchRegistry.Key<ItemStack>> tagSearchKeys = new IdentityHashMap<>();
|
||||
public static Map<CreativeModeTab, SessionSearchTrees.Key> getTagSearchKeys() {
|
||||
Map<CreativeModeTab, SessionSearchTrees.Key> tagSearchKeys = new IdentityHashMap<>();
|
||||
|
||||
tagSearchKeys.put(CreativeModeTabs.searchTab(), getTagSearchKey(CreativeModeTabs.searchTab()));
|
||||
|
||||
for (CreativeModeTab tab : CreativeModeTabRegistry.getSortedCreativeModeTabs())
|
||||
{
|
||||
SearchRegistry.Key<ItemStack> tagSearchKey = getTagSearchKey(tab);
|
||||
for (var tab : CreativeModeTabRegistry.getSortedCreativeModeTabs()) {
|
||||
var tagSearchKey = getTagSearchKey(tab);
|
||||
if (tagSearchKey != null)
|
||||
tagSearchKeys.put(tab, tagSearchKey);
|
||||
}
|
||||
@@ -52,32 +46,24 @@ public class CreativeModeTabSearchRegistry
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SearchRegistry.Key<ItemStack> getNameSearchKey(CreativeModeTab tab)
|
||||
{
|
||||
public static SessionSearchTrees.Key getNameSearchKey(CreativeModeTab tab) {
|
||||
if (tab == CreativeModeTabs.searchTab())
|
||||
return SearchRegistry.CREATIVE_NAMES;
|
||||
return SessionSearchTrees.CREATIVE_NAMES;
|
||||
|
||||
if (!tab.hasSearchBar())
|
||||
return null;
|
||||
|
||||
return NAME_SEARCH_KEYS.computeIfAbsent(tab, k -> new SearchRegistry.Key<>());
|
||||
return NAME_SEARCH_KEYS.computeIfAbsent(tab, k -> new SessionSearchTrees.Key());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SearchRegistry.Key<ItemStack> getTagSearchKey(CreativeModeTab tab)
|
||||
{
|
||||
public static SessionSearchTrees.Key getTagSearchKey(CreativeModeTab tab) {
|
||||
if (tab == CreativeModeTabs.searchTab())
|
||||
return SearchRegistry.CREATIVE_TAGS;
|
||||
return SessionSearchTrees.CREATIVE_TAGS;
|
||||
|
||||
if (!tab.hasSearchBar())
|
||||
return null;
|
||||
|
||||
return TAG_SEARCH_KEYS.computeIfAbsent(tab, k -> new SearchRegistry.Key<>());
|
||||
}
|
||||
|
||||
// We do it this way to prevent unwanted classloading
|
||||
@ApiStatus.Internal
|
||||
public static void createSearchTrees() {
|
||||
Minecraft.getInstance().createSearchTrees();
|
||||
return TAG_SEARCH_KEYS.computeIfAbsent(tab, k -> new SessionSearchTrees.Key());
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,12 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.mojang.math.Constants;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.FileUtil;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
@@ -42,21 +40,17 @@ import net.minecraft.client.model.Model;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||
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.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
@@ -68,21 +62,19 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.ChatTypeDecoration;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
@@ -94,18 +86,14 @@ import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
@@ -118,7 +106,6 @@ import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
||||
import net.minecraftforge.client.event.ClientPauseChangeEvent;
|
||||
import net.minecraftforge.client.event.ClientPlayerChangeGameTypeEvent;
|
||||
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.minecraftforge.client.event.ComputeFovModifierEvent;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
@@ -132,14 +119,12 @@ import net.minecraftforge.client.event.RegisterColorHandlersEvent;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
import net.minecraftforge.client.event.RenderArmEvent;
|
||||
import net.minecraftforge.client.event.RenderBlockScreenEffectEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.client.event.ScreenshotEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.event.ToastAddEvent;
|
||||
import net.minecraftforge.client.event.ViewportEvent;
|
||||
@@ -180,7 +165,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -424,11 +408,11 @@ public class ForgeHooksClient {
|
||||
}
|
||||
}
|
||||
|
||||
public static void onModifyBakingResult(Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
public static void onModifyBakingResult(Map<ModelResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
ModLoader.get().postEvent(new ModelEvent.ModifyBakingResult(models, modelBakery));
|
||||
}
|
||||
|
||||
public static void onModelBake(ModelManager modelManager, Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
public static void onModelBake(ModelManager modelManager, Map<ModelResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery));
|
||||
}
|
||||
|
||||
@@ -526,8 +510,8 @@ public class ForgeHooksClient {
|
||||
}
|
||||
|
||||
public static CustomizeGuiOverlayEvent.BossEventProgress onCustomizeBossEventProgress(GuiGraphics guiGraphics, Window window, LerpingBossEvent bossInfo, int x, int y, int increment) {
|
||||
CustomizeGuiOverlayEvent.BossEventProgress evt = new CustomizeGuiOverlayEvent.BossEventProgress(window, guiGraphics,
|
||||
Minecraft.getInstance().getPartialTick(), bossInfo, x, y, increment);
|
||||
var evt = new CustomizeGuiOverlayEvent.BossEventProgress(window, guiGraphics,
|
||||
Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false), bossInfo, x, y, increment);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt;
|
||||
}
|
||||
@@ -535,7 +519,7 @@ public class ForgeHooksClient {
|
||||
public static void onCustomizeChatEvent(GuiGraphics guiGraphics, ChatComponent chat, Window window, int mouseX, int mouseY, int tickCount) {
|
||||
var minecraft = Minecraft.getInstance();
|
||||
minecraft.getProfiler().push("chat");
|
||||
CustomizeGuiOverlayEvent.Chat evt = new CustomizeGuiOverlayEvent.Chat(window, guiGraphics, minecraft.getFrameTime(), 0, chat.getHeight() - 40);
|
||||
var evt = new CustomizeGuiOverlayEvent.Chat(window, guiGraphics, minecraft.getTimer().getRealtimeDeltaTicks(), 0, chat.getHeight() - 40);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
guiGraphics.pose().pushPose();
|
||||
// We give the absolute Y position of the chat component in the event and account for the chat component's own offsetting here.
|
||||
@@ -686,7 +670,7 @@ public class ForgeHooksClient {
|
||||
}, () -> target.forgeData = new ExtendedServerListData("VANILLA", NetworkRegistry.canConnectToVanillaServer(),0, null));
|
||||
}
|
||||
|
||||
private static final ResourceLocation ICON_SHEET = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/icons.png");
|
||||
private static final ResourceLocation ICON_SHEET = ResourceLocation.fromNamespaceAndPath(ForgeVersion.MOD_ID, "textures/gui/icons.png");
|
||||
public static void drawForgePingInfo(JoinMultiplayerScreen gui, ServerData target, GuiGraphics guiGraphics, int x, int y, int width, int relativeMouseX, int relativeMouseY) {
|
||||
int idx;
|
||||
String tooltip;
|
||||
@@ -752,7 +736,7 @@ public class ForgeHooksClient {
|
||||
ModLoader.get().postEvent(new RegisterKeyMappingsEvent(options));
|
||||
}
|
||||
|
||||
public static void onRegisterAdditionalModels(Set<ResourceLocation> additionalModels) {
|
||||
public static void onRegisterAdditionalModels(Set<ModelResourceLocation> additionalModels) {
|
||||
ModLoader.get().postEvent(new ModelEvent.RegisterAdditional(additionalModels));
|
||||
}
|
||||
|
||||
@@ -804,7 +788,7 @@ public class ForgeHooksClient {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerShaders(RegisterShadersEvent event) throws IOException {
|
||||
event.registerShader(new ShaderInstance(event.getResourceProvider(), new ResourceLocation("forge","rendertype_entity_unlit_translucent"), DefaultVertexFormat.NEW_ENTITY), (p_172645_) -> {
|
||||
event.registerShader(new ShaderInstance(event.getResourceProvider(), ResourceLocation.fromNamespaceAndPath("forge", "rendertype_entity_unlit_translucent"), DefaultVertexFormat.NEW_ENTITY), (p_172645_) -> {
|
||||
rendertypeEntityTranslucentUnlitShader = p_172645_;
|
||||
});
|
||||
}
|
||||
@@ -955,10 +939,10 @@ public class ForgeHooksClient {
|
||||
}
|
||||
|
||||
public static ResourceLocation getShaderImportLocation(String basePath, boolean isRelative, String importPath) {
|
||||
final var loc = new ResourceLocation(importPath);
|
||||
final var loc = ResourceLocation.parse(importPath);
|
||||
final var normalised = FileUtil.normalizeResourcePath(
|
||||
(isRelative ? basePath : "shaders/include/") + loc.getPath());
|
||||
return new ResourceLocation(loc.getNamespace(), normalised);
|
||||
return loc.withPath(normalised);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,21 +20,18 @@ import java.util.Map;
|
||||
* <p>
|
||||
* Provides a lookup.
|
||||
*/
|
||||
public final class NamedRenderTypeManager
|
||||
{
|
||||
public final class NamedRenderTypeManager {
|
||||
private static ImmutableMap<ResourceLocation, RenderTypeGroup> RENDER_TYPES;
|
||||
|
||||
/**
|
||||
* Finds the {@link RenderTypeGroup} for a given name, or the {@link RenderTypeGroup#EMPTY empty group} if not found.
|
||||
*/
|
||||
public static RenderTypeGroup get(ResourceLocation name)
|
||||
{
|
||||
public static RenderTypeGroup get(ResourceLocation name) {
|
||||
return RENDER_TYPES.getOrDefault(name, RenderTypeGroup.EMPTY);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void init()
|
||||
{
|
||||
public static void init() {
|
||||
var renderTypes = new HashMap<ResourceLocation, RenderTypeGroup>();
|
||||
preRegisterVanillaRenderTypes(renderTypes);
|
||||
var event = new RegisterNamedRenderTypesEvent(renderTypes);
|
||||
@@ -45,18 +42,19 @@ public final class NamedRenderTypeManager
|
||||
/**
|
||||
* Pre-registers vanilla render types.
|
||||
*/
|
||||
private static void preRegisterVanillaRenderTypes(Map<ResourceLocation, RenderTypeGroup> blockRenderTypes)
|
||||
{
|
||||
blockRenderTypes.put(new ResourceLocation("solid"), new RenderTypeGroup(RenderType.solid(), ForgeRenderTypes.ITEM_LAYERED_SOLID.get()));
|
||||
blockRenderTypes.put(new ResourceLocation("cutout"), new RenderTypeGroup(RenderType.cutout(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT.get()));
|
||||
private static void preRegisterVanillaRenderTypes(Map<ResourceLocation, RenderTypeGroup> blockRenderTypes) {
|
||||
blockRenderTypes.put(rl("solid"), new RenderTypeGroup(RenderType.solid(), ForgeRenderTypes.ITEM_LAYERED_SOLID.get()));
|
||||
blockRenderTypes.put(rl("cutout"), new RenderTypeGroup(RenderType.cutout(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT.get()));
|
||||
// Generally entity/item rendering shouldn't use mipmaps, so cutout_mipped has them off by default. To enforce them, use cutout_mipped_all.
|
||||
blockRenderTypes.put(new ResourceLocation("cutout_mipped"), new RenderTypeGroup(RenderType.cutoutMipped(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT.get()));
|
||||
blockRenderTypes.put(new ResourceLocation("cutout_mipped_all"), new RenderTypeGroup(RenderType.cutoutMipped(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT_MIPPED.get()));
|
||||
blockRenderTypes.put(new ResourceLocation("translucent"), new RenderTypeGroup(RenderType.translucent(), ForgeRenderTypes.ITEM_LAYERED_TRANSLUCENT.get()));
|
||||
blockRenderTypes.put(new ResourceLocation("tripwire"), new RenderTypeGroup(RenderType.tripwire(), ForgeRenderTypes.ITEM_LAYERED_TRANSLUCENT.get()));
|
||||
blockRenderTypes.put(rl("cutout_mipped"), new RenderTypeGroup(RenderType.cutoutMipped(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT.get()));
|
||||
blockRenderTypes.put(rl("cutout_mipped_all"), new RenderTypeGroup(RenderType.cutoutMipped(), ForgeRenderTypes.ITEM_LAYERED_CUTOUT_MIPPED.get()));
|
||||
blockRenderTypes.put(rl("translucent"), new RenderTypeGroup(RenderType.translucent(), ForgeRenderTypes.ITEM_LAYERED_TRANSLUCENT.get()));
|
||||
blockRenderTypes.put(rl("tripwire"), new RenderTypeGroup(RenderType.tripwire(), ForgeRenderTypes.ITEM_LAYERED_TRANSLUCENT.get()));
|
||||
}
|
||||
|
||||
private NamedRenderTypeManager()
|
||||
{
|
||||
private static ResourceLocation rl(String paht) {
|
||||
return ResourceLocation.withDefaultNamespace(paht);
|
||||
}
|
||||
|
||||
private NamedRenderTypeManager() { }
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -24,32 +23,27 @@ import java.util.List;
|
||||
* @see DebugText
|
||||
* @see Chat
|
||||
*/
|
||||
public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
{
|
||||
public abstract class CustomizeGuiOverlayEvent extends Event {
|
||||
private final Window window;
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final float partialTick;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected CustomizeGuiOverlayEvent(Window window, GuiGraphics guiGraphics, float partialTick)
|
||||
{
|
||||
protected CustomizeGuiOverlayEvent(Window window, GuiGraphics guiGraphics, float partialTick) {
|
||||
this.window = window;
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.partialTick = partialTick;
|
||||
}
|
||||
|
||||
public Window getWindow()
|
||||
{
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public GuiGraphics getGuiGraphics()
|
||||
{
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
|
||||
public float getPartialTick()
|
||||
{
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
@@ -63,16 +57,14 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class BossEventProgress extends CustomizeGuiOverlayEvent
|
||||
{
|
||||
public static class BossEventProgress extends CustomizeGuiOverlayEvent {
|
||||
private final LerpingBossEvent bossEvent;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private int increment;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BossEventProgress(Window window, GuiGraphics guiGraphics, float partialTick, LerpingBossEvent bossEvent, int x, int y, int increment)
|
||||
{
|
||||
public BossEventProgress(Window window, GuiGraphics guiGraphics, float partialTick, LerpingBossEvent bossEvent, int x, int y, int increment) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.bossEvent = bossEvent;
|
||||
this.x = x;
|
||||
@@ -83,32 +75,28 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
/**
|
||||
* @return the boss health bar currently being rendered
|
||||
*/
|
||||
public LerpingBossEvent getBossEvent()
|
||||
{
|
||||
public LerpingBossEvent getBossEvent() {
|
||||
return bossEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the boss health bar}
|
||||
*/
|
||||
public int getX()
|
||||
{
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the boss health bar}
|
||||
*/
|
||||
public int getY()
|
||||
{
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position increment before rendering the next boss health bar}
|
||||
*/
|
||||
public int getIncrement()
|
||||
{
|
||||
public int getIncrement() {
|
||||
return increment;
|
||||
}
|
||||
|
||||
@@ -117,8 +105,7 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
*
|
||||
* @param increment the new Y position increment
|
||||
*/
|
||||
public void setIncrement(int increment)
|
||||
{
|
||||
public void setIncrement(int increment) {
|
||||
this.increment = increment;
|
||||
}
|
||||
}
|
||||
@@ -132,15 +119,13 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
* <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 class DebugText extends CustomizeGuiOverlayEvent
|
||||
{
|
||||
public static class DebugText extends CustomizeGuiOverlayEvent {
|
||||
private final List<String> text;
|
||||
|
||||
private final Side side;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public DebugText(Window window, GuiGraphics guiGraphics, float partialTick, List<String> text, Side side)
|
||||
{
|
||||
public DebugText(Window window, GuiGraphics guiGraphics, float partialTick, List<String> text, Side side) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.text = text;
|
||||
this.side = side;
|
||||
@@ -149,21 +134,10 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
/**
|
||||
* @return the modifiable list of text to render on the side
|
||||
*/
|
||||
public List<String> getText()
|
||||
{
|
||||
public List<String> getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.6")
|
||||
public List<String> getLeft() {
|
||||
return Side.Left.equals(this.side) ? this.text : new ArrayList<>();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.6")
|
||||
public List<String> getRight() {
|
||||
return Side.Right.equals(this.side) ? this.text : new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the side of the text getting rendered.
|
||||
*/
|
||||
@@ -185,14 +159,12 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
* <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 class Chat extends CustomizeGuiOverlayEvent
|
||||
{
|
||||
public static class Chat extends CustomizeGuiOverlayEvent {
|
||||
private int posX;
|
||||
private int posY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Chat(Window window, GuiGraphics guiGraphics, float partialTick, int posX, int posY)
|
||||
{
|
||||
public Chat(Window window, GuiGraphics guiGraphics, float partialTick, int posX, int posY) {
|
||||
super(window, guiGraphics, partialTick);
|
||||
this.setPosX(posX);
|
||||
this.setPosY(posY);
|
||||
@@ -201,8 +173,7 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
/**
|
||||
* @return the X position of the chat messages overlay
|
||||
*/
|
||||
public int getPosX()
|
||||
{
|
||||
public int getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
@@ -211,16 +182,14 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
*
|
||||
* @param posX the new X position
|
||||
*/
|
||||
public void setPosX(int posX)
|
||||
{
|
||||
public void setPosX(int posX) {
|
||||
this.posX = posX;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Y position of the chat messages overlay
|
||||
*/
|
||||
public int getPosY()
|
||||
{
|
||||
public int getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
@@ -229,8 +198,7 @@ public abstract class CustomizeGuiOverlayEvent extends Event
|
||||
*
|
||||
* @param posY the new y position
|
||||
*/
|
||||
public void setPosY(int posY)
|
||||
{
|
||||
public void setPosY(int posY) {
|
||||
this.posY = posY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,16 +164,6 @@ public abstract class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
return (R)skinMap.get(skinName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getEntitySkin, return type down graded to EntityRenderer instead of LivingEntityRenderer
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public <R extends LivingEntityRenderer<? extends Player, ? extends EntityModel<? extends Player>>> R getSkin(PlayerSkin.Model skinName) {
|
||||
return (R)skinMap.get(skinName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an entity renderer for the given entity type.
|
||||
*
|
||||
@@ -188,16 +178,6 @@ public abstract class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
return (R)renderers.get(entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getEntityRenderer, return type down graded to EntityRenderer instead of LivingEntityRenderer
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public <T extends LivingEntity, R extends LivingEntityRenderer<T, ? extends EntityModel<T>>> R getRenderer(EntityType<? extends T> entityType) {
|
||||
return (R) renderers.get(entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the set of entity models}
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
@@ -23,6 +24,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
@@ -254,4 +256,12 @@ public final class ForgeEventFactoryClient {
|
||||
public static void onRenderScreenBackground(Screen screen, GuiGraphics guiGraphics) {
|
||||
fire(new ScreenEvent.BackgroundRendered(screen, guiGraphics));
|
||||
}
|
||||
|
||||
public static void onRenderTickStart(DeltaTracker timer) {
|
||||
post(new TickEvent.RenderTickEvent.Start(timer));
|
||||
}
|
||||
|
||||
public static void onRenderTickEnd(DeltaTracker timer) {
|
||||
post(new TickEvent.RenderTickEvent.End(timer));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.google.common.base.Preconditions;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.geometry.IGeometryLoader;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
@@ -25,12 +26,9 @@ import java.util.Set;
|
||||
/**
|
||||
* Houses events related to models.
|
||||
*/
|
||||
public abstract class ModelEvent extends Event
|
||||
{
|
||||
public abstract class ModelEvent extends Event {
|
||||
@ApiStatus.Internal
|
||||
protected ModelEvent()
|
||||
{
|
||||
}
|
||||
protected ModelEvent() { }
|
||||
|
||||
/**
|
||||
* Fired while the {@link ModelManager} is reloading models, after the model registry is set up, but before it's
|
||||
@@ -48,14 +46,12 @@ public abstract class ModelEvent extends Event
|
||||
* <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 ModifyBakingResult extends ModelEvent implements IModBusEvent
|
||||
{
|
||||
private final Map<ResourceLocation, BakedModel> models;
|
||||
public static class ModifyBakingResult extends ModelEvent implements IModBusEvent {
|
||||
private final Map<ModelResourceLocation, BakedModel> models;
|
||||
private final ModelBakery modelBakery;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ModifyBakingResult(Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery)
|
||||
{
|
||||
public ModifyBakingResult(Map<ModelResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
this.models = models;
|
||||
this.modelBakery = modelBakery;
|
||||
}
|
||||
@@ -63,16 +59,14 @@ public abstract class ModelEvent extends Event
|
||||
/**
|
||||
* @return the modifiable registry map of models and their model names
|
||||
*/
|
||||
public Map<ResourceLocation, BakedModel> getModels()
|
||||
{
|
||||
public Map<ModelResourceLocation, BakedModel> getModels() {
|
||||
return models;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the model loader
|
||||
*/
|
||||
public ModelBakery getModelBakery()
|
||||
{
|
||||
public ModelBakery getModelBakery() {
|
||||
return modelBakery;
|
||||
}
|
||||
}
|
||||
@@ -88,15 +82,13 @@ public abstract class ModelEvent extends Event
|
||||
* <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 BakingCompleted extends ModelEvent implements IModBusEvent
|
||||
{
|
||||
public static class BakingCompleted extends ModelEvent implements IModBusEvent {
|
||||
private final ModelManager modelManager;
|
||||
private final Map<ResourceLocation, BakedModel> models;
|
||||
private final Map<ModelResourceLocation, BakedModel> models;
|
||||
private final ModelBakery modelBakery;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BakingCompleted(ModelManager modelManager, Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery)
|
||||
{
|
||||
public BakingCompleted(ModelManager modelManager, Map<ModelResourceLocation, BakedModel> models, ModelBakery modelBakery) {
|
||||
this.modelManager = modelManager;
|
||||
this.models = models;
|
||||
this.modelBakery = modelBakery;
|
||||
@@ -105,24 +97,21 @@ public abstract class ModelEvent extends Event
|
||||
/**
|
||||
* @return the model manager
|
||||
*/
|
||||
public ModelManager getModelManager()
|
||||
{
|
||||
public ModelManager getModelManager() {
|
||||
return modelManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an unmodifiable view of the registry map of models and their model names
|
||||
*/
|
||||
public Map<ResourceLocation, BakedModel> getModels()
|
||||
{
|
||||
public Map<ModelResourceLocation, BakedModel> getModels() {
|
||||
return models;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the model loader
|
||||
*/
|
||||
public ModelBakery getModelBakery()
|
||||
{
|
||||
public ModelBakery getModelBakery() {
|
||||
return modelBakery;
|
||||
}
|
||||
}
|
||||
@@ -136,21 +125,18 @@ public abstract class ModelEvent extends Event
|
||||
* <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 RegisterAdditional extends ModelEvent implements IModBusEvent
|
||||
{
|
||||
private final Set<ResourceLocation> models;
|
||||
public static class RegisterAdditional extends ModelEvent implements IModBusEvent {
|
||||
private final Set<ModelResourceLocation> models;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RegisterAdditional(Set<ResourceLocation> models)
|
||||
{
|
||||
public RegisterAdditional(Set<ModelResourceLocation> models) {
|
||||
this.models = models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a model to be loaded, along with its dependencies.
|
||||
*/
|
||||
public void register(ResourceLocation model)
|
||||
{
|
||||
public void register(ModelResourceLocation model) {
|
||||
models.add(model);
|
||||
}
|
||||
}
|
||||
@@ -163,22 +149,19 @@ public abstract class ModelEvent extends Event
|
||||
* <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 RegisterGeometryLoaders extends ModelEvent implements IModBusEvent
|
||||
{
|
||||
public static class RegisterGeometryLoaders extends ModelEvent implements IModBusEvent {
|
||||
private final Map<ResourceLocation, IGeometryLoader<?>> loaders;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RegisterGeometryLoaders(Map<ResourceLocation, IGeometryLoader<?>> loaders)
|
||||
{
|
||||
public RegisterGeometryLoaders(Map<ResourceLocation, IGeometryLoader<?>> loaders) {
|
||||
this.loaders = loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new geometry loader.
|
||||
*/
|
||||
public void register(String name, IGeometryLoader<?> loader)
|
||||
{
|
||||
var key = new ResourceLocation(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
public void register(String name, IGeometryLoader<?> loader) {
|
||||
var key = ResourceLocation.fromNamespaceAndPath(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
Preconditions.checkArgument(!loaders.containsKey(key), "Geometry loader already registered: " + key);
|
||||
loaders.put(key, loader);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class RegisterNamedRenderTypesEvent extends Event implements IModBusEvent
|
||||
*/
|
||||
public void register(String name, RenderType blockRenderType, RenderType entityRenderType, RenderType fabulousEntityRenderType)
|
||||
{
|
||||
var key = new ResourceLocation(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
var key = ResourceLocation.fromNamespaceAndPath(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
Preconditions.checkArgument(!renderTypes.containsKey(key), "Render type already registered: " + key);
|
||||
Preconditions.checkArgument(blockRenderType.format() == DefaultVertexFormat.BLOCK, "The block render type must use the BLOCK vertex format.");
|
||||
Preconditions.checkArgument(blockRenderType.getChunkLayerId() >= 0, "Only chunk render types can be used for block rendering. Query RenderType#chunkBufferLayers() for a list.");
|
||||
|
||||
+4
-7
@@ -26,22 +26,19 @@ import java.util.Map;
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public class RegisterTextureAtlasSpriteLoadersEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public class RegisterTextureAtlasSpriteLoadersEvent extends Event implements IModBusEvent {
|
||||
private final Map<ResourceLocation, ITextureAtlasSpriteLoader> loaders;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RegisterTextureAtlasSpriteLoadersEvent(Map<ResourceLocation, ITextureAtlasSpriteLoader> loaders)
|
||||
{
|
||||
public RegisterTextureAtlasSpriteLoadersEvent(Map<ResourceLocation, ITextureAtlasSpriteLoader> loaders) {
|
||||
this.loaders = loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom {@link ITextureAtlasSpriteLoader sprite loader}.
|
||||
*/
|
||||
public void register(String name, ITextureAtlasSpriteLoader loader)
|
||||
{
|
||||
var key = new ResourceLocation(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
public void register(String name, ITextureAtlasSpriteLoader loader) {
|
||||
var key = ResourceLocation.fromNamespaceAndPath(ModLoadingContext.get().getActiveNamespace(), name);
|
||||
Preconditions.checkArgument(!loaders.containsKey(key), "Sprite loader already registered: " + key);
|
||||
loaders.put(key, loader);
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class RenderLevelStageEvent extends Event {
|
||||
}
|
||||
|
||||
private static Stage register(String name, @Nullable RenderType renderType) throws IllegalArgumentException {
|
||||
return register(new ResourceLocation(name), renderType);
|
||||
return register(ResourceLocation.parse(name), renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,7 +239,7 @@ public class RenderLevelStageEvent extends Event {
|
||||
var mc = Minecraft.getInstance();
|
||||
var profiler = mc.getProfiler();
|
||||
profiler.push(this.toString());
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelStageEvent(this, levelRenderer, poseStack, projectionMatrix, renderTick, mc.getPartialTick(), camera, frustum));
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelStageEvent(this, levelRenderer, poseStack, projectionMatrix, renderTick, mc.getTimer().getRealtimeDeltaTicks(), camera, frustum));
|
||||
profiler.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,27 +9,29 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link VertexFormat}.
|
||||
*/
|
||||
public interface IForgeVertexFormat {
|
||||
ImmutableList<VertexFormatElement> getElements();
|
||||
List<VertexFormatElement> getElements();
|
||||
|
||||
default boolean hasPosition() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.POSITION);
|
||||
return getElements().stream().anyMatch(e -> e.usage() == VertexFormatElement.Usage.POSITION);
|
||||
}
|
||||
|
||||
default boolean hasNormal() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.NORMAL);
|
||||
return getElements().stream().anyMatch(e -> e.usage() == VertexFormatElement.Usage.NORMAL);
|
||||
}
|
||||
|
||||
default boolean hasColor() {
|
||||
return getElements().stream().anyMatch(e -> e.getUsage() == VertexFormatElement.Usage.COLOR);
|
||||
return getElements().stream().anyMatch(e -> e.usage() == VertexFormatElement.Usage.COLOR);
|
||||
}
|
||||
|
||||
default boolean hasUV(int which) {
|
||||
for (var e : getElements()) {
|
||||
if (e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == which) {
|
||||
if (e.usage() == VertexFormatElement.Usage.UV && e.index() == which) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -8,11 +8,13 @@ package net.minecraftforge.client.extensions.common;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -91,7 +93,8 @@ public interface IClientBlockExtensions {
|
||||
float f12 = 0.0F;
|
||||
|
||||
if (entity instanceof LivingEntity ent) {
|
||||
f12 = (float) EnchantmentHelper.getRespiration(ent) * 0.2F;
|
||||
var lookup = level.registryAccess().lookup(Registries.ENCHANTMENT).get();
|
||||
f12 = (float) EnchantmentHelper.getEnchantmentLevel(lookup.getOrThrow(Enchantments.RESPIRATION), ent) * 0.2F;
|
||||
|
||||
if (ent.hasEffect(MobEffects.WATER_BREATHING)) {
|
||||
f12 = f12 * 0.3F + 0.6F;
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
/**
|
||||
* This class provides several methods and constants used by the Config GUI classes.
|
||||
*
|
||||
* @author bspkrs
|
||||
* @deprecated Use extension methods in {@link net.minecraftforge.client.extensions.IForgeGuiGraphics} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class ScreenUtils
|
||||
{
|
||||
public static final int DEFAULT_BACKGROUND_COLOR = 0xF0100010;
|
||||
public static final int DEFAULT_BORDER_COLOR_START = 0x505000FF;
|
||||
public static final int DEFAULT_BORDER_COLOR_END = (DEFAULT_BORDER_COLOR_START & 0xFEFEFE) >> 1 | DEFAULT_BORDER_COLOR_START & 0xFF000000;
|
||||
public static final String UNDO_CHAR = "\u21B6";
|
||||
public static final String RESET_CHAR = "\u2604";
|
||||
public static final String VALID = "\u2714";
|
||||
public static final String INVALID = "\u2715";
|
||||
|
||||
public static int[] TEXT_COLOR_CODES = new int[] { 0, 170, 43520, 43690, 11141120, 11141290, 16755200, 11184810, 5592405, 5592575, 5635925, 5636095, 16733525, 16733695, 16777045, 16777215,
|
||||
0, 42, 10752, 10794, 2752512, 2752554, 2763264, 2763306, 1381653, 1381695, 1392405, 1392447, 4134165, 4134207, 4144917, 4144959 };
|
||||
|
||||
public static int getColorFromFormattingCharacter(char c, boolean isLighter)
|
||||
{
|
||||
return TEXT_COLOR_CODES[isLighter ? "0123456789abcdef".indexOf(c) : "0123456789abcdef".indexOf(c) + 16];
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. It is assumed that the desired texture ResourceLocation object has been bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param guiGraphics the gui graphics
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param borderSize the size of the box's borders
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void blitWithBorder(GuiGraphics guiGraphics, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int borderSize, float zLevel)
|
||||
{
|
||||
blitWithBorder(guiGraphics, x, y, u, v, width, height, textureWidth, textureHeight, borderSize, borderSize, borderSize, borderSize, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. The provided ResourceLocation object will be bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param guiGraphics the gui graphics
|
||||
* @param res the ResourceLocation object that contains the desired image
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param borderSize the size of the box's borders
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void blitWithBorder(GuiGraphics guiGraphics, ResourceLocation res, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int borderSize, float zLevel)
|
||||
{
|
||||
blitWithBorder(guiGraphics, res, x, y, u, v, width, height, textureWidth, textureHeight, borderSize, borderSize, borderSize, borderSize, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. The provided ResourceLocation object will be bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param guiGraphics the gui graphics
|
||||
* @param res the ResourceLocation object that contains the desired image
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param topBorder the size of the box's top border
|
||||
* @param bottomBorder the size of the box's bottom border
|
||||
* @param leftBorder the size of the box's left border
|
||||
* @param rightBorder the size of the box's right border
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void blitWithBorder(GuiGraphics guiGraphics, ResourceLocation res, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int topBorder, int bottomBorder, int leftBorder, int rightBorder, float zLevel)
|
||||
{
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, res);
|
||||
blitWithBorder(guiGraphics, x, y, u, v, width, height, textureWidth, textureHeight, topBorder, bottomBorder, leftBorder, rightBorder, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. It is assumed that the desired texture ResourceLocation object has been bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param guiGraphics the gui graphics
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param topBorder the size of the box's top border
|
||||
* @param bottomBorder the size of the box's bottom border
|
||||
* @param leftBorder the size of the box's left border
|
||||
* @param rightBorder the size of the box's right border
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void blitWithBorder(GuiGraphics guiGraphics, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int topBorder, int bottomBorder, int leftBorder, int rightBorder, float zLevel)
|
||||
{
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
int fillerWidth = textureWidth - leftBorder - rightBorder;
|
||||
int fillerHeight = textureHeight - topBorder - bottomBorder;
|
||||
int canvasWidth = width - leftBorder - rightBorder;
|
||||
int canvasHeight = height - topBorder - bottomBorder;
|
||||
int xPasses = canvasWidth / fillerWidth;
|
||||
int remainderWidth = canvasWidth % fillerWidth;
|
||||
int yPasses = canvasHeight / fillerHeight;
|
||||
int remainderHeight = canvasHeight % fillerHeight;
|
||||
|
||||
// Draw Border
|
||||
// Top Left
|
||||
drawTexturedModalRect(guiGraphics, x, y, u, v, leftBorder, topBorder, zLevel);
|
||||
// Top Right
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + canvasWidth, y, u + leftBorder + fillerWidth, v, rightBorder, topBorder, zLevel);
|
||||
// Bottom Left
|
||||
drawTexturedModalRect(guiGraphics, x, y + topBorder + canvasHeight, u, v + topBorder + fillerHeight, leftBorder, bottomBorder, zLevel);
|
||||
// Bottom Right
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + canvasWidth, y + topBorder + canvasHeight, u + leftBorder + fillerWidth, v + topBorder + fillerHeight, rightBorder, bottomBorder, zLevel);
|
||||
|
||||
for (int i = 0; i < xPasses + (remainderWidth > 0 ? 1 : 0); i++)
|
||||
{
|
||||
// Top Border
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + (i * fillerWidth), y, u + leftBorder, v, (i == xPasses ? remainderWidth : fillerWidth), topBorder, zLevel);
|
||||
// Bottom Border
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + (i * fillerWidth), y + topBorder + canvasHeight, u + leftBorder, v + topBorder + fillerHeight, (i == xPasses ? remainderWidth : fillerWidth), bottomBorder, zLevel);
|
||||
|
||||
// Throw in some filler for good measure
|
||||
for (int j = 0; j < yPasses + (remainderHeight > 0 ? 1 : 0); j++)
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + (i * fillerWidth), y + topBorder + (j * fillerHeight), u + leftBorder, v + topBorder, (i == xPasses ? remainderWidth : fillerWidth), (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
}
|
||||
|
||||
// Side Borders
|
||||
for (int j = 0; j < yPasses + (remainderHeight > 0 ? 1 : 0); j++)
|
||||
{
|
||||
// Left Border
|
||||
drawTexturedModalRect(guiGraphics, x, y + topBorder + (j * fillerHeight), u, v + topBorder, leftBorder, (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
// Right Border
|
||||
drawTexturedModalRect(guiGraphics, x + leftBorder + canvasWidth, y + topBorder + (j * fillerHeight), u + leftBorder + fillerWidth, v + topBorder, rightBorder, (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link GuiGraphics#blit(ResourceLocation, int, int, int, int, int, int)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void drawTexturedModalRect(GuiGraphics guiGraphics, int x, int y, int u, int v, int width, int height, float zLevel)
|
||||
{
|
||||
final float uScale = 1f / 0x100;
|
||||
final float vScale = 1f / 0x100;
|
||||
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder wr = tessellator.getBuilder();
|
||||
wr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
|
||||
Matrix4f matrix = guiGraphics.pose().last().pose();
|
||||
wr.vertex(matrix, x , y + height, zLevel).uv( u * uScale, ((v + height) * vScale)).endVertex();
|
||||
wr.vertex(matrix, x + width, y + height, zLevel).uv((u + width) * uScale, ((v + height) * vScale)).endVertex();
|
||||
wr.vertex(matrix, x + width, y , zLevel).uv((u + width) * uScale, ( v * vScale)).endVertex();
|
||||
wr.vertex(matrix, x , y , zLevel).uv( u * uScale, ( v * vScale)).endVertex();
|
||||
tessellator.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link GuiGraphics#fillGradient(int, int, int, int, int, int, int)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void drawGradientRect(Matrix4f mat, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor)
|
||||
{
|
||||
float startAlpha = (float)(startColor >> 24 & 255) / 255.0F;
|
||||
float startRed = (float)(startColor >> 16 & 255) / 255.0F;
|
||||
float startGreen = (float)(startColor >> 8 & 255) / 255.0F;
|
||||
float startBlue = (float)(startColor & 255) / 255.0F;
|
||||
float endAlpha = (float)(endColor >> 24 & 255) / 255.0F;
|
||||
float endRed = (float)(endColor >> 16 & 255) / 255.0F;
|
||||
float endGreen = (float)(endColor >> 8 & 255) / 255.0F;
|
||||
float endBlue = (float)(endColor & 255) / 255.0F;
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuilder();
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
buffer.vertex(mat, right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
|
||||
buffer.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
|
||||
buffer.vertex(mat, left, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex();
|
||||
buffer.vertex(mat, right, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex();
|
||||
tessellator.end();
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void blitInscribed(GuiGraphics guiGraphics, ResourceLocation texture, int x, int y, int boundsWidth, int boundsHeight, int rectWidth, int rectHeight)
|
||||
{
|
||||
blitInscribed(guiGraphics, texture, x, y, boundsWidth, boundsHeight, rectWidth, rectHeight, true, true);
|
||||
}
|
||||
|
||||
public static void blitInscribed(GuiGraphics guiGraphics, ResourceLocation texture, int x, int y, int boundsWidth, int boundsHeight, int rectWidth, int rectHeight, boolean centerX, boolean centerY)
|
||||
{
|
||||
if (rectWidth * boundsHeight > rectHeight * boundsWidth) {
|
||||
int h = boundsHeight;
|
||||
boundsHeight = (int) (boundsWidth * ((double) rectHeight / rectWidth));
|
||||
if (centerY) y += (h - boundsHeight) / 2;
|
||||
} else {
|
||||
int w = boundsWidth;
|
||||
boundsWidth = (int) (boundsHeight * ((double) rectWidth / rectHeight));
|
||||
if (centerX) x += (w - boundsWidth) / 2;
|
||||
}
|
||||
|
||||
guiGraphics.blit(texture, x, y, boundsWidth, boundsHeight, 0.0f,0.0f, rectWidth, rectHeight, rectWidth, rectHeight);
|
||||
}
|
||||
}
|
||||
@@ -19,41 +19,32 @@ import net.minecraftforge.client.loading.ClientModLoader;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class TitleScreenModUpdateIndicator extends Screen
|
||||
{
|
||||
public class TitleScreenModUpdateIndicator extends Screen {
|
||||
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = ResourceLocation.fromNamespaceAndPath(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
|
||||
|
||||
private final Button modButton;
|
||||
private VersionChecker.Status showNotification = null;
|
||||
private boolean hasCheckedForUpdates = false;
|
||||
|
||||
public TitleScreenModUpdateIndicator(Button modButton)
|
||||
{
|
||||
public TitleScreenModUpdateIndicator(Button modButton) {
|
||||
super(Component.translatable("forge.menu.updatescreen.title"));
|
||||
this.modButton = modButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
if (!hasCheckedForUpdates)
|
||||
{
|
||||
public void init() {
|
||||
if (!hasCheckedForUpdates) {
|
||||
if (modButton != null)
|
||||
{
|
||||
showNotification = ClientModLoader.checkForUpdates();
|
||||
}
|
||||
hasCheckedForUpdates = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
if (showNotification == null || !showNotification.shouldDraw() || !FMLConfig.getBoolConfigValue(FMLConfig.ConfigValue.VERSION_CHECK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int x = modButton.getX();
|
||||
int y = modButton.getY();
|
||||
@@ -63,8 +54,7 @@ public class TitleScreenModUpdateIndicator extends Screen
|
||||
guiGraphics.blit(VERSION_CHECK_ICONS, x + w - (h / 2 + 4), y + (h / 2 - 4), showNotification.getSheetOffset() * 8, (showNotification.isAnimated() && ((System.currentTimeMillis() / 800 & 1) == 1)) ? 8 : 0, 8, 8, 64, 16);
|
||||
}
|
||||
|
||||
public static TitleScreenModUpdateIndicator init(TitleScreen guiMainMenu, Button modButton)
|
||||
{
|
||||
public static TitleScreenModUpdateIndicator init(TitleScreen guiMainMenu, Button modButton) {
|
||||
TitleScreenModUpdateIndicator titleScreenModUpdateIndicator = new TitleScreenModUpdateIndicator(modButton);
|
||||
//titleScreenModUpdateIndicator.resize(guiMainMenu.getMinecraft(), guiMainMenu.width, guiMainMenu.height);
|
||||
titleScreenModUpdateIndicator.init();
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry>
|
||||
{
|
||||
private static String stripControlCodes(String value) { return net.minecraft.util.StringUtil.stripColor(value); }
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
|
||||
private static final ResourceLocation VERSION_CHECK_ICONS = ResourceLocation.fromNamespaceAndPath(ForgeVersion.MOD_ID, "textures/gui/version_check_icons.png");
|
||||
private final int listWidth;
|
||||
|
||||
private final ModListScreen parent;
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
package net.minecraftforge.client.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
@@ -151,7 +148,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* Draws the background of the scroll panel. This runs AFTER Scissors are enabled.
|
||||
*/
|
||||
protected void drawBackground(GuiGraphics guiGraphics, Tesselator tess, float partialTick) {
|
||||
BufferBuilder worldr = tess.getBuilder();
|
||||
// BufferBuilder worldr = tess.getBuilder();
|
||||
|
||||
if (this.client.level != null) {
|
||||
this.drawGradientRect(guiGraphics, this.left, this.top, this.right, this.bottom, bgColorFrom, bgColorTo);
|
||||
@@ -268,7 +265,6 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
Tesselator tess = Tesselator.getInstance();
|
||||
BufferBuilder worldr = tess.getBuilder();
|
||||
|
||||
double scale = client.getWindow().getGuiScale();
|
||||
RenderSystem.enableScissor((int)(left * scale), (int)(client.getWindow().getHeight() - (bottom * scale)),
|
||||
@@ -295,36 +291,36 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
int barBgBlue = this.barBgColor & 0xff;
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.vertex(barLeft, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth, this.top, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
worldr.vertex(barLeft, this.top, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
tess.end();
|
||||
BufferBuilder worldr = tess.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.addVertex(barLeft, this.bottom, 0.0F).setColor(barBgRed, barBgGreen, barBgBlue, barBgAlpha);
|
||||
worldr.addVertex(barLeft + barWidth, this.bottom, 0.0F).setColor(barBgRed, barBgGreen, barBgBlue, barBgAlpha);
|
||||
worldr.addVertex(barLeft + barWidth, this.top, 0.0F).setColor(barBgRed, barBgGreen, barBgBlue, barBgAlpha);
|
||||
worldr.addVertex(barLeft, this.top, 0.0F).setColor(barBgRed, barBgGreen, barBgBlue, barBgAlpha);
|
||||
BufferUploader.drawWithShader(worldr.buildOrThrow());
|
||||
|
||||
int barAlpha = this.barColor >> 24 & 0xff;
|
||||
int barRed = this.barColor >> 16 & 0xff;
|
||||
int barGreen = this.barColor >> 8 & 0xff;
|
||||
int barBlue = this.barColor & 0xff;
|
||||
|
||||
worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.vertex(barLeft, barTop + barHeight, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth, barTop + barHeight, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth, barTop, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
|
||||
worldr.vertex(barLeft, barTop, 0.0D).color(barRed, barGreen, barBlue, barAlpha).endVertex();
|
||||
tess.end();
|
||||
worldr = tess.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.addVertex(barLeft, barTop + barHeight, 0.0F).setColor(barRed, barGreen, barBlue, barAlpha);
|
||||
worldr.addVertex(barLeft + barWidth, barTop + barHeight, 0.0F).setColor(barRed, barGreen, barBlue, barAlpha);
|
||||
worldr.addVertex(barLeft + barWidth, barTop, 0.0F).setColor(barRed, barGreen, barBlue, barAlpha);
|
||||
worldr.addVertex(barLeft, barTop, 0.0F).setColor(barRed, barGreen, barBlue, barAlpha);
|
||||
BufferUploader.drawWithShader(worldr.buildOrThrow());
|
||||
|
||||
int barBorderAlpha = this.barBorderColor >> 24 & 0xff;
|
||||
int barBorderRed = this.barBorderColor >> 16 & 0xff;
|
||||
int barBorderGreen = this.barBorderColor >> 8 & 0xff;
|
||||
int barBorderBlue = this.barBorderColor & 0xff;
|
||||
|
||||
worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.vertex(barLeft, barTop + barHeight - 1, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth - 1, barTop + barHeight - 1, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth - 1, barTop, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
|
||||
worldr.vertex(barLeft, barTop, 0.0D).color(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha).endVertex();
|
||||
tess.end();
|
||||
worldr = tess.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.addVertex(barLeft, barTop + barHeight - 1, 0.0F).setColor(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha);
|
||||
worldr.addVertex(barLeft + barWidth - 1, barTop + barHeight - 1, 0.0F).setColor(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha);
|
||||
worldr.addVertex(barLeft + barWidth - 1, barTop, 0.0F).setColor(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha);
|
||||
worldr.addVertex(barLeft, barTop, 0.0F).setColor(barBorderRed, barBorderGreen, barBorderBlue, barBorderAlpha);
|
||||
BufferUploader.drawWithShader(worldr.buildOrThrow());
|
||||
}
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.BufferUploader;
|
||||
import com.mojang.blaze3d.vertex.BufferVertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
@@ -44,6 +43,7 @@ import java.util.function.Supplier;
|
||||
* It is somewhat a copy of the superclass render method.
|
||||
*/
|
||||
public class ForgeLoadingOverlay extends LoadingOverlay {
|
||||
private static final ResourceLocation MOJANG_STUDIOS_LOGO_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/title/mojangstudios.png");
|
||||
private final Minecraft minecraft;
|
||||
private final ReloadInstance reload;
|
||||
private final Consumer<Optional<Throwable>> onFinish;
|
||||
@@ -57,7 +57,7 @@ public class ForgeLoadingOverlay extends LoadingOverlay {
|
||||
this.reload = reloader;
|
||||
this.onFinish = errorConsumer;
|
||||
this.displayWindow = displayWindow;
|
||||
displayWindow.addMojangTexture(mc.getTextureManager().getTexture(new ResourceLocation("textures/gui/title/mojangstudios.png")).getId());
|
||||
displayWindow.addMojangTexture(mc.getTextureManager().getTexture(MOJANG_STUDIOS_LOGO_LOCATION).getId());
|
||||
this.progress = StartupMessageManager.prependProgressBar("Minecraft Progress", 100);
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ public class ForgeLoadingOverlay extends LoadingOverlay {
|
||||
var wbottom = Mth.clamp(fbHeight * 0.5f + scale * theight, 0, fbHeight);
|
||||
GlStateManager.glActiveTexture(GlConst.GL_TEXTURE0);
|
||||
RenderSystem.disableCull();
|
||||
BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder();
|
||||
BufferBuilder bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, fade);
|
||||
RenderSystem.getModelViewMatrix().identity();
|
||||
RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0.0F, fbWidth, 0.0F, fbHeight, 0.1f, -0.1f), VertexSorting.ORTHOGRAPHIC_Z);
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
// This is fill in around the edges - it's empty solid colour
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
// top box from hpos
|
||||
addQuad(bufferbuilder, 0, fbWidth, wtop, fbHeight, colour, fade);
|
||||
// bottom box to hpos
|
||||
@@ -114,21 +114,21 @@ public class ForgeLoadingOverlay extends LoadingOverlay {
|
||||
addQuad(bufferbuilder, 0, wleft, wtop, wbottom, colour, fade);
|
||||
// right box from wpos
|
||||
addQuad(bufferbuilder, wright, fbWidth, wtop, wbottom, colour, fade);
|
||||
BufferUploader.drawWithShader(bufferbuilder.end());
|
||||
BufferUploader.drawWithShader(bufferbuilder.buildOrThrow());
|
||||
|
||||
// This is the actual screen data from the loading screen
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlConst.GL_SRC_ALPHA, GlConst.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
RenderSystem.setShaderTexture(0, displayWindow.getFramebufferTextureId());
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
bufferbuilder.vertex(wleft, wbottom, 0f).uv(0, 0).color(1f, 1f, 1f, fade).endVertex();
|
||||
bufferbuilder.vertex(wright, wbottom, 0f).uv(1, 0).color(1f, 1f, 1f, fade).endVertex();
|
||||
bufferbuilder.vertex(wright, wtop, 0f).uv(1, 1).color(1f, 1f, 1f, fade).endVertex();
|
||||
bufferbuilder.vertex(wleft, wtop, 0f).uv(0, 1).color(1f, 1f, 1f, fade).endVertex();
|
||||
bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
bufferbuilder.addVertex(wleft, wbottom, 0f).setUv(0, 0).setColor(1f, 1f, 1f, fade);
|
||||
bufferbuilder.addVertex(wright, wbottom, 0f).setUv(1, 0).setColor(1f, 1f, 1f, fade);
|
||||
bufferbuilder.addVertex(wright, wtop, 0f).setUv(1, 1).setColor(1f, 1f, 1f, fade);
|
||||
bufferbuilder.addVertex(wleft, wtop, 0f).setUv(0, 1).setColor(1f, 1f, 1f, fade);
|
||||
GL30C.glTexParameterIi(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_MIN_FILTER, GlConst.GL_NEAREST);
|
||||
GL30C.glTexParameterIi(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_MAG_FILTER, GlConst.GL_NEAREST);
|
||||
BufferUploader.drawWithShader(bufferbuilder.end());
|
||||
BufferUploader.drawWithShader(bufferbuilder.buildOrThrow());
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1f);
|
||||
@@ -154,10 +154,10 @@ public class ForgeLoadingOverlay extends LoadingOverlay {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addQuad(BufferVertexConsumer bufferbuilder, float x0, float x1, float y0, float y1, ColourScheme.Colour colour, float fade) {
|
||||
bufferbuilder.vertex(x0, y0, 0f).color(colour.redf(), colour.greenf(), colour.bluef(), fade).endVertex();
|
||||
bufferbuilder.vertex(x0, y1, 0f).color(colour.redf(), colour.greenf(), colour.bluef(), fade).endVertex();
|
||||
bufferbuilder.vertex(x1, y1, 0f).color(colour.redf(), colour.greenf(), colour.bluef(), fade).endVertex();
|
||||
bufferbuilder.vertex(x1, y0, 0f).color(colour.redf(), colour.greenf(), colour.bluef(), fade).endVertex();
|
||||
private static void addQuad(BufferBuilder bufferbuilder, float x0, float x1, float y0, float y1, ColourScheme.Colour colour, float fade) {
|
||||
bufferbuilder.addVertex(x0, y0, 0f).setColor(colour.redf(), colour.greenf(), colour.bluef(), fade);
|
||||
bufferbuilder.addVertex(x0, y1, 0f).setColor(colour.redf(), colour.greenf(), colour.bluef(), fade);
|
||||
bufferbuilder.addVertex(x1, y1, 0f).setColor(colour.redf(), colour.greenf(), colour.bluef(), fade);
|
||||
bufferbuilder.addVertex(x1, y0, 0f).setColor(colour.redf(), colour.greenf(), colour.bluef(), fade);
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
Material particleLocation = context.getMaterial("particle");
|
||||
TextureAtlasSprite particle = spriteGetter.apply(particleLocation);
|
||||
@@ -84,7 +84,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
if (!context.isComponentVisible(name, true))
|
||||
continue;
|
||||
var model = entry.getValue();
|
||||
bakedPartsBuilder.put(name, model.bake(baker, model, spriteGetter, modelState, modelLocation, true));
|
||||
bakedPartsBuilder.put(name, model.bake(baker, model, spriteGetter, modelState, true));
|
||||
}
|
||||
var bakedParts = bakedPartsBuilder.build();
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.joml.Vector3f;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.minecraftforge.client.model.geometry.StandaloneGeometryBakingContext.LOCATION;
|
||||
|
||||
/**
|
||||
* A dynamic fluid container model, capable of re-texturing itself at runtime to match the contained fluid.
|
||||
* <p>
|
||||
@@ -88,7 +90,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
Material particleLocation = context.hasMaterial("particle") ? context.getMaterial("particle") : null;
|
||||
Material baseLocation = context.hasMaterial("base") ? context.getMaterial("base") : null;
|
||||
@@ -114,7 +116,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
|
||||
// We need to disable GUI 3D and block lighting for this to render properly
|
||||
var itemContext = StandaloneGeometryBakingContext.builder(context).withGui3d(false).withUseBlockLight(false).build(modelLocation);
|
||||
var itemContext = StandaloneGeometryBakingContext.builder(context).withGui3d(false).withUseBlockLight(false).build(LOCATION);
|
||||
var modelBuilder = CompositeModel.Baked.builder(itemContext, particleSprite, new ContainedFluidOverrideHandler(overrides, baker, itemContext, this), context.getTransforms());
|
||||
|
||||
var normalRenderTypes = getLayerRenderTypes(false);
|
||||
@@ -123,7 +125,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
{
|
||||
// Base texture
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(0, baseSprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> baseSprite, modelState, modelLocation);
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> baseSprite, modelState);
|
||||
modelBuilder.addQuads(normalRenderTypes, quads);
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
// Fluid layer
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(FLUID_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(1, templateSprite.contents()); // Use template as mask
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> fluidSprite, transformedState, modelLocation); // Bake with fluid texture
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> fluidSprite, transformedState); // Bake with fluid texture
|
||||
|
||||
var emissive = applyFluidLuminosity && fluid.getFluidType().getLightLevel() > 0;
|
||||
var renderTypes = getLayerRenderTypes(emissive);
|
||||
@@ -153,7 +155,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
// Cover/overlay
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(COVER_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(2, coverSprite.contents()); // Use cover as mask
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, transformedState, modelLocation); // Bake with selected texture
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, transformedState); // Bake with selected texture
|
||||
modelBuilder.addQuads(normalRenderTypes, quads);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +179,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
if (!jsonObject.has("fluid"))
|
||||
throw new RuntimeException("Bucket model requires 'fluid' value.");
|
||||
|
||||
ResourceLocation fluidName = new ResourceLocation(jsonObject.get("fluid").getAsString());
|
||||
ResourceLocation fluidName = ResourceLocation.parse(jsonObject.get("fluid").getAsString());
|
||||
|
||||
Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
|
||||
|
||||
@@ -219,7 +221,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
if (!cache.containsKey(name))
|
||||
{
|
||||
DynamicFluidContainerModel unbaked = this.parent.withFluid(fluid);
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, this, new ResourceLocation("forge:bucket_override"));
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, originalModel.getOverrides());
|
||||
cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ElementsModel extends SimpleUnbakedGeometry<ElementsModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
// If there is a root transform, undo the ModelState transform, apply it, then re-apply the ModelState transform.
|
||||
// This is necessary because of things like UV locking, which should only respond to the ModelState, and as such
|
||||
@@ -54,14 +54,14 @@ public class ElementsModel extends SimpleUnbakedGeometry<ElementsModel>
|
||||
for (Direction direction : element.faces.keySet())
|
||||
{
|
||||
var face = element.faces.get(direction);
|
||||
var sprite = spriteGetter.apply(context.getMaterial(face.texture));
|
||||
var quad = BlockModel.bakeFace(element, face, sprite, direction, modelState, modelLocation);
|
||||
var sprite = spriteGetter.apply(context.getMaterial(face.texture()));
|
||||
var quad = BlockModel.bakeFace(element, face, sprite, direction, modelState);
|
||||
postTransform.processInPlace(quad);
|
||||
|
||||
if (face.cullForDirection == null)
|
||||
if (face.cullForDirection() == null)
|
||||
modelBuilder.addUnculledFace(quad);
|
||||
else
|
||||
modelBuilder.addCulledFace(modelState.getRotation().rotateTransform(face.cullForDirection), quad);
|
||||
modelBuilder.addCulledFace(modelState.getRotation().rotateTransform(face.cullForDirection()), quad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class EmptyModel extends SimpleUnbakedGeometry<EmptyModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform)
|
||||
{
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
return BAKED;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
if (jsonobject.has("render_type"))
|
||||
{
|
||||
var renderTypeHintName = GsonHelper.getAsString(jsonobject, "render_type");
|
||||
model.customData.setRenderTypeHint(new ResourceLocation(renderTypeHintName));
|
||||
model.customData.setRenderTypeHint(ResourceLocation.parse(renderTypeHintName));
|
||||
}
|
||||
|
||||
if (jsonobject.has("visibility"))
|
||||
@@ -91,7 +91,7 @@ public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
if (!object.has("loader"))
|
||||
return null;
|
||||
|
||||
var name = new ResourceLocation(GsonHelper.getAsString(object, "loader"));
|
||||
var name = ResourceLocation.parse(GsonHelper.getAsString(object, "loader"));
|
||||
var loader = GeometryLoaderManager.get(name);
|
||||
if (loader == null)
|
||||
throw new JsonParseException(String.format(Locale.ENGLISH, "Model loader '%s' not found. Registered loaders: %s", name, GeometryLoaderManager.getLoaderList()));
|
||||
|
||||
@@ -30,10 +30,8 @@ import net.minecraft.util.ExtraCodecs;
|
||||
* @param ambientOcclusion If this face has AO
|
||||
* @param calculateNormals If we should manually calculate the normals for this block or inherit facing normals like vanilla
|
||||
*/
|
||||
public record ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion, boolean calculateNormals)
|
||||
{
|
||||
public ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion)
|
||||
{
|
||||
public record ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion, boolean calculateNormals) {
|
||||
public ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion) {
|
||||
this(color, blockLight, skyLight, ambientOcclusion, false);
|
||||
}
|
||||
|
||||
@@ -59,12 +57,9 @@ public record ForgeFaceData(int color, int blockLight, int skyLight, boolean amb
|
||||
* @throws JsonParseException
|
||||
*/
|
||||
@Nullable
|
||||
public static ForgeFaceData read(@Nullable JsonElement obj, @Nullable ForgeFaceData fallback) throws JsonParseException
|
||||
{
|
||||
if(obj == null)
|
||||
{
|
||||
public static ForgeFaceData read(@Nullable JsonElement obj, @Nullable ForgeFaceData fallback) throws JsonParseException {
|
||||
if (obj == null)
|
||||
return fallback;
|
||||
}
|
||||
return CODEC.parse(JsonOps.INSTANCE, obj).getOrThrow(JsonParseException::new);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,6 @@ public class ForgeItemModelShaper extends ItemModelShaper {
|
||||
|
||||
public ModelResourceLocation getLocation(@NotNull ItemStack stack) {
|
||||
ModelResourceLocation location = locations.get(ForgeRegistries.ITEMS.getDelegateOrThrow(stack.getItem()));
|
||||
return location == null ? ModelBakery.MISSING_MODEL_LOCATION : location;
|
||||
return location == null ? ModelBakery.MISSING_MODEL_VARIANT : location;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -18,54 +17,47 @@ import java.util.List;
|
||||
*
|
||||
* @see QuadTransformers
|
||||
*/
|
||||
public interface IQuadTransformer
|
||||
{
|
||||
int STRIDE = DefaultVertexFormat.BLOCK.getIntegerSize();
|
||||
int POSITION = findOffset(DefaultVertexFormat.ELEMENT_POSITION);
|
||||
int COLOR = findOffset(DefaultVertexFormat.ELEMENT_COLOR);
|
||||
int UV0 = findOffset(DefaultVertexFormat.ELEMENT_UV0);
|
||||
int UV1 = findOffset(DefaultVertexFormat.ELEMENT_UV1);
|
||||
int UV2 = findOffset(DefaultVertexFormat.ELEMENT_UV2);
|
||||
int NORMAL = findOffset(DefaultVertexFormat.ELEMENT_NORMAL);
|
||||
public interface IQuadTransformer {
|
||||
int STRIDE = DefaultVertexFormat.BLOCK.getVertexSize() / 4;
|
||||
int POSITION = findOffset(VertexFormatElement.POSITION);
|
||||
int COLOR = findOffset(VertexFormatElement.COLOR);
|
||||
int UV0 = findOffset(VertexFormatElement.UV0);
|
||||
int UV1 = findOffset(VertexFormatElement.UV1);
|
||||
int UV2 = findOffset(VertexFormatElement.UV2);
|
||||
int NORMAL = findOffset(VertexFormatElement.NORMAL);
|
||||
|
||||
void processInPlace(BakedQuad quad);
|
||||
|
||||
default void processInPlace(List<BakedQuad> quads)
|
||||
{
|
||||
default void processInPlace(List<BakedQuad> quads) {
|
||||
for (BakedQuad quad : quads)
|
||||
processInPlace(quad);
|
||||
}
|
||||
|
||||
default BakedQuad process(BakedQuad quad)
|
||||
{
|
||||
default BakedQuad process(BakedQuad quad) {
|
||||
var copy = copy(quad);
|
||||
processInPlace(copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
default List<BakedQuad> process(List<BakedQuad> inputs)
|
||||
{
|
||||
default List<BakedQuad> process(List<BakedQuad> inputs) {
|
||||
return inputs.stream().map(IQuadTransformer::copy).peek(this::processInPlace).toList();
|
||||
}
|
||||
|
||||
default IQuadTransformer andThen(IQuadTransformer other)
|
||||
{
|
||||
default IQuadTransformer andThen(IQuadTransformer other) {
|
||||
return quad -> {
|
||||
processInPlace(quad);
|
||||
other.processInPlace(quad);
|
||||
};
|
||||
}
|
||||
|
||||
private static BakedQuad copy(BakedQuad quad)
|
||||
{
|
||||
private static BakedQuad copy(BakedQuad quad) {
|
||||
var vertices = quad.getVertices();
|
||||
return new BakedQuad(Arrays.copyOf(vertices, vertices.length), quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade(), quad.hasAmbientOcclusion());
|
||||
}
|
||||
|
||||
private static int findOffset(VertexFormatElement element)
|
||||
{
|
||||
private static int findOffset(VertexFormatElement element) {
|
||||
// Divide by 4 because we want the int offset
|
||||
var index = DefaultVertexFormat.BLOCK.getElements().indexOf(element);
|
||||
return index < 0 ? -1 : DefaultVertexFormat.BLOCK.getOffset(index) / 4;
|
||||
var index = DefaultVertexFormat.BLOCK.getOffset(element);
|
||||
return index < 0 ? -1 : index / 4;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
@@ -43,18 +42,16 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
{
|
||||
@Nullable
|
||||
private ImmutableList<Material> textures;
|
||||
private final Int2ObjectMap<ForgeFaceData> layerData;
|
||||
private final Int2ObjectMap<ResourceLocation> renderTypeNames;
|
||||
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ForgeFaceData> layerData, Int2ObjectMap<ResourceLocation> renderTypeNames)
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames)
|
||||
{
|
||||
this.textures = textures;
|
||||
this.layerData = layerData;
|
||||
this.renderTypeNames = renderTypeNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
if (textures == null)
|
||||
{
|
||||
@@ -78,8 +75,8 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
for (int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
TextureAtlasSprite sprite = spriteGetter.apply(textures.get(i));
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(i, sprite.contents(), this.layerData.get(i));
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState, modelLocation);
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(i, sprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState);
|
||||
var renderTypeName = renderTypeNames.get(i);
|
||||
var renderTypes = renderTypeName != null ? context.getRenderType(renderTypeName) : null;
|
||||
builder.addQuads(renderTypes != null ? renderTypes : normalRenderTypes, quads);
|
||||
@@ -101,20 +98,14 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
var renderTypes = jsonObject.getAsJsonObject("render_types");
|
||||
for (Map.Entry<String, JsonElement> entry : renderTypes.entrySet())
|
||||
{
|
||||
var renderType = new ResourceLocation(entry.getKey());
|
||||
var renderType = ResourceLocation.parse(entry.getKey());
|
||||
for (var layer : entry.getValue().getAsJsonArray())
|
||||
if (renderTypeNames.put(layer.getAsInt(), renderType) != null)
|
||||
throw new JsonParseException("Registered duplicate render type for layer " + layer);
|
||||
}
|
||||
}
|
||||
|
||||
var emissiveLayers = new Int2ObjectArrayMap<ForgeFaceData>();
|
||||
if(jsonObject.has("forge_data"))
|
||||
{
|
||||
JsonObject forgeData = jsonObject.get("forge_data").getAsJsonObject();
|
||||
readLayerData(forgeData, "layers", renderTypeNames, emissiveLayers, false);
|
||||
}
|
||||
return new ItemLayerModel(null, emissiveLayers, renderTypeNames);
|
||||
return new ItemLayerModel(null, renderTypeNames);
|
||||
}
|
||||
|
||||
protected void readLayerData(JsonObject jsonObject, String name, Int2ObjectOpenHashMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ForgeFaceData> layerData, boolean logWarning)
|
||||
|
||||
@@ -160,7 +160,7 @@ public final class QuadTransformers {
|
||||
/**
|
||||
* Converts an ARGB color to an ABGR color, as the commonly used color format is not the format colors end up packed into.
|
||||
* This function doubles as its own inverse.
|
||||
* @param color ARGB color
|
||||
* @param argb ARGB color
|
||||
* @return ABGR color
|
||||
*/
|
||||
public static int toABGR(int argb)
|
||||
|
||||
@@ -54,14 +54,14 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
return new Baked(
|
||||
context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(),
|
||||
spriteGetter.apply(context.getMaterial("particle")), overrides,
|
||||
baseModel.bake(baker, baseModel, spriteGetter, modelState, modelLocation, context.useBlockLight()),
|
||||
baseModel.bake(baker, baseModel, spriteGetter, modelState, context.useBlockLight()),
|
||||
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> {
|
||||
return value.bake(baker, value, spriteGetter, modelState, modelLocation, context.useBlockLight());
|
||||
return value.bake(baker, value, spriteGetter, modelState, context.useBlockLight(), context.getRenderType(context.getRenderTypeHint()));
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.client.model.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -32,61 +33,52 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@EventBusSubscriber(modid = "forge", bus = Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ModelDataManager
|
||||
{
|
||||
public class ModelDataManager {
|
||||
private final Level level;
|
||||
private final Map<ChunkPos, Set<BlockPos>> needModelDataRefresh = new ConcurrentHashMap<>();
|
||||
private final Map<ChunkPos, Map<BlockPos, ModelData>> modelDataCache = new ConcurrentHashMap<>();
|
||||
|
||||
public ModelDataManager(Level level)
|
||||
{
|
||||
public ModelDataManager(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void requestRefresh(@NotNull BlockEntity blockEntity)
|
||||
{
|
||||
public void requestRefresh(@NotNull BlockEntity blockEntity) {
|
||||
Preconditions.checkNotNull(blockEntity, "Block entity must not be null");
|
||||
needModelDataRefresh.computeIfAbsent(new ChunkPos(blockEntity.getBlockPos()), $ -> Collections.synchronizedSet(new HashSet<>()))
|
||||
.add(blockEntity.getBlockPos());
|
||||
}
|
||||
|
||||
private void refreshAt(ChunkPos chunk)
|
||||
{
|
||||
private void refreshAt(ChunkPos chunk) {
|
||||
Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
|
||||
|
||||
if (needUpdate != null)
|
||||
{
|
||||
if (needUpdate != null) {
|
||||
Map<BlockPos, ModelData> data = modelDataCache.computeIfAbsent(chunk, $ -> new ConcurrentHashMap<>());
|
||||
for (BlockPos pos : needUpdate)
|
||||
{
|
||||
for (BlockPos pos : needUpdate) {
|
||||
BlockEntity toUpdate = level.getBlockEntity(pos);
|
||||
if (toUpdate != null && !toUpdate.isRemoved())
|
||||
{
|
||||
data.put(pos, toUpdate.getModelData());
|
||||
}
|
||||
else
|
||||
{
|
||||
data.remove(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable ModelData getAt(BlockPos pos)
|
||||
{
|
||||
public @Nullable ModelData getAt(BlockPos pos) {
|
||||
return getAt(new ChunkPos(pos)).get(pos);
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(ChunkPos pos)
|
||||
{
|
||||
public Map<BlockPos, ModelData> getAt(SectionPos pos) {
|
||||
return getAt(pos.chunk());
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(ChunkPos pos) {
|
||||
Preconditions.checkArgument(level.isClientSide, "Cannot request model data for server level");
|
||||
refreshAt(pos);
|
||||
return modelDataCache.getOrDefault(pos, Collections.emptyMap());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onChunkUnload(ChunkEvent.Unload event)
|
||||
{
|
||||
public static void onChunkUnload(ChunkEvent.Unload event) {
|
||||
var level = event.getChunk().getWorldForge();
|
||||
if (level == null)
|
||||
return;
|
||||
|
||||
@@ -143,11 +143,11 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public ResourceLocation modLoc(String name) {
|
||||
return new ResourceLocation(modid, name);
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
}
|
||||
|
||||
public ResourceLocation mcLoc(String name) {
|
||||
return new ResourceLocation(name);
|
||||
return ResourceLocation.parse(name);
|
||||
}
|
||||
|
||||
private ResourceLocation key(Block block) {
|
||||
@@ -159,12 +159,11 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public ResourceLocation blockTexture(Block block) {
|
||||
ResourceLocation name = key(block);
|
||||
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
|
||||
return key(block).withPath(p -> ModelProvider.BLOCK_FOLDER + '/' + p);
|
||||
}
|
||||
|
||||
private ResourceLocation extend(ResourceLocation rl, String suffix) {
|
||||
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
|
||||
return rl.withSuffix(suffix);
|
||||
}
|
||||
|
||||
public ModelFile cubeAll(Block block) {
|
||||
@@ -627,31 +626,31 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public static final ImmutableMap<Direction, Property<WallSide>> WALL_PROPS = ImmutableMap.<Direction, Property<WallSide>>builder()
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
.put(Direction.SOUTH, BlockStateProperties.SOUTH_WALL)
|
||||
.put(Direction.WEST, BlockStateProperties.WEST_WALL)
|
||||
.build();
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
.put(Direction.SOUTH, BlockStateProperties.SOUTH_WALL)
|
||||
.put(Direction.WEST, BlockStateProperties.WEST_WALL)
|
||||
.build();
|
||||
|
||||
public void wallBlock(WallBlock block, ModelFile post, ModelFile side, ModelFile sideTall) {
|
||||
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
|
||||
.part().modelFile(post).addModel()
|
||||
.condition(WallBlock.UP, true).end();
|
||||
WALL_PROPS.entrySet().stream()
|
||||
.filter(e -> e.getKey().getAxis().isHorizontal())
|
||||
.forEach(e -> {
|
||||
wallSidePart(builder, side, e, WallSide.LOW);
|
||||
wallSidePart(builder, sideTall, e, WallSide.TALL);
|
||||
});
|
||||
.filter(e -> e.getKey().getAxis().isHorizontal())
|
||||
.forEach(e -> {
|
||||
wallSidePart(builder, side, e, WallSide.LOW);
|
||||
wallSidePart(builder, sideTall, e, WallSide.TALL);
|
||||
});
|
||||
}
|
||||
|
||||
private void wallSidePart(MultiPartBlockStateBuilder builder, ModelFile model, Map.Entry<Direction, Property<WallSide>> entry, WallSide height) {
|
||||
builder.part()
|
||||
.modelFile(model)
|
||||
.rotationY((((int) entry.getKey().toYRot()) + 180) % 360)
|
||||
.uvLock(true)
|
||||
.addModel()
|
||||
.condition(entry.getValue(), height);
|
||||
.modelFile(model)
|
||||
.rotationY((((int) entry.getKey().toYRot()) + 180) % 360)
|
||||
.uvLock(true)
|
||||
.addModel()
|
||||
.condition(entry.getValue(), height);
|
||||
}
|
||||
|
||||
public void paneBlock(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
|
||||
{
|
||||
return getBuilder(item.toString())
|
||||
.parent(new ModelFile.UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", new ResourceLocation(item.getNamespace(), "item/" + item.getPath()));
|
||||
.texture("layer0", item.withPrefix("item/"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -119,9 +119,9 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
} else {
|
||||
ResourceLocation asLoc;
|
||||
if (texture.contains(":")) {
|
||||
asLoc = new ResourceLocation(texture);
|
||||
asLoc = ResourceLocation.parse(texture);
|
||||
} else {
|
||||
asLoc = new ResourceLocation(getLocation().getNamespace(), texture);
|
||||
asLoc = ResourceLocation.fromNamespaceAndPath(getLocation().getNamespace(), texture);
|
||||
}
|
||||
return texture(key, asLoc);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
*/
|
||||
public T renderType(String renderType) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
return renderType(new ResourceLocation(renderType));
|
||||
return renderType(ResourceLocation.parse(renderType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,27 +317,21 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (face == null) continue;
|
||||
|
||||
JsonObject faceObj = new JsonObject();
|
||||
faceObj.addProperty("texture", serializeLocOrKey(face.texture));
|
||||
if (!Arrays.equals(face.uv.uvs, part.uvsByFace(dir))) {
|
||||
faceObj.add("uv", new Gson().toJsonTree(face.uv.uvs));
|
||||
}
|
||||
if (face.cullForDirection != null) {
|
||||
faceObj.addProperty("cullface", face.cullForDirection.getSerializedName());
|
||||
}
|
||||
if (face.uv.rotation != 0) {
|
||||
faceObj.addProperty("rotation", face.uv.rotation);
|
||||
}
|
||||
if (face.tintIndex != -1) {
|
||||
faceObj.addProperty("tintindex", face.tintIndex);
|
||||
}
|
||||
if (!face.getFaceData().equals(ForgeFaceData.DEFAULT)) {
|
||||
faceObj.add("forge_data", ForgeFaceData.CODEC.encodeStart(JsonOps.INSTANCE, face.getFaceData()).result().get());
|
||||
}
|
||||
faceObj.addProperty("texture", serializeLocOrKey(face.texture()));
|
||||
if (!Arrays.equals(face.uv().uvs, part.uvsByFace(dir)))
|
||||
faceObj.add("uv", new Gson().toJsonTree(face.uv().uvs));
|
||||
if (face.cullForDirection() != null)
|
||||
faceObj.addProperty("cullface", face.cullForDirection().getSerializedName());
|
||||
if (face.uv().rotation != 0)
|
||||
faceObj.addProperty("rotation", face.uv().rotation);
|
||||
if (face.tintIndex() != -1)
|
||||
faceObj.addProperty("tintindex", face.tintIndex());
|
||||
if (face.data() != null && !ForgeFaceData.DEFAULT.equals(face.data()))
|
||||
faceObj.add("forge_data", ForgeFaceData.CODEC.encodeStart(JsonOps.INSTANCE, face.data()).result().get());
|
||||
faces.add(dir.getSerializedName(), faceObj);
|
||||
}
|
||||
if (!part.faces.isEmpty()) {
|
||||
if (!part.faces.isEmpty())
|
||||
partObj.add("faces", faces);
|
||||
}
|
||||
elements.add(partObj);
|
||||
});
|
||||
root.add("elements", elements);
|
||||
@@ -360,7 +354,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (tex.charAt(0) == '#') {
|
||||
return tex;
|
||||
}
|
||||
return new ResourceLocation(tex).toString();
|
||||
return ResourceLocation.parse(tex).toString();
|
||||
}
|
||||
|
||||
private JsonArray serializeVector3f(Vector3f vec) {
|
||||
@@ -385,10 +379,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private final Map<Direction, FaceBuilder> faces = new LinkedHashMap<>();
|
||||
private RotationBuilder rotation;
|
||||
private boolean shade = true;
|
||||
private int color = 0xFFFFFFFF;
|
||||
private int blockLight = 0, skyLight = 0;
|
||||
private boolean hasAmbientOcclusion = true;
|
||||
private boolean calculateNormals = false;
|
||||
private ForgeFaceData data = ForgeFaceData.DEFAULT;
|
||||
|
||||
private void validateCoordinate(float coord, char name) {
|
||||
Preconditions.checkArgument(!(coord < -16.0F) && !(coord > 32.0F), "Position " + name + " out of range, must be within [-16, 32]. Found: %d", coord);
|
||||
@@ -530,9 +521,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder emissivity(int blockLight, int skyLight) {
|
||||
this.blockLight = blockLight;
|
||||
this.skyLight = skyLight;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), blockLight, skyLight, this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,8 +531,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
return data(new ForgeFaceData(color, this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,8 +541,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder ao(boolean ao) {
|
||||
this.hasAmbientOcclusion = ao;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), ao, this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -564,7 +551,11 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder calculateNormals(boolean calc) {
|
||||
this.calculateNormals = calc;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), calc));
|
||||
}
|
||||
|
||||
public ElementBuilder data(ForgeFaceData data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -575,22 +566,18 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
BlockElement build() {
|
||||
Map<Direction, BlockElementFace> faces = this.faces.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build(), (k1, k2) -> { throw new IllegalArgumentException(); }, LinkedHashMap::new));
|
||||
return new BlockElement(from, to, faces, rotation == null ? null : rotation.build(), shade, new ForgeFaceData(this.color, this.blockLight, this.skyLight, this.hasAmbientOcclusion, this.calculateNormals));
|
||||
return new BlockElement(from, to, faces, rotation == null ? null : rotation.build(), shade);
|
||||
}
|
||||
|
||||
public T end() { return self(); }
|
||||
|
||||
public class FaceBuilder {
|
||||
|
||||
private Direction cullface;
|
||||
private int tintindex = -1;
|
||||
private String texture = MissingTextureAtlasSprite.getLocation().toString();
|
||||
private float[] uvs;
|
||||
private FaceRotation rotation = FaceRotation.ZERO;
|
||||
private int color = 0xFFFFFFFF;
|
||||
private int blockLight = 0, skyLight = 0;
|
||||
private boolean hasAmbientOcclusion = true;
|
||||
private boolean calculateNormals = false;
|
||||
private ForgeFaceData data = ElementBuilder.this.data;
|
||||
|
||||
FaceBuilder(Direction dir) {
|
||||
// param unused for functional match
|
||||
@@ -646,9 +633,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder emissivity(int blockLight, int skyLight) {
|
||||
this.blockLight = blockLight;
|
||||
this.skyLight = skyLight;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), blockLight, skyLight, this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,8 +643,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
return data(new ForgeFaceData(color, this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -669,8 +653,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder ao(boolean ao) {
|
||||
this.hasAmbientOcclusion = ao;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), ao, this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -680,15 +663,18 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder calculateNormals(boolean calc) {
|
||||
this.calculateNormals = calc;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), calc));
|
||||
}
|
||||
|
||||
public FaceBuilder data(ForgeFaceData data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockElementFace build() {
|
||||
if (this.texture == null) {
|
||||
if (this.texture == null)
|
||||
throw new IllegalStateException("A model face must have a texture");
|
||||
}
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), new ForgeFaceData(this.color, this.blockLight, this.skyLight, this.hasAmbientOcclusion, this.calculateNormals));
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), this.data);
|
||||
}
|
||||
|
||||
public ElementBuilder end() { return ElementBuilder.this; }
|
||||
@@ -826,8 +812,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
}
|
||||
}
|
||||
|
||||
public class RootTransformsBuilder
|
||||
{
|
||||
public class RootTransformsBuilder {
|
||||
private static final Vector3f ONE = new Vector3f(1, 1, 1);
|
||||
|
||||
private Vector3f translation = new Vector3f();
|
||||
@@ -838,9 +823,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private @Nullable TransformationHelper.TransformOrigin origin;
|
||||
private @Nullable Vector3f originVec;
|
||||
|
||||
RootTransformsBuilder()
|
||||
{
|
||||
}
|
||||
RootTransformsBuilder() { }
|
||||
|
||||
/**
|
||||
* Sets the translation of the root transform.
|
||||
@@ -849,8 +832,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code translation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder translation(Vector3f translation)
|
||||
{
|
||||
public RootTransformsBuilder translation(Vector3f translation) {
|
||||
this.translation = Preconditions.checkNotNull(translation, "Translation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -863,8 +845,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param z z translation
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder translation(float x, float y, float z)
|
||||
{
|
||||
public RootTransformsBuilder translation(float x, float y, float z) {
|
||||
return translation(new Vector3f(x, y, z));
|
||||
}
|
||||
|
||||
@@ -875,8 +856,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder rotation(Quaternionf rotation)
|
||||
{
|
||||
public RootTransformsBuilder rotation(Quaternionf rotation) {
|
||||
this.leftRotation = Preconditions.checkNotNull(rotation, "Rotation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -890,8 +870,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder rotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder rotation(float x, float y, float z, boolean isDegrees) {
|
||||
return rotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -902,8 +881,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code leftRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder leftRotation(Quaternionf leftRotation)
|
||||
{
|
||||
public RootTransformsBuilder leftRotation(Quaternionf leftRotation) {
|
||||
return rotation(leftRotation);
|
||||
}
|
||||
|
||||
@@ -916,8 +894,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder leftRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder leftRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return leftRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -928,8 +905,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rightRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder rightRotation(Quaternionf rightRotation)
|
||||
{
|
||||
public RootTransformsBuilder rightRotation(Quaternionf rightRotation) {
|
||||
this.rightRotation = Preconditions.checkNotNull(rightRotation, "Rotation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -943,8 +919,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder rightRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder rightRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return rightRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -955,8 +930,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rightRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder postRotation(Quaternionf postRotation)
|
||||
{
|
||||
public RootTransformsBuilder postRotation(Quaternionf postRotation) {
|
||||
return rightRotation(postRotation);
|
||||
}
|
||||
|
||||
@@ -969,8 +943,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder postRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder postRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return postRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -980,8 +953,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param scale the scale
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder scale(float scale)
|
||||
{
|
||||
public RootTransformsBuilder scale(float scale) {
|
||||
return scale(new Vector3f(scale, scale, scale));
|
||||
}
|
||||
|
||||
@@ -993,8 +965,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param zScale z scale
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder scale(float xScale, float yScale, float zScale)
|
||||
{
|
||||
public RootTransformsBuilder scale(float xScale, float yScale, float zScale) {
|
||||
return scale(new Vector3f(xScale, yScale, zScale));
|
||||
}
|
||||
|
||||
@@ -1005,8 +976,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code scale} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder scale(Vector3f scale)
|
||||
{
|
||||
public RootTransformsBuilder scale(Vector3f scale) {
|
||||
this.scale = Preconditions.checkNotNull(scale, "Scale must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -1018,8 +988,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code transformation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder transform(Transformation transformation)
|
||||
{
|
||||
public RootTransformsBuilder transform(Transformation transformation) {
|
||||
Preconditions.checkNotNull(transformation, "Transformation must not be null");
|
||||
this.translation = transformation.getTranslation();
|
||||
this.leftRotation = transformation.getLeftRotation();
|
||||
@@ -1035,8 +1004,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code origin} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder origin(Vector3f origin)
|
||||
{
|
||||
public RootTransformsBuilder origin(Vector3f origin) {
|
||||
this.originVec = Preconditions.checkNotNull(origin, "Origin must not be null");
|
||||
this.origin = null;
|
||||
return this;
|
||||
@@ -1050,8 +1018,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @throws NullPointerException if {@code origin} is {@code null}
|
||||
* @throws IllegalArgumentException if {@code origin} is not {@code center}, {@code corner} or {@code opposing-corner}
|
||||
*/
|
||||
public RootTransformsBuilder origin(TransformationHelper.TransformOrigin origin)
|
||||
{
|
||||
public RootTransformsBuilder origin(TransformationHelper.TransformOrigin origin) {
|
||||
this.origin = Preconditions.checkNotNull(origin, "Origin must not be null");
|
||||
this.originVec = null;
|
||||
return this;
|
||||
@@ -1061,8 +1028,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* Finish configuring the parent builder
|
||||
* @return the parent block model builder
|
||||
*/
|
||||
public ModelBuilder<T> end()
|
||||
{
|
||||
public ModelBuilder<T> end() {
|
||||
return ModelBuilder.this;
|
||||
}
|
||||
|
||||
@@ -1071,39 +1037,26 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
JsonObject transform = new JsonObject();
|
||||
|
||||
if (!translation.equals(0, 0, 0))
|
||||
{
|
||||
transform.add("translation", writeVec3(translation));
|
||||
}
|
||||
|
||||
if (!scale.equals(ONE))
|
||||
{
|
||||
transform.add("scale", writeVec3(scale));
|
||||
}
|
||||
|
||||
if (!leftRotation.equals(0, 0, 0, 1))
|
||||
{
|
||||
transform.add("rotation", writeQuaternion(leftRotation));
|
||||
}
|
||||
|
||||
if (!rightRotation.equals(0, 0, 0, 1))
|
||||
{
|
||||
transform.add("post_rotation", writeQuaternion(rightRotation));
|
||||
}
|
||||
|
||||
if (origin != null)
|
||||
{
|
||||
transform.addProperty("origin", origin.getSerializedName());
|
||||
}
|
||||
else if (originVec != null && !originVec.equals(0, 0, 0))
|
||||
{
|
||||
transform.add("origin", writeVec3(originVec));
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
private static JsonArray writeVec3(Vector3f vector)
|
||||
{
|
||||
private static JsonArray writeVec3(Vector3f vector) {
|
||||
JsonArray array = new JsonArray();
|
||||
array.add(vector.x());
|
||||
array.add(vector.y());
|
||||
@@ -1111,8 +1064,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
return array;
|
||||
}
|
||||
|
||||
private static JsonArray writeQuaternion(Quaternionf quaternion)
|
||||
{
|
||||
private static JsonArray writeQuaternion(Quaternionf quaternion) {
|
||||
JsonArray array = new JsonArray();
|
||||
array.add(quaternion.x());
|
||||
array.add(quaternion.y());
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class ModelFile {
|
||||
public static class UncheckedModelFile extends ModelFile {
|
||||
|
||||
public UncheckedModelFile(String location) {
|
||||
this(new ResourceLocation(location));
|
||||
this(ResourceLocation.parse(location));
|
||||
}
|
||||
public UncheckedModelFile(ResourceLocation location) {
|
||||
super(location);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -32,7 +30,6 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
protected static final ResourceType MODEL = new ResourceType(PackType.CLIENT_RESOURCES, ".json", "models");
|
||||
protected static final ResourceType MODEL_WITH_EXTENSION = new ResourceType(PackType.CLIENT_RESOURCES, "", "models");
|
||||
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
|
||||
protected final PackOutput output;
|
||||
protected final String modid;
|
||||
protected final String folder;
|
||||
@@ -63,7 +60,7 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
|
||||
public T getBuilder(String path) {
|
||||
Preconditions.checkNotNull(path, "Path must not be null");
|
||||
ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? new ResourceLocation(path) : new ResourceLocation(modid, path));
|
||||
ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? ResourceLocation.parse(path) : ResourceLocation.fromNamespaceAndPath(modid, path));
|
||||
this.existingFileHelper.trackGenerated(outputLoc, MODEL);
|
||||
return generatedModels.computeIfAbsent(outputLoc, factory);
|
||||
}
|
||||
@@ -72,15 +69,15 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
if (rl.getPath().contains("/")) {
|
||||
return rl;
|
||||
}
|
||||
return new ResourceLocation(rl.getNamespace(), folder + "/" + rl.getPath());
|
||||
return rl.withPrefix(folder + '/');
|
||||
}
|
||||
|
||||
public ResourceLocation modLoc(String name) {
|
||||
return new ResourceLocation(modid, name);
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
}
|
||||
|
||||
public ResourceLocation mcLoc(String name) {
|
||||
return new ResourceLocation(name);
|
||||
return ResourceLocation.parse(name);
|
||||
}
|
||||
|
||||
public T withExistingParent(String name, String parent) {
|
||||
@@ -375,9 +372,8 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
/**
|
||||
* {@return a model builder that's not directly saved to disk. Meant for use in custom model loaders.}
|
||||
*/
|
||||
public T nested()
|
||||
{
|
||||
return factory.apply(new ResourceLocation("dummy:dummy"));
|
||||
public T nested() {
|
||||
return factory.apply(ResourceLocation.fromNamespaceAndPath("dummy", "dummy"));
|
||||
}
|
||||
|
||||
public ModelFile.ExistingModelFile getExistingFile(ResourceLocation path) {
|
||||
|
||||
+3
-1
@@ -17,6 +17,8 @@ import java.util.*;
|
||||
|
||||
public class CompositeModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "composite");
|
||||
|
||||
public static <T extends ModelBuilder<T>> CompositeModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new CompositeModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -27,7 +29,7 @@ public class CompositeModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
|
||||
protected CompositeModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:composite"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public CompositeModelBuilder<T> child(String name, T modelBuilder)
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class DynamicFluidContainerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "fluid_container");
|
||||
public static <T extends ModelBuilder<T>> DynamicFluidContainerModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new DynamicFluidContainerModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +30,7 @@ public class DynamicFluidContainerModelBuilder<T extends ModelBuilder<T>> extend
|
||||
|
||||
protected DynamicFluidContainerModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:fluid_container"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public DynamicFluidContainerModelBuilder<T> fluid(Fluid fluid)
|
||||
|
||||
+4
-3
@@ -26,6 +26,7 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "item_layers");
|
||||
public static <T extends ModelBuilder<T>> ItemLayerModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new ItemLayerModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -37,7 +38,7 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
|
||||
protected ItemLayerModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:item_layers"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +110,9 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
ResourceLocation asLoc;
|
||||
if (renderType.contains(":"))
|
||||
asLoc = new ResourceLocation(renderType);
|
||||
asLoc = ResourceLocation.parse(renderType);
|
||||
else
|
||||
asLoc = new ResourceLocation(parent.getLocation().getNamespace(), renderType);
|
||||
asLoc = parent.getLocation().withPath(renderType);
|
||||
return renderType(asLoc, layers);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "obj");
|
||||
public static <T extends ModelBuilder<T>> ObjModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new ObjModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +30,7 @@ public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuil
|
||||
|
||||
protected ObjModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:obj"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public ObjModelBuilder<T> modelLocation(ResourceLocation modelLocation)
|
||||
|
||||
+3
-1
@@ -19,6 +19,8 @@ import java.util.Map;
|
||||
|
||||
public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "separate_transforms");
|
||||
|
||||
public static <T extends ModelBuilder<T>> SeparateTransformsModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new SeparateTransformsModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +31,7 @@ public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends C
|
||||
|
||||
protected SeparateTransformsModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:separate_transforms"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public SeparateTransformsModelBuilder<T> base(T modelBuilder)
|
||||
|
||||
+2
-2
@@ -156,12 +156,12 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext
|
||||
this.gui3d = other.gui3d;
|
||||
}
|
||||
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform, ItemOverrides overrides)
|
||||
{
|
||||
IUnbakedGeometry<?> geometry = getCustomGeometry();
|
||||
if (geometry == null)
|
||||
throw new IllegalStateException("Can not use custom baking without custom geometry");
|
||||
return geometry.bake(this, baker, bakedTextureGetter, modelTransform, overrides, modelLocation);
|
||||
return geometry.bake(this, baker, bakedTextureGetter, modelTransform, overrides);
|
||||
}
|
||||
|
||||
public static class VisibilityData
|
||||
|
||||
@@ -26,25 +26,20 @@ import net.minecraft.resources.ResourceLocation;
|
||||
* @see IGeometryLoader
|
||||
* @see IGeometryBakingContext
|
||||
*/
|
||||
public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>>
|
||||
{
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation);
|
||||
public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>> {
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides);
|
||||
|
||||
/**
|
||||
* Resolve parents of nested {@link BlockModel}s which are later used in
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState, ItemOverrides, ResourceLocation)}
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState, ItemOverrides)}
|
||||
* via {@link BlockModel#resolveParents(Function)}
|
||||
*/
|
||||
default void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context)
|
||||
{
|
||||
|
||||
}
|
||||
default void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context) { }
|
||||
|
||||
/**
|
||||
* {@return a set of all the components whose visibility may be configured via {@link IGeometryBakingContext}}
|
||||
*/
|
||||
default Set<String> getConfigurableComponentNames()
|
||||
{
|
||||
default Set<String> getConfigurableComponentNames() {
|
||||
return Set.of();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import net.minecraftforge.client.model.IModelBuilder;
|
||||
public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>> implements IUnbakedGeometry<T>
|
||||
{
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
TextureAtlasSprite particle = spriteGetter.apply(context.getMaterial("particle"));
|
||||
|
||||
@@ -33,10 +33,10 @@ public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>>
|
||||
IModelBuilder<?> builder = IModelBuilder.of(context.useAmbientOcclusion(), context.useBlockLight(), context.isGui3d(),
|
||||
context.getTransforms(), overrides, particle, renderTypes);
|
||||
|
||||
addQuads(context, builder, baker, spriteGetter, modelState, modelLocation);
|
||||
addQuads(context, builder, baker, spriteGetter, modelState);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected abstract void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation);
|
||||
protected abstract void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform);
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
{
|
||||
public static final ResourceLocation LOCATION = new ResourceLocation("forge", "standalone");
|
||||
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath("forge", "standalone");
|
||||
|
||||
public static final StandaloneGeometryBakingContext INSTANCE = create(LOCATION);
|
||||
|
||||
|
||||
@@ -91,22 +91,22 @@ public class UnbakedGeometryHelper
|
||||
tex = namespace != null ? namespace + ":" + path : path;
|
||||
}
|
||||
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(tex));
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.parse(tex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for baking {@link BlockModel} instances. Handles baking custom geometries and deferring item model baking.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static BakedModel bake(BlockModel blockModel, ModelBaker modelBaker, BlockModel owner, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation, boolean guiLight3d)
|
||||
public static BakedModel bake(BlockModel blockModel, ModelBaker modelBaker, BlockModel owner, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, boolean guiLight3d)
|
||||
{
|
||||
IUnbakedGeometry<?> customModel = blockModel.customData.getCustomGeometry();
|
||||
if (customModel != null)
|
||||
return customModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter), modelLocation);
|
||||
return customModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter));
|
||||
|
||||
// Handle vanilla item models here, since vanilla has a shortcut for them
|
||||
if (blockModel.getRootModel() == ModelBakery.GENERATION_MARKER)
|
||||
return ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBaker, blockModel, spriteGetter, modelState, modelLocation, guiLight3d);
|
||||
return ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBaker, blockModel, spriteGetter, modelState, guiLight3d);
|
||||
|
||||
if (blockModel.getRootModel() == ModelBakery.BLOCK_ENTITY_MARKER)
|
||||
{
|
||||
@@ -115,15 +115,7 @@ public class UnbakedGeometryHelper
|
||||
}
|
||||
|
||||
var elementsModel = new ElementsModel(blockModel.getElements());
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter), modelLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #createUnbakedItemElements(int, SpriteContents, ForgeFaceData)
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
return createUnbakedItemElements(layerIndex, spriteContents, null);
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,22 +124,9 @@ public class UnbakedGeometryHelper
|
||||
* <p>
|
||||
* The {@link Direction#NORTH} and {@link Direction#SOUTH} faces take up the whole surface.
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents, @Nullable ForgeFaceData faceData)
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
var elements = ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
if(faceData != null)
|
||||
{
|
||||
elements.forEach(element -> element.setFaceData(faceData));
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #createUnbakedItemMaskElements(int, SpriteContents, ForgeFaceData)
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
return createUnbakedItemMaskElements(layerIndex, spriteContents, null);
|
||||
return ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,9 +135,9 @@ public class UnbakedGeometryHelper
|
||||
* <p>
|
||||
* The {@link Direction#NORTH} and {@link Direction#SOUTH} faces take up only the pixels the texture uses.
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents, @Nullable ForgeFaceData faceData)
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
var elements = createUnbakedItemElements(layerIndex, spriteContents, faceData);
|
||||
var elements = createUnbakedItemElements(layerIndex, spriteContents);
|
||||
elements.remove(0); // Remove north and south faces
|
||||
|
||||
int width = spriteContents.width(), height = spriteContents.height();
|
||||
@@ -224,17 +203,17 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Bakes a list of {@linkplain BlockElement block elements} and feeds the baked quads to a {@linkplain IModelBuilder model builder}.
|
||||
*/
|
||||
public static void bakeElements(IModelBuilder<?> builder, List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
public static void bakeElements(IModelBuilder<?> builder, List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
for (BlockElement element : elements)
|
||||
{
|
||||
element.faces.forEach((side, face) -> {
|
||||
var sprite = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(face.texture)));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState, modelLocation);
|
||||
if (face.cullForDirection == null)
|
||||
var sprite = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.parse(face.texture())));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState);
|
||||
if (face.cullForDirection() == null)
|
||||
builder.addUnculledFace(quad);
|
||||
else
|
||||
builder.addCulledFace(Direction.rotate(modelState.getRotation().getMatrix(), face.cullForDirection), quad);
|
||||
builder.addCulledFace(Direction.rotate(modelState.getRotation().getMatrix(), face.cullForDirection()), quad);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -242,21 +221,21 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Bakes a list of {@linkplain BlockElement block elements} and returns the list of baked quads.
|
||||
*/
|
||||
public static List<BakedQuad> bakeElements(List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
public static List<BakedQuad> bakeElements(List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
if (elements.isEmpty())
|
||||
return List.of();
|
||||
var list = new ArrayList<BakedQuad>();
|
||||
bakeElements(IModelBuilder.collecting(list), elements, spriteGetter, modelState, modelLocation);
|
||||
bakeElements(IModelBuilder.collecting(list), elements, spriteGetter, modelState);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a single {@link BlockElementFace} into a {@link BakedQuad}.
|
||||
*/
|
||||
public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState state, ResourceLocation modelLocation)
|
||||
public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState state)
|
||||
{
|
||||
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade, modelLocation);
|
||||
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,4 +265,4 @@ public class UnbakedGeometryHelper
|
||||
rootTransform = rootTransform.applyOrigin(new Vector3f(-.5F, -.5F, -.5F));
|
||||
return new SimpleModelState(modelState.getRotation().compose(rootTransform), modelState.isUvLocked());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,21 +152,4 @@ public abstract class QuadLighter
|
||||
float yFactor = constantAmbientLight ? 0.9F : ((3.0F + normalY) / 4.0F);
|
||||
return Math.min(normalX * normalX * 0.6F + normalY * normalY * yFactor + normalZ * normalZ * 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is subtly different than {@link net.minecraft.client.renderer.LevelRenderer#getLightColor(BlockAndTintGetter, BlockState, BlockPos)}
|
||||
* as it only uses the state for querying if the state has emissive rendering but instead looks up the state at the given position for checking the
|
||||
* light emission.
|
||||
*/
|
||||
@Deprecated(since = "1.20.1")
|
||||
protected static int getLightColor(BlockAndTintGetter level, BlockPos pos, BlockState state)
|
||||
{
|
||||
if (state.emissiveRendering(level, pos))
|
||||
{
|
||||
return LightTexture.FULL_BRIGHT;
|
||||
}
|
||||
int skyLight = level.getBrightness(LightLayer.SKY, pos);
|
||||
int blockLight = Math.max(level.getBrightness(LightLayer.BLOCK, pos), level.getBlockState(pos).getLightEmission(level, pos));
|
||||
return skyLight << 20 | blockLight << 4;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -58,7 +57,7 @@ public class ObjLoader implements IGeometryLoader<ObjModel>, ResourceManagerRelo
|
||||
boolean emissiveAmbient = GsonHelper.getAsBoolean(jsonObject, "emissive_ambient", true);
|
||||
String mtlOverride = GsonHelper.getAsString(jsonObject, "mtl_override", null);
|
||||
|
||||
return loadModel(new ObjModel.ModelSettings(new ResourceLocation(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride));
|
||||
return loadModel(new ObjModel.ModelSettings(ResourceLocation.parse(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride));
|
||||
}
|
||||
|
||||
public ObjModel loadModel(ObjModel.ModelSettings settings)
|
||||
|
||||
@@ -119,9 +119,9 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
{
|
||||
String lib = materialLibraryOverrideLocation;
|
||||
if (lib.contains(":"))
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
|
||||
else
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.fromNamespaceAndPath(modelDomain, modelPath + lib));
|
||||
}
|
||||
|
||||
String[] line;
|
||||
@@ -136,9 +136,9 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
|
||||
String lib = line[1];
|
||||
if (lib.contains(":"))
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
|
||||
else
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.fromNamespaceAndPath(modelDomain, modelPath + lib));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform)
|
||||
{
|
||||
parts.values().stream().filter(part -> owner.isComponentVisible(part.name(), true))
|
||||
.forEach(part -> part.addQuads(owner, modelBuilder, baker, spriteGetter, modelTransform, modelLocation));
|
||||
@@ -421,19 +421,18 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
color.y() * colorTint.y(),
|
||||
color.z() * colorTint.z(),
|
||||
color.w() * colorTint.w());
|
||||
quadBaker.vertex(position.x(), position.y(), position.z());
|
||||
quadBaker.color(tintedColor.x(), tintedColor.y(), tintedColor.z(), tintedColor.w());
|
||||
quadBaker.uv(
|
||||
quadBaker.addVertex(position.x(), position.y(), position.z());
|
||||
quadBaker.setColor(tintedColor.x(), tintedColor.y(), tintedColor.z(), tintedColor.w());
|
||||
quadBaker.setUv(
|
||||
texture.getU(texCoord.x),
|
||||
texture.getV((flipV ? 1 - texCoord.y : texCoord.y))
|
||||
);
|
||||
quadBaker.uv2(uv2);
|
||||
quadBaker.normal(normal.x(), normal.y(), normal.z());
|
||||
quadBaker.setUv2(uv2 & 0xFFFF, uv2 >> 16 & 0xFFFF);
|
||||
quadBaker.setNormal(normal.x(), normal.y(), normal.z());
|
||||
if (i == 0)
|
||||
{
|
||||
quadBaker.setDirection(Direction.getNearest(normal.x(), normal.y(), normal.z()));
|
||||
}
|
||||
quadBaker.endVertex();
|
||||
pos[i] = position;
|
||||
norm[i] = normal;
|
||||
}
|
||||
@@ -656,7 +655,7 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
}
|
||||
|
||||
ResourceLocation textureLocation = UnbakedGeometryHelper.resolveDirtyMaterial(mat.diffuseColorMap, configuration).texture();
|
||||
ResourceLocation texturePath = new ResourceLocation(textureLocation.getNamespace(), "textures/" + textureLocation.getPath() + ".png");
|
||||
ResourceLocation texturePath = textureLocation.withPath(p -> "textures/" + p + ".png");
|
||||
|
||||
builder.addMesh(texturePath, quads);
|
||||
}
|
||||
|
||||
+12
-19
@@ -52,8 +52,10 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
endVertex();
|
||||
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.POSITION;
|
||||
quadData[offset] = Float.floatToRawIntBits((float) x);
|
||||
quadData[offset + 1] = Float.floatToRawIntBits((float) y);
|
||||
@@ -62,7 +64,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.NORMAL;
|
||||
quadData[offset] = ((int) (x * 127.0f) & 0xFF) |
|
||||
@@ -72,7 +74,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
public VertexConsumer setColor(int r, int g, int b, int a)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.COLOR;
|
||||
quadData[offset] = ((a & 0xFF) << 24) |
|
||||
@@ -83,7 +85,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
public VertexConsumer setUv(float u, float v)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV0;
|
||||
quadData[offset] = Float.floatToRawIntBits(u);
|
||||
@@ -92,7 +94,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
public VertexConsumer setUv1(int u, int v)
|
||||
{
|
||||
if (IQuadTransformer.UV1 >= 0) // Vanilla doesn't support this, but it may be added by a 3rd party
|
||||
{
|
||||
@@ -103,7 +105,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
public VertexConsumer setUv2(int u, int v)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV2;
|
||||
quadData[offset] = (u & 0xFFFF) | ((v & 0xFFFF) << 16);
|
||||
@@ -122,27 +124,18 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
private void endVertex()
|
||||
{
|
||||
if (++vertexIndex != 4)
|
||||
if (vertexIndex != 4) {
|
||||
++vertexIndex;
|
||||
return;
|
||||
}
|
||||
// We have a full quad, pass it to the consumer and reset
|
||||
quadConsumer.accept(new BakedQuad(quadData, tintIndex, direction, sprite, shade, hasAmbientOcclusion));
|
||||
vertexIndex = 0;
|
||||
quadData = new int[QUAD_DATA_SIZE];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
}
|
||||
|
||||
public void setTintIndex(int tintIndex)
|
||||
{
|
||||
this.tintIndex = tintIndex;
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Vertex pipeline element that remaps incoming data to another format.
|
||||
*/
|
||||
public class RemappingVertexPipeline implements VertexConsumer
|
||||
{
|
||||
private static final Set<VertexFormatElement> KNOWN_ELEMENTS = Set.of(DefaultVertexFormat.ELEMENT_POSITION,
|
||||
DefaultVertexFormat.ELEMENT_COLOR, DefaultVertexFormat.ELEMENT_UV, DefaultVertexFormat.ELEMENT_UV1,
|
||||
DefaultVertexFormat.ELEMENT_UV2, DefaultVertexFormat.ELEMENT_NORMAL, DefaultVertexFormat.ELEMENT_PADDING);
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
private final VertexConsumer parent;
|
||||
private final VertexFormat targetFormat;
|
||||
|
||||
private final Vector3d position = new Vector3d();
|
||||
private final Vector3f normal = new Vector3f();
|
||||
private final int[] color = new int[] { 255, 255, 255, 255 };
|
||||
private final float[] uv0 = new float[] { 0, 0 };
|
||||
private final int[] uv1 = new int[] { OverlayTexture.NO_WHITE_U, OverlayTexture.WHITE_OVERLAY_V };
|
||||
private final int[] uv2 = new int[] { 0, 0 };
|
||||
|
||||
private final Map<VertexFormatElement, Integer> miscElementIds;
|
||||
private final int[][] misc;
|
||||
|
||||
public RemappingVertexPipeline(VertexConsumer parent, VertexFormat targetFormat)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.targetFormat = targetFormat;
|
||||
|
||||
this.miscElementIds = new IdentityHashMap<>();
|
||||
int i = 0;
|
||||
for (var element : targetFormat.getElements())
|
||||
if (element.getUsage() != VertexFormatElement.Usage.PADDING && !KNOWN_ELEMENTS.contains(element))
|
||||
this.miscElementIds.put(element, i++);
|
||||
this.misc = new int[i][];
|
||||
Arrays.fill(this.misc, EMPTY_INT_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
{
|
||||
position.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
{
|
||||
normal.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
{
|
||||
color[0] = r;
|
||||
color[1] = g;
|
||||
color[2] = b;
|
||||
color[3] = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
{
|
||||
uv0[0] = u;
|
||||
uv0[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
{
|
||||
uv1[0] = u;
|
||||
uv1[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
{
|
||||
uv2[0] = u;
|
||||
uv2[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer misc(VertexFormatElement element, int... values)
|
||||
{
|
||||
Integer id = miscElementIds.get(element);
|
||||
if (id != null)
|
||||
misc[id] = Arrays.copyOf(values, values.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
{
|
||||
for (var element : targetFormat.getElements())
|
||||
{
|
||||
// Ignore padding
|
||||
if (element.getUsage() == VertexFormatElement.Usage.PADDING)
|
||||
continue;
|
||||
|
||||
// Try to match and output any of the supported elements, and if that fails, treat as misc
|
||||
if (element.equals(DefaultVertexFormat.ELEMENT_POSITION))
|
||||
parent.vertex(position.x, position.y, position.z);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_NORMAL))
|
||||
parent.normal(normal.x(), normal.y(), normal.z());
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_COLOR))
|
||||
parent.color(color[0], color[1], color[2], color[3]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV0))
|
||||
parent.uv(uv0[0], uv0[1]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV1))
|
||||
parent.overlayCoords(uv1[0], uv1[1]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV2))
|
||||
parent.uv2(uv2[0], uv2[1]);
|
||||
else
|
||||
parent.misc(element, misc[miscElementIds.get(element)]);
|
||||
}
|
||||
parent.endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.defaultColor(r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
parent.unsetDefaultColor();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -24,21 +24,21 @@ public class TransformingVertexPipeline extends VertexConsumerWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
var vec = new Vector4f((float) x, (float) y, (float) z, 1);
|
||||
transformation.transformPosition(vec);
|
||||
vec.div(vec.w);
|
||||
return super.vertex(vec.x(), vec.y(), vec.z());
|
||||
return super.addVertex(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
var vec = new Vector3f(x, y, z);
|
||||
transformation.transformNormal(vec);
|
||||
vec.normalize();
|
||||
return super.normal(vec.x(), vec.y(), vec.z());
|
||||
return super.setNormal(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,44 +23,44 @@ public abstract class VertexConsumerWrapper implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
parent.vertex(x, y, z);
|
||||
parent.addVertex(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
public VertexConsumer setColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.color(r, g, b, a);
|
||||
parent.setColor(r, g, b, a);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
public VertexConsumer setUv(float u, float v)
|
||||
{
|
||||
parent.uv(u, v);
|
||||
parent.setUv(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
public VertexConsumer setUv1(int u, int v)
|
||||
{
|
||||
parent.overlayCoords(u, v);
|
||||
parent.setUv1(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
public VertexConsumer setUv2(int u, int v)
|
||||
{
|
||||
parent.uv2(u, v);
|
||||
parent.setUv2(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
parent.normal(x, y, z);
|
||||
parent.setNormal(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -70,22 +70,4 @@ public abstract class VertexConsumerWrapper implements VertexConsumer
|
||||
parent.misc(element, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
{
|
||||
parent.endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.defaultColor(r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
parent.unsetDefaultColor();
|
||||
}
|
||||
}
|
||||
+11
-20
@@ -10,6 +10,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.RandomSource;
|
||||
@@ -30,42 +31,36 @@ import java.util.Arrays;
|
||||
*
|
||||
* @see Context
|
||||
*/
|
||||
public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Context>
|
||||
{
|
||||
public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Context> {
|
||||
/**
|
||||
* Constructs a {@link BakedModelRenderable} from the given model location.
|
||||
* The model is expected to have been baked ahead of time.
|
||||
*
|
||||
* @see net.minecraftforge.client.event.ModelEvent.RegisterAdditional
|
||||
*/
|
||||
public static BakedModelRenderable of(ResourceLocation model)
|
||||
{
|
||||
public static BakedModelRenderable of(ModelResourceLocation model) {
|
||||
return of(Minecraft.getInstance().getModelManager().getModel(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link BakedModelRenderable} from the given baked model.
|
||||
*/
|
||||
public static BakedModelRenderable of(BakedModel model)
|
||||
{
|
||||
public static BakedModelRenderable of(BakedModel model) {
|
||||
return new BakedModelRenderable(model);
|
||||
}
|
||||
|
||||
private final BakedModel model;
|
||||
|
||||
private BakedModelRenderable(BakedModel model)
|
||||
{
|
||||
private BakedModelRenderable(BakedModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, MultiBufferSource bufferSource, ITextureRenderTypeLookup textureRenderTypeLookup, int lightmap, int overlay, float partialTick, Context context)
|
||||
{
|
||||
public void render(PoseStack poseStack, MultiBufferSource bufferSource, ITextureRenderTypeLookup textureRenderTypeLookup, int lightmap, int overlay, float partialTick, Context context) {
|
||||
var buffer = bufferSource.getBuffer(textureRenderTypeLookup.get(InventoryMenu.BLOCK_ATLAS));
|
||||
var tint = context.tint();
|
||||
var randomSource = context.randomSource();
|
||||
for (Direction direction : context.faces())
|
||||
{
|
||||
for (var direction : context.faces()) {
|
||||
randomSource.setSeed(context.seed());
|
||||
// Given the lack of context, the requested render type has to be null to ensure the model renders all of its geometry
|
||||
for (BakedQuad quad : model.getQuads(context.state(), direction, randomSource, context.data(), null))
|
||||
@@ -73,24 +68,20 @@ public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Co
|
||||
}
|
||||
}
|
||||
|
||||
public IRenderable<Unit> withContext(ModelData modelData)
|
||||
{
|
||||
public IRenderable<Unit> withContext(ModelData modelData) {
|
||||
return withContext(new Context(modelData));
|
||||
}
|
||||
|
||||
public IRenderable<ModelData> withModelDataContext()
|
||||
{
|
||||
public IRenderable<ModelData> withModelDataContext() {
|
||||
return (poseStack, bufferSource, textureRenderTypeLookup, lightmap, overlay, partialTick, context) ->
|
||||
render(poseStack, bufferSource, textureRenderTypeLookup, lightmap, overlay, partialTick, new Context(context));
|
||||
}
|
||||
|
||||
public record Context(@Nullable BlockState state, Direction[] faces, RandomSource randomSource, long seed, ModelData data, Vector4f tint)
|
||||
{
|
||||
public record Context(@Nullable BlockState state, Direction[] faces, RandomSource randomSource, long seed, ModelData data, Vector4f tint) {
|
||||
private static final Direction[] ALL_FACES_AND_NULL = Arrays.copyOf(Direction.values(), Direction.values().length + 1);
|
||||
private static final Vector4f WHITE = new Vector4f(1, 1, 1, 1);
|
||||
|
||||
public Context(ModelData data)
|
||||
{
|
||||
public Context(ModelData data) {
|
||||
this(null, ALL_FACES_AND_NULL, RandomSource.create(), 42, data, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,18 +93,6 @@ public enum KeyModifier {
|
||||
}
|
||||
};
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public static final KeyModifier[] MODIFIER_VALUES = {SHIFT, CONTROL, ALT};
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.20.2")
|
||||
public static KeyModifier getActiveModifier() {
|
||||
for (var keyModifier : VALUES) {
|
||||
if (keyModifier.isActive(null))
|
||||
return keyModifier;
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
private static final KeyModifier[] VALUES = {SHIFT, CONTROL, ALT};
|
||||
private static final List<KeyModifier> VALUES_LIST = List.of(SHIFT, CONTROL, ALT);
|
||||
private static final List<KeyModifier> ALL = List.of(SHIFT, CONTROL, ALT, NONE);
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class ForgeTextureMetadata
|
||||
ITextureAtlasSpriteLoader loader;
|
||||
if (json.has("loader"))
|
||||
{
|
||||
ResourceLocation loaderName = new ResourceLocation(GsonHelper.getAsString(json, "loader"));
|
||||
ResourceLocation loaderName = ResourceLocation.parse(GsonHelper.getAsString(json, "loader"));
|
||||
loader = TextureAtlasSpriteLoaderManager.get(loaderName);
|
||||
if (loader == null)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
* Useful for baking quads that won't be used with an atlas.
|
||||
*/
|
||||
public class UnitTextureAtlasSprite extends TextureAtlasSprite {
|
||||
public static final ResourceLocation LOCATION = new ResourceLocation("forge", "unit");
|
||||
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath("forge", "unit");
|
||||
public static final UnitTextureAtlasSprite INSTANCE = new UnitTextureAtlasSprite();
|
||||
|
||||
private UnitTextureAtlasSprite() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.gson.JsonObject;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -30,10 +31,6 @@ import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.CreativeModeTabSearchRegistry;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.toposort.TopologicalSort;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -50,10 +47,9 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class CreativeModeTabRegistry
|
||||
{
|
||||
public final class CreativeModeTabRegistry {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final ResourceLocation CREATIVE_MODE_TAB_ORDERING_JSON = new ResourceLocation("forge", "creative_mode_tab_ordering.json");
|
||||
private static final ResourceLocation CREATIVE_MODE_TAB_ORDERING_JSON = ResourceLocation.fromNamespaceAndPath("forge", "creative_mode_tab_ordering.json");
|
||||
private static final List<CreativeModeTab> SORTED_TABS = new ArrayList<>();
|
||||
private static final List<CreativeModeTab> SORTED_TABS_VIEW = Collections.unmodifiableList(SORTED_TABS);
|
||||
private static final List<CreativeModeTab> DEFAULT_TABS = new ArrayList<>();
|
||||
@@ -61,8 +57,7 @@ public final class CreativeModeTabRegistry
|
||||
/**
|
||||
* {@return an unmodifiable view of the sorted list of creative mode tabs in ascending order}
|
||||
*/
|
||||
public static List<CreativeModeTab> getSortedCreativeModeTabs()
|
||||
{
|
||||
public static List<CreativeModeTab> getSortedCreativeModeTabs() {
|
||||
return SORTED_TABS_VIEW;
|
||||
}
|
||||
|
||||
@@ -76,8 +71,7 @@ public final class CreativeModeTabRegistry
|
||||
* @param name the name to look up
|
||||
*/
|
||||
@Nullable
|
||||
public static CreativeModeTab getTab(ResourceLocation name)
|
||||
{
|
||||
public static CreativeModeTab getTab(ResourceLocation name) {
|
||||
return BuiltInRegistries.CREATIVE_MODE_TAB.get(name);
|
||||
}
|
||||
|
||||
@@ -87,50 +81,39 @@ public final class CreativeModeTabRegistry
|
||||
* @param tab the tab to look up
|
||||
*/
|
||||
@Nullable
|
||||
public static ResourceLocation getName(CreativeModeTab tab)
|
||||
{
|
||||
public static ResourceLocation getName(CreativeModeTab tab) {
|
||||
return BuiltInRegistries.CREATIVE_MODE_TAB.getKey(tab);
|
||||
}
|
||||
|
||||
private static final Multimap<ResourceLocation, ResourceLocation> edges = HashMultimap.create();
|
||||
|
||||
static PreparableReloadListener getReloadListener()
|
||||
{
|
||||
return new SimplePreparableReloadListener<JsonObject>()
|
||||
{
|
||||
static PreparableReloadListener getReloadListener() {
|
||||
return new SimplePreparableReloadListener<JsonObject>() {
|
||||
final Gson gson = new GsonBuilder().create();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JsonObject prepare(@NotNull ResourceManager resourceManager, ProfilerFiller profiler)
|
||||
{
|
||||
protected JsonObject prepare(@NotNull ResourceManager resourceManager, ProfilerFiller profiler) {
|
||||
Optional<Resource> res = resourceManager.getResource(CREATIVE_MODE_TAB_ORDERING_JSON);
|
||||
if (res.isEmpty())
|
||||
return new JsonObject();
|
||||
|
||||
try (Reader reader = res.get().openAsReader())
|
||||
{
|
||||
try (Reader reader = res.get().openAsReader()) {
|
||||
return this.gson.fromJson(reader, JsonObject.class);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Could not read CreativeModeTab sorting file " + CREATIVE_MODE_TAB_ORDERING_JSON, e);
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (data.size() > 0)
|
||||
{
|
||||
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p) {
|
||||
try {
|
||||
if (data.size() > 0) {
|
||||
JsonArray order = GsonHelper.getAsJsonArray(data, "order");
|
||||
List<CreativeModeTab> customOrder = new ArrayList<>();
|
||||
for (JsonElement entry : order)
|
||||
{
|
||||
ResourceLocation id = new ResourceLocation(entry.getAsString());
|
||||
for (JsonElement entry : order) {
|
||||
ResourceLocation id = ResourceLocation.parse(entry.getAsString());
|
||||
CreativeModeTab CreativeModeTab = getTab(id);
|
||||
if (CreativeModeTab == null)
|
||||
throw new IllegalStateException("CreativeModeTab not found with name " + id);
|
||||
@@ -145,9 +128,7 @@ public final class CreativeModeTabRegistry
|
||||
setCreativeModeTabOrder(customOrder);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error parsing CreativeModeTab sorting file " + CREATIVE_MODE_TAB_ORDERING_JSON, e);
|
||||
}
|
||||
|
||||
@@ -156,23 +137,21 @@ public final class CreativeModeTabRegistry
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private static void recalculateItemCreativeModeTabs()
|
||||
{
|
||||
private static void recalculateItemCreativeModeTabs() {
|
||||
final MutableGraph<CreativeModeTab> graph = GraphBuilder.directed().nodeOrder(ElementOrder.<CreativeModeTab>insertion()).build();
|
||||
|
||||
for (CreativeModeTab tab : BuiltInRegistries.CREATIVE_MODE_TAB)
|
||||
{
|
||||
for (CreativeModeTab tab : BuiltInRegistries.CREATIVE_MODE_TAB) {
|
||||
if (!DEFAULT_TABS.contains(tab))
|
||||
graph.addNode(tab);
|
||||
}
|
||||
edges.forEach((key, value) ->
|
||||
{
|
||||
|
||||
edges.forEach((key, value) -> {
|
||||
final CreativeModeTab keyC = getTab(key);
|
||||
final CreativeModeTab valueC = getTab(value);
|
||||
if (keyC != null && valueC != null)
|
||||
graph.putEdge(keyC, valueC);
|
||||
});
|
||||
|
||||
//Note: We can ignore the null warning as we validate getting tabs by key before adding to the graph
|
||||
// so the graph should only contain tabs that we know have names in the registry
|
||||
List<CreativeModeTab> tierList = TopologicalSort.topologicalSort(graph, Comparator.comparing(tab -> getName(tab)));
|
||||
@@ -180,17 +159,14 @@ public final class CreativeModeTabRegistry
|
||||
setCreativeModeTabOrder(tierList);
|
||||
}
|
||||
|
||||
private static void setCreativeModeTabOrder(List<CreativeModeTab> tierList)
|
||||
{
|
||||
runInServerThreadIfPossible(hasServer ->
|
||||
{
|
||||
private static void setCreativeModeTabOrder(List<CreativeModeTab> tierList) {
|
||||
runInServerThreadIfPossible(hasServer -> {
|
||||
SORTED_TABS.clear();
|
||||
SORTED_TABS.addAll(tierList);
|
||||
});
|
||||
}
|
||||
|
||||
private static void runInServerThreadIfPossible(BooleanConsumer runnable)
|
||||
{
|
||||
private static void runInServerThreadIfPossible(BooleanConsumer runnable) {
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if (server != null)
|
||||
server.execute(() -> runnable.accept(true));
|
||||
@@ -199,8 +175,7 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void sortTabs()
|
||||
{
|
||||
public static void sortTabs() {
|
||||
edges.clear();
|
||||
|
||||
DEFAULT_TABS.add(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.HOTBAR));
|
||||
@@ -212,16 +187,14 @@ public final class CreativeModeTabRegistry
|
||||
BuiltInRegistries.CREATIVE_MODE_TAB.holders().filter(c -> !DEFAULT_TABS.contains(c.get())).forEach(indexed::add);
|
||||
int vanillaTabs = 10;
|
||||
|
||||
for (int i = 0; i < vanillaTabs; i++) // Vanilla ordering
|
||||
{
|
||||
for (int i = 0; i < vanillaTabs; i++) { // Vanilla ordering
|
||||
final Holder<CreativeModeTab> value = indexed.get(i);
|
||||
final CreativeModeTab tab = value.get();
|
||||
final ResourceLocation name = value.unwrapKey().orElseThrow().location();
|
||||
|
||||
if (!tab.tabsBefore.isEmpty() || !tab.tabsAfter.isEmpty())
|
||||
addTabOrder(tab, name);
|
||||
else
|
||||
{
|
||||
else {
|
||||
// If there is no order specified ensure vanilla ordering by specifying the previous and next indexed tab as edges
|
||||
if (i != 0)
|
||||
edges.put(indexed.get(i - 1).unwrapKey().orElseThrow().location(), name);
|
||||
@@ -231,8 +204,7 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
ResourceLocation lastVanilla = indexed.get(vanillaTabs - 1).unwrapKey().orElseThrow().location();
|
||||
for (int i = vanillaTabs; i < indexed.size(); i++)
|
||||
{
|
||||
for (int i = vanillaTabs; i < indexed.size(); i++) {
|
||||
final Holder<CreativeModeTab> value = indexed.get(i);
|
||||
final CreativeModeTab tab = value.get();
|
||||
final ResourceLocation name = value.unwrapKey().orElseThrow().location();
|
||||
@@ -244,22 +216,15 @@ public final class CreativeModeTabRegistry
|
||||
}
|
||||
|
||||
recalculateItemCreativeModeTabs();
|
||||
|
||||
if (FMLEnvironment.dist == Dist.CLIENT && !FMLLoader.getLaunchHandler().isData())
|
||||
CreativeModeTabSearchRegistry.createSearchTrees();
|
||||
}
|
||||
|
||||
private static void addTabOrder(CreativeModeTab tab, ResourceLocation name)
|
||||
{
|
||||
for (final ResourceLocation after : tab.tabsAfter)
|
||||
{
|
||||
private static void addTabOrder(CreativeModeTab tab, ResourceLocation name) {
|
||||
for (var after : tab.tabsAfter) {
|
||||
edges.put(name, after);
|
||||
}
|
||||
|
||||
for (final ResourceLocation before : tab.tabsBefore)
|
||||
{
|
||||
for (var before : tab.tabsBefore) {
|
||||
edges.put(before, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -52,6 +51,7 @@ import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
@@ -131,7 +131,6 @@ import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.GatherComponentsEvent;
|
||||
import net.minecraftforge.event.GrindstoneEvent;
|
||||
import net.minecraftforge.event.ModMismatchEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
@@ -143,16 +142,12 @@ import net.minecraftforge.event.entity.living.EnderManAngerEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDrownEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingMakeBrainEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingUseTotemEvent;
|
||||
import net.minecraftforge.event.entity.living.LootingLevelEvent;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.entity.player.CriticalHitEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
@@ -172,7 +167,6 @@ import net.minecraftforge.network.ForgePayload;
|
||||
import net.minecraftforge.network.NetworkContext;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
import net.minecraftforge.network.NetworkInitialization;
|
||||
import net.minecraftforge.network.NetworkProtocol;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.packets.SpawnEntity;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
@@ -265,16 +259,12 @@ public final class ForgeHooks {
|
||||
public static int getLootingLevel(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) {
|
||||
int looting = 0;
|
||||
if (killer instanceof LivingEntity living)
|
||||
looting = EnchantmentHelper.getMobLooting(living);
|
||||
if (target instanceof LivingEntity living)
|
||||
looting = getLootingLevel(living, cause, looting);
|
||||
return looting;
|
||||
}
|
||||
looting = EnchantmentHelper.getEnchantmentLevel(living.level().holderLookup(Registries.ENCHANTMENT).getOrThrow(Enchantments.LOOTING), living);
|
||||
|
||||
public static int getLootingLevel(LivingEntity target, @Nullable DamageSource cause, int level) {
|
||||
LootingLevelEvent event = new LootingLevelEvent(target, cause, level);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getLootingLevel();
|
||||
if (target instanceof LivingEntity living)
|
||||
looting = ForgeEventFactory.fireLootingLevel(living, cause, looting).getLootingLevel();
|
||||
|
||||
return looting;
|
||||
}
|
||||
|
||||
public static double getEntityVisibilityMultiplier(LivingEntity entity, Entity lookingEntity, double originalMultiplier){
|
||||
@@ -406,8 +396,9 @@ public final class ForgeHooks {
|
||||
}
|
||||
|
||||
public static void dropXpForBlock(BlockState state, ServerLevel level, BlockPos pos, ItemStack stack) {
|
||||
int fortuneLevel = stack.getEnchantmentLevel(Enchantments.FORTUNE);
|
||||
int silkTouchLevel = stack.getEnchantmentLevel(Enchantments.SILK_TOUCH);
|
||||
var lookup = level.holderLookup(Registries.ENCHANTMENT);
|
||||
int fortuneLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.FORTUNE), stack);
|
||||
int silkTouchLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.SILK_TOUCH), stack);
|
||||
int exp = state.getExpDrop(level, level.random, pos, fortuneLevel, silkTouchLevel);
|
||||
if (exp > 0)
|
||||
state.getBlock().popExperience(level, pos, exp);
|
||||
@@ -948,7 +939,7 @@ public final class ForgeHooks {
|
||||
Map<ResourceLocation, ForgeRegistry.Snapshot> snapshot = new HashMap<>();
|
||||
CompoundTag regs = tag.getCompound("Registries");
|
||||
for (String key : regs.getAllKeys())
|
||||
snapshot.put(new ResourceLocation(key), ForgeRegistry.Snapshot.read(regs.getCompound(key)));
|
||||
snapshot.put(ResourceLocation.parse(key), ForgeRegistry.Snapshot.read(regs.getCompound(key)));
|
||||
failedElements = GameData.injectSnapshot(snapshot, true, true);
|
||||
}
|
||||
|
||||
@@ -1013,30 +1004,6 @@ public final class ForgeHooks {
|
||||
return biomeLocation != null && !biomeLocation.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraft
|
||||
* </p>
|
||||
* <p>
|
||||
* This rules conflicts with equal paths out. If for example the mod {@code fancy_cheese} adds a registry named {@code cheeses},
|
||||
* but the mod {@code awesome_cheese} also adds a registry called {@code cheeses},
|
||||
* they are going to have the same path {@code cheeses}, just with different namespaces.
|
||||
* If {@code additional_cheese} wants to add additional cheese to {@code awesome_cheese}, but not {@code fancy_cheese},
|
||||
* it can not differentiate both. Both paths will look like {@code data/additional_cheese/cheeses}.
|
||||
* </p>
|
||||
* <p>
|
||||
* The fix, which is applied here prefixes the path of the registry with the namespace,
|
||||
* so {@code fancy_cheese}'s registry stores its elements in {@code data/<namespace>/fancy_cheese/cheeses}
|
||||
* and {@code awesome_cheese}'s registry stores its elements in {@code data/namespace/awesome_cheese/cheeses}
|
||||
* </p>
|
||||
*
|
||||
* @param registryKey key of the registry
|
||||
* @return path of the registry key. Prefixed with the namespace if it is not "minecraft"
|
||||
*/
|
||||
public static String prefixNamespace(ResourceLocation registryKey) {
|
||||
return registryKey.getNamespace().equals("minecraft") ? registryKey.getPath() : registryKey.getNamespace() + "/" + registryKey.getPath();
|
||||
}
|
||||
|
||||
public static boolean canUseEntitySelectors(SharedSuggestionProvider provider) {
|
||||
if (provider.hasPermission(Commands.LEVEL_GAMEMASTERS))
|
||||
return true;
|
||||
|
||||
@@ -17,10 +17,7 @@ import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.metadata.PackMetadataGenerator;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.ChatTypeDecoration;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
@@ -116,7 +113,6 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -233,10 +229,10 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation UNDERWATER_LOCATION = new ResourceLocation("textures/misc/underwater.png"),
|
||||
WATER_STILL = new ResourceLocation("block/water_still"),
|
||||
WATER_FLOW = new ResourceLocation("block/water_flow"),
|
||||
WATER_OVERLAY = new ResourceLocation("block/water_overlay");
|
||||
private static final ResourceLocation UNDERWATER_LOCATION = ResourceLocation.withDefaultNamespace("textures/misc/underwater.png");
|
||||
private static final ResourceLocation WATER_STILL = ResourceLocation.withDefaultNamespace("block/water_still");
|
||||
private static final ResourceLocation WATER_FLOW = ResourceLocation.withDefaultNamespace("block/water_flow");
|
||||
private static final ResourceLocation WATER_OVERLAY = ResourceLocation.withDefaultNamespace("block/water_overlay");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -300,8 +296,8 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation LAVA_STILL = new ResourceLocation("block/lava_still"),
|
||||
LAVA_FLOW = new ResourceLocation("block/lava_flow");
|
||||
private static final ResourceLocation LAVA_STILL = ResourceLocation.withDefaultNamespace("block/lava_still");
|
||||
private static final ResourceLocation LAVA_FLOW = ResourceLocation.withDefaultNamespace("block/lava_flow");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -350,11 +346,11 @@ public class ForgeMod {
|
||||
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
public static final RegistryObject<SoundEvent> BUCKET_EMPTY_MILK = RegistryObject.create(new ResourceLocation("item.bucket.empty_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_FILL_MILK = RegistryObject.create(new ResourceLocation("item.bucket.fill_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(new ResourceLocation("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(new ResourceLocation("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_EMPTY_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("item.bucket.empty_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<SoundEvent> BUCKET_FILL_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("item.bucket.fill_milk"), ForgeRegistries.SOUND_EVENTS);
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(ResourceLocation.withDefaultNamespace("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(ResourceLocation.withDefaultNamespace("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
|
||||
/*
|
||||
private static final ChatTypeDecoration SYSTEM_CHAT_TYPE_DECORATION = new ChatTypeDecoration("forge.chatType.system", List.of(ChatTypeDecoration.Parameter.CONTENT), Style.EMPTY);
|
||||
@@ -425,8 +421,8 @@ public class ForgeMod {
|
||||
ForgeRegistries.ITEMS.tags().addOptionalTagDefaults(Tags.Items.ENCHANTING_FUELS, Set.of(ForgeRegistries.ITEMS.getDelegateOrThrow(Items.LAPIS_LAZULI)));
|
||||
|
||||
// TODO: Remove when addAlias becomes proper API, as this should be done in the DR's above.
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, new ResourceLocation("forge", "reach_distance"), new ResourceLocation("forge", "block_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, new ResourceLocation("forge", "attack_range"), new ResourceLocation("forge", "entity_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, ResourceLocation.fromNamespaceAndPath("forge", "reach_distance"), ResourceLocation.fromNamespaceAndPath("forge", "block_reach"));
|
||||
addAlias(ForgeRegistries.ATTRIBUTES, ResourceLocation.fromNamespaceAndPath("forge", "attack_range"), ResourceLocation.fromNamespaceAndPath("forge", "entity_reach"));
|
||||
}
|
||||
|
||||
public void preInit(FMLCommonSetupEvent evt) {
|
||||
@@ -493,8 +489,8 @@ public class ForgeMod {
|
||||
@Override
|
||||
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
|
||||
consumer.accept(new IClientFluidTypeExtensions() {
|
||||
private static final ResourceLocation MILK_STILL = new ResourceLocation("forge", "block/milk_still");
|
||||
private static final ResourceLocation MILK_FLOW = new ResourceLocation("forge", "block/milk_flowing");
|
||||
private static final ResourceLocation MILK_STILL = ResourceLocation.fromNamespaceAndPath("forge", "block/milk_still");
|
||||
private static final ResourceLocation MILK_FLOW = ResourceLocation.fromNamespaceAndPath("forge", "block/milk_flowing");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture() {
|
||||
@@ -528,7 +524,7 @@ public class ForgeMod {
|
||||
|
||||
Arrays.stream(ItemDisplayContext.values())
|
||||
.filter(Predicate.not(ItemDisplayContext::isModded))
|
||||
.forEach(ctx -> forgeRegistry.register(ctx.getId(), new ResourceLocation("minecraft", ctx.getSerializedName()), ctx));
|
||||
.forEach(ctx -> forgeRegistry.register(ctx.getId(), ResourceLocation.fromNamespaceAndPath("minecraft", ctx.getSerializedName()), ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Block> tag(String name)
|
||||
{
|
||||
return BlockTags.create(new ResourceLocation("forge", name));
|
||||
return BlockTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class Tags
|
||||
|
||||
private static TagKey<EntityType<?>> tag(String name)
|
||||
{
|
||||
return TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation("forge", name));
|
||||
return TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Item> tag(String name)
|
||||
{
|
||||
return ItemTags.create(new ResourceLocation("forge", name));
|
||||
return ItemTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Fluid> tag(String name)
|
||||
{
|
||||
return FluidTags.create(new ResourceLocation("forge", name));
|
||||
return FluidTags.create(ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ public class Tags
|
||||
|
||||
private static TagKey<Biome> tag(String name)
|
||||
{
|
||||
return TagKey.create(Registries.BIOME, new ResourceLocation("forge", name));
|
||||
return TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath("forge", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class ConditionalAdvancement {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private static final ResourceLocation DOESNT_MATTER = new ResourceLocation("doesnt", "matter");
|
||||
private static final ResourceLocation DOESNT_MATTER = ResourceLocation.fromNamespaceAndPath("doesnt", "matter");
|
||||
|
||||
private List<Adv> advancements = new ArrayList<>();
|
||||
private ICondition condition;
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.data.recipes.RecipeBuilder;
|
||||
import net.minecraft.data.recipes.RecipeOutput;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@@ -134,7 +135,7 @@ public class ConditionalRecipe {
|
||||
}
|
||||
|
||||
public void save(RecipeOutput out, String namespace, String path) {
|
||||
save(out, new ResourceLocation(namespace, path));
|
||||
save(out, ResourceLocation.fromNamespaceAndPath(namespace, path));
|
||||
}
|
||||
|
||||
public void save(RecipeOutput out, ResourceLocation id) {
|
||||
@@ -168,9 +169,9 @@ public class ConditionalRecipe {
|
||||
private record InnerRecipe(ICondition condition, Recipe<?> recipe) {}
|
||||
private record InnerAdvancement(ICondition condition, AdvancementHolder advancement, JsonObject json) {}
|
||||
|
||||
private static class Wrapper implements Recipe<Container> {
|
||||
@Override public boolean matches(Container inv, Level level) { return false; }
|
||||
@Override public ItemStack assemble(Container inv, HolderLookup.Provider reg) { return null; }
|
||||
private static class Wrapper implements Recipe<CraftingInput> {
|
||||
@Override public boolean matches(CraftingInput inv, Level level) { return false; }
|
||||
@Override public ItemStack assemble(CraftingInput inv, HolderLookup.Provider reg) { return null; }
|
||||
@Override public boolean canCraftInDimensions(int width, int height) { return false; }
|
||||
@Override public ItemStack getResultItem(HolderLookup.Provider reg) { return null; }
|
||||
@Override public RecipeSerializer<?> getSerializer() { return ConditionalRecipe.SERIALZIER; }
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeInput;
|
||||
|
||||
/**
|
||||
* Used to mark a recipe that shape matters so that the recipe
|
||||
* book and auto crafting picks the correct shape.
|
||||
* Note: These methods can't be named 'getHeight' or 'getWidth' due to obfusication issues.
|
||||
*/
|
||||
public interface IShapedRecipe<T extends Container> extends Recipe<T> {
|
||||
public interface IShapedRecipe<T extends RecipeInput> extends Recipe<T> {
|
||||
int getRecipeWidth();
|
||||
int getRecipeHeight();
|
||||
}
|
||||
@@ -11,98 +11,15 @@ import it.unimi.dsi.fastutil.chars.Char2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.chars.CharArraySet;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class SimpleCraftingContainer implements CraftingContainer {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final NonNullList<ItemStack> items;
|
||||
|
||||
public class SimpleCraftingContainer {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer(int width, int height) {
|
||||
this(width, height, NonNullList.withSize(width * height, ItemStack.EMPTY));
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer(int width, int height, NonNullList<ItemStack> items) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.items = items;
|
||||
if (items.size() != (width * height))
|
||||
throw new IllegalArgumentException("Invalid item list, must be same size inventory width * height, received " + items.size() + " expected " + (width * height));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return this.items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.items.stream().noneMatch(p -> !p.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
return slot >= this.items.size() ? ItemStack.EMPTY : this.items.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItem(int slot, int count) {
|
||||
return ContainerHelper.removeItem(this.items, slot, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
return ContainerHelper.takeItem(this.items, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
this.items.set(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
this.items.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillStackedContents(StackedContents stacked) {
|
||||
this.items.forEach(stacked::accountSimpleStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
return List.copyOf(this.items);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<String> rows = new ArrayList<>();
|
||||
private final Char2ObjectMap<ItemStack> keys = new Char2ObjectOpenHashMap<>();
|
||||
@@ -135,7 +52,7 @@ public class SimpleCraftingContainer implements CraftingContainer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCraftingContainer build() {
|
||||
public CraftingInput build() {
|
||||
var unseen = new CharArraySet(this.keys.keySet());
|
||||
unseen.remove(' ');
|
||||
|
||||
@@ -160,7 +77,7 @@ public class SimpleCraftingContainer implements CraftingContainer {
|
||||
if (!unseen.isEmpty())
|
||||
throw new IllegalStateException("Invalid builder, missing usage of defined keys: " + unseen);
|
||||
|
||||
return new SimpleCraftingContainer(width, height, items);
|
||||
return CraftingInput.of(width, height, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public interface ICondition {
|
||||
interface IContext {
|
||||
/* Key used to attach this context option to a DynamicOps instance */
|
||||
@ApiStatus.Internal
|
||||
public static ResourceLocation KEY = new ResourceLocation("forge", "condition_context");
|
||||
public static ResourceLocation KEY = ResourceLocation.fromNamespaceAndPath("forge", "condition_context");
|
||||
|
||||
IContext EMPTY = new IContext() {
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface IConditionBuilder {
|
||||
}
|
||||
|
||||
default ICondition itemExists(String namespace, String path) {
|
||||
return new ItemExistsCondition(new ResourceLocation(namespace, path));
|
||||
return new ItemExistsCondition(ResourceLocation.fromNamespaceAndPath(namespace, path));
|
||||
}
|
||||
|
||||
default ICondition modLoaded(String modid) {
|
||||
|
||||
@@ -6,18 +6,10 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.registries.RegistriesDatapackGenerator;
|
||||
import net.minecraft.data.registries.RegistryPatchGenerator;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.data.worldgen.features.OreFeatures;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -26,8 +18,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
* referencing existing dynamic registry objects within another dynamic registry
|
||||
* object.
|
||||
*/
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
{
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator {
|
||||
|
||||
private final CompletableFuture<HolderLookup.Provider> fullRegistries;
|
||||
|
||||
@@ -39,8 +30,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* @param registries a future of patched registries
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<RegistrySetBuilder.PatchedRegistries> registries, Set<String> modIds)
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<RegistrySetBuilder.PatchedRegistries> registries, Set<String> modIds) {
|
||||
super(output, registries.thenApply(RegistrySetBuilder.PatchedRegistries::patches), modIds);
|
||||
this.fullRegistries = registries.thenApply(RegistrySetBuilder.PatchedRegistries::full);
|
||||
}
|
||||
@@ -55,8 +45,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* @param registryBuilder a builder containing the dynamic registry objects added by this provider
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder registryBuilder, Set<String> modIds)
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder registryBuilder, Set<String> modIds) {
|
||||
this(output, RegistryPatchGenerator.createLookup(registries, registryBuilder), modIds);
|
||||
}
|
||||
|
||||
@@ -69,8 +58,7 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
* An example use case is the {@link TagsProvider}.
|
||||
* @return the future of the full registry lookup
|
||||
*/
|
||||
public CompletableFuture<HolderLookup.Provider> getFullRegistries()
|
||||
{
|
||||
public CompletableFuture<HolderLookup.Provider> getFullRegistries() {
|
||||
return this.fullRegistries;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class ExistingFileHelper {
|
||||
}
|
||||
|
||||
private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix) {
|
||||
return new ResourceLocation(base.getNamespace(), prefix + "/" + base.getPath() + suffix);
|
||||
return base.withPath(p -> prefix + '/' + p + suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,7 +112,7 @@ public final class ForgeBlockTagsProvider extends BlockTagsProvider
|
||||
String prefix = group.location().getPath().toUpperCase(Locale.ENGLISH) + '_';
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
|
||||
ResourceLocation key = ResourceLocation.fromNamespaceAndPath("minecraft", pattern.replace("{color}", color.getName()));
|
||||
TagKey<Block> tag = getForgeTag(prefix + color.getName());
|
||||
Block block = ForgeRegistries.BLOCKS.getValue(key);
|
||||
if (block == null || block == Blocks.AIR)
|
||||
|
||||
@@ -175,7 +175,7 @@ public final class ForgeItemTagsProvider extends ItemTagsProvider
|
||||
String prefix = group.location().getPath().toUpperCase(Locale.ENGLISH) + '_';
|
||||
for (DyeColor color : DyeColor.values())
|
||||
{
|
||||
ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
|
||||
ResourceLocation key = ResourceLocation.fromNamespaceAndPath("minecraft", pattern.replace("{color}", color.getName()));
|
||||
TagKey<Item> tag = getForgeItemTag(prefix + color.getName());
|
||||
Item item = ForgeRegistries.ITEMS.getValue(key);
|
||||
if (item == null || item == Items.AIR)
|
||||
|
||||
@@ -62,12 +62,12 @@ public final class ForgeLootTableProvider extends LootTableProvider {
|
||||
public List<LootTableProvider.SubProviderEntry> getTables() {
|
||||
return super.getTables().stream().map(entry -> {
|
||||
// Provides new sub provider with filtering only changed loot tables and replacing condition item to condition tag
|
||||
return new LootTableProvider.SubProviderEntry(() -> replaceAndFilterChangesOnly(entry.provider().get()), entry.paramSet());
|
||||
return new LootTableProvider.SubProviderEntry(provider -> replaceAndFilterChangesOnly(entry.provider().apply(provider)), entry.paramSet());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private LootTableSubProvider replaceAndFilterChangesOnly(LootTableSubProvider subProvider) {
|
||||
return (provider, newConsumer) -> subProvider.generate(provider, (resourceLocation, builder) -> {
|
||||
return (newConsumer) -> subProvider.generate((resourceLocation, builder) -> {
|
||||
if (findAndReplaceInLootTableBuilder(builder, Items.SHEARS, ToolActions.SHEARS_DIG)) {
|
||||
newConsumer.accept(resourceLocation, builder);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
}
|
||||
|
||||
private void exclude(String name) {
|
||||
excludes.add(new ResourceLocation(name));
|
||||
excludes.add(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
private void replace(ItemLike item, TagKey<Item> tag) {
|
||||
|
||||
@@ -21,6 +21,6 @@ public class ForgeSpriteSourceProvider extends SpriteSourceProvider
|
||||
@Override
|
||||
protected void addSources()
|
||||
{
|
||||
atlas(SpriteSourceProvider.BLOCKS_ATLAS).addSource(new SingleFile(new ResourceLocation("forge:white"), Optional.empty()));
|
||||
atlas(SpriteSourceProvider.BLOCKS_ATLAS).addSource(new SingleFile(ResourceLocation.parse("forge:white"), Optional.empty()));
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
/**
|
||||
* Call {@link #add} here, which will pass in the necessary information to write the jsons.
|
||||
*/
|
||||
protected abstract void start();
|
||||
protected abstract void start(HolderLookup.Provider registries);
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cache) {
|
||||
@@ -64,7 +64,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
}
|
||||
|
||||
private CompletableFuture<?> run(CachedOutput cache, HolderLookup.Provider registries) {
|
||||
start();
|
||||
start(registries);
|
||||
|
||||
Path forgePath = this.output.getOutputFolder(PackOutput.Target.DATA_PACK).resolve("forge/loot_modifiers/global_loot_modifiers.json");
|
||||
Path modifierFolderPath = this.output.getOutputFolder(PackOutput.Target.DATA_PACK).resolve(this.modid).resolve("loot_modifiers");
|
||||
@@ -78,7 +78,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider {
|
||||
|
||||
toSerialize.forEach(LamdbaExceptionUtils.rethrowBiConsumer((name, instance) -> {
|
||||
var json = codec.encodeStart(ops, instance).getOrThrow();
|
||||
entries.add(new ResourceLocation(modid, name));
|
||||
entries.add(ResourceLocation.fromNamespaceAndPath(modid, name));
|
||||
Path modifierPath = modifierFolderPath.resolve(name + ".json");
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, json, modifierPath));
|
||||
}));
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.function.Supplier;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -87,7 +88,10 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void add(Enchantment key, String name) {
|
||||
add(key.getDescriptionId(), name);
|
||||
if (!(key.description().getContents() instanceof TranslatableContents description))
|
||||
throw new IllegalArgumentException("Enchantment " + key + " does not have a translatable name");
|
||||
|
||||
add(description.getKey(), name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -114,7 +114,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected static SoundDefinition.Sound sound(final String name, final SoundDefinition.SoundType type)
|
||||
{
|
||||
return sound(new ResourceLocation(name), type);
|
||||
return sound(ResourceLocation.parse(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected static SoundDefinition.Sound sound(final String name)
|
||||
{
|
||||
return sound(new ResourceLocation(name));
|
||||
return sound(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
// Addition methods
|
||||
@@ -186,7 +186,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
*/
|
||||
protected void add(final String soundEvent, final SoundDefinition definition)
|
||||
{
|
||||
this.add(new ResourceLocation(soundEvent), definition);
|
||||
this.add(ResourceLocation.parse(soundEvent), definition);
|
||||
}
|
||||
|
||||
private void addSounds(final String soundEvent, final SoundDefinition definition)
|
||||
|
||||
@@ -27,16 +27,16 @@ import java.util.function.BiConsumer;
|
||||
*/
|
||||
public abstract class SpriteSourceProvider extends JsonCodecProvider<List<SpriteSource>>
|
||||
{
|
||||
protected static final ResourceLocation BLOCKS_ATLAS = new ResourceLocation("blocks");
|
||||
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = new ResourceLocation("banner_patterns");
|
||||
protected static final ResourceLocation BEDS_ATLAS = new ResourceLocation("beds");
|
||||
protected static final ResourceLocation CHESTS_ATLAS = new ResourceLocation("chests");
|
||||
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = new ResourceLocation("shield_patterns");
|
||||
protected static final ResourceLocation SHULKER_BOXES_ATLAS = new ResourceLocation("shulker_boxes");
|
||||
protected static final ResourceLocation SIGNS_ATLAS = new ResourceLocation("signs");
|
||||
protected static final ResourceLocation MOB_EFFECTS_ATLAS = new ResourceLocation("mob_effects");
|
||||
protected static final ResourceLocation PAINTINGS_ATLAS = new ResourceLocation("paintings");
|
||||
protected static final ResourceLocation PARTICLES_ATLAS = new ResourceLocation("particles");
|
||||
protected static final ResourceLocation BLOCKS_ATLAS = ResourceLocation.withDefaultNamespace("blocks");
|
||||
protected static final ResourceLocation BANNER_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("banner_patterns");
|
||||
protected static final ResourceLocation BEDS_ATLAS = ResourceLocation.withDefaultNamespace("beds");
|
||||
protected static final ResourceLocation CHESTS_ATLAS = ResourceLocation.withDefaultNamespace("chests");
|
||||
protected static final ResourceLocation SHIELD_PATTERNS_ATLAS = ResourceLocation.withDefaultNamespace("shield_patterns");
|
||||
protected static final ResourceLocation SHULKER_BOXES_ATLAS = ResourceLocation.withDefaultNamespace("shulker_boxes");
|
||||
protected static final ResourceLocation SIGNS_ATLAS = ResourceLocation.withDefaultNamespace("signs");
|
||||
protected static final ResourceLocation MOB_EFFECTS_ATLAS = ResourceLocation.withDefaultNamespace("mob_effects");
|
||||
protected static final ResourceLocation PAINTINGS_ATLAS = ResourceLocation.withDefaultNamespace("paintings");
|
||||
protected static final ResourceLocation PARTICLES_ATLAS = ResourceLocation.withDefaultNamespace("particles");
|
||||
|
||||
private final Map<ResourceLocation, SourceList> atlases = new HashMap<>();
|
||||
|
||||
|
||||
@@ -476,13 +476,13 @@ public interface IForgeBlock {
|
||||
* @param level The level
|
||||
* @param pos The position of this state
|
||||
* @param beaconPos The position of the beacon
|
||||
* @return A float RGB [0.0, 1.0] array to be averaged with a beacon's existing beam color, or null to do nothing to the beam
|
||||
* @return A ARGB32 color to merge info the beacon's existing beam color, or -1 to do nothing to the beam
|
||||
*/
|
||||
@Nullable
|
||||
default float[] getBeaconColorMultiplier(BlockState state, LevelReader level, BlockPos pos, BlockPos beaconPos) {
|
||||
default int getBeaconColorMultiplier(BlockState state, LevelReader level, BlockPos pos, BlockPos beaconPos) {
|
||||
if (self() instanceof BeaconBeamBlock beam)
|
||||
return beam.getColor().getTextureDiffuseColors();
|
||||
return null;
|
||||
return beam.getColor().getTextureDiffuseColor();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -397,10 +397,10 @@ public interface IForgeBlockState {
|
||||
* @param level The level
|
||||
* @param pos The position of this state
|
||||
* @param beacon The position of the beacon
|
||||
* @return A float RGB [0.0, 1.0] array to be averaged with a beacon's existing beam color, or null to do nothing to the beam
|
||||
* @return A ARGB32 color to merge info the beacon's existing beam color, or -1 to do nothing to the beam
|
||||
*/
|
||||
@Nullable
|
||||
default float[] getBeaconColorMultiplier(LevelReader level, BlockPos pos, BlockPos beacon) {
|
||||
default int getBeaconColorMultiplier(LevelReader level, BlockPos pos, BlockPos beacon) {
|
||||
return self().getBlock().getBeaconColorMultiplier(self(), level, pos, beacon);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IForgeEnchantment {
|
||||
private Enchantment self() {
|
||||
return (Enchantment)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemStack aware version of {@link Enchantment#getDamageBonus(int, MobType)}
|
||||
* @param level the level of the enchantment
|
||||
* @param mobType the mob type being attacked
|
||||
* @param enchantedItem the item used for the attack
|
||||
* @return the damage bonus
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default float getDamageBonus(int level, @Nullable EntityType<?> mobType, ItemStack enchantedItem) {
|
||||
return self().getDamageBonus(level, mobType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this enchantment allowed to be enchanted on books via Enchantment Table
|
||||
* @return false to disable the vanilla feature
|
||||
*/
|
||||
default boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This applies specifically to applying at the enchanting table. The other method {@link #canEnchant(ItemStack)}
|
||||
* applies for <i>all possible</i> enchantments.
|
||||
*/
|
||||
default boolean canApplyAtEnchantingTable(ItemStack stack) {
|
||||
return stack.canApplyAtEnchantingTable(self());
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public interface IForgeGameTestHelper {
|
||||
var server = level.getServer();
|
||||
|
||||
var listener = new ServerGamePacketListenerImpl(server, connection, player, cookie);
|
||||
var info = GameProtocols.SERVERBOUND.bind(RegistryFriendlyByteBuf.decorator(server.registryAccess()));
|
||||
var info = GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(server.registryAccess()));
|
||||
connection.setupInboundProtocol(info, listener);
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -106,14 +107,6 @@ public interface IForgeItem {
|
||||
return stack.getItem() instanceof ArmorItem && ((ArmorItem) stack.getItem()).getMaterial() == ArmorMaterials.GOLD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the amount of durability the mending enchantment
|
||||
* will repair, on average, per point of experience.
|
||||
*/
|
||||
default float getXpRepairRatio(ItemStack stack) {
|
||||
return 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before a block is broken. Return true to prevent default block
|
||||
* harvesting.
|
||||
@@ -255,12 +248,6 @@ public interface IForgeItem {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick armor in the armor slot. Override to do something
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1") // Use onInventoryTick
|
||||
default void onArmorTick(ItemStack stack, Level level, Player player){ }
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
@@ -272,8 +259,6 @@ public interface IForgeItem {
|
||||
vanillaIndex -= inv.items.size();
|
||||
if (vanillaIndex >= inv.armor.size())
|
||||
vanillaIndex -= inv.armor.size();
|
||||
else
|
||||
onArmorTick(stack, level, player);
|
||||
}
|
||||
stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex);
|
||||
}
|
||||
@@ -288,7 +273,9 @@ public interface IForgeItem {
|
||||
* @return True if the given ItemStack can be inserted in the slot
|
||||
*/
|
||||
default boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity) {
|
||||
return Mob.getEquipmentSlotForItem(stack) == armorType;
|
||||
if (entity instanceof LivingEntity living)
|
||||
return living.getEquipmentSlotForItem(stack) == armorType;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,21 +369,7 @@ public interface IForgeItem {
|
||||
* @return true if the enchantment can be applied to this item
|
||||
*/
|
||||
default boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
||||
return self().builtInRegistryHolder().is(enchantment.getSupportedItems()) && enchantment.isPrimaryItem(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level of the enchantment currently present on the stack. By default, returns the enchantment level present in NBT.
|
||||
* Most enchantment implementations rely upon this method.
|
||||
* For consistency, results of this method should be the same as getting the enchantment from {@link #getAllEnchantments(ItemStack)}
|
||||
*
|
||||
* @param stack the item stack being checked
|
||||
* @param enchantment the enchantment being checked for
|
||||
* @return Level of the enchantment, or 0 if not present
|
||||
* @see #getAllEnchantments(ItemStack)
|
||||
*/
|
||||
default int getEnchantmentLevel(ItemStack stack, Enchantment enchantment) {
|
||||
return EnchantmentHelper.getEnchantmentsForCrafting(stack).getLevel(enchantment);
|
||||
return enchantment.isPrimaryItem(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,22 +137,6 @@ public interface IForgeItemStack {
|
||||
return self().getItem().canApplyAtEnchantingTable(self(), enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level of the enchantment currently present on the stack. By default, returns the enchantment level present in NBT.
|
||||
*
|
||||
* Equivalent to calling {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getItemEnchantmentLevel(Enchantment, ItemStack)}
|
||||
* Use in place of {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)} for checking presence of an enchantment in logic implementing the enchantment behavior.
|
||||
* Use {@link net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)} instead when modifying an item's enchantments.
|
||||
*
|
||||
* @param enchantment the enchantment being checked for
|
||||
* @return Level of the enchantment, or 0 if not present
|
||||
* @see #getAllEnchantments()
|
||||
* @see net.minecraft.world.item.enchantment.EnchantmentHelper#getTagEnchantmentLevel(Enchantment, ItemStack)
|
||||
*/
|
||||
default int getEnchantmentLevel(Enchantment enchantment) {
|
||||
return self().getItem().getEnchantmentLevel(self(), enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemStack sensitive version of {@link Item#getEnchantmentValue()}.
|
||||
*
|
||||
@@ -231,14 +215,6 @@ public interface IForgeItemStack {
|
||||
return self().getItem().onEntityItemUpdate(self(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the amount of durability the mending enchantment
|
||||
* will repair, on average, per point of experience.
|
||||
*/
|
||||
default float getXpRepairRatio() {
|
||||
return self().getItem().getXpRepairRatio(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagBuilder;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
@@ -16,12 +14,6 @@ public interface IForgeRawTagBuilder {
|
||||
return (TagBuilder) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Never used, tags use a Codec now, so remove this later.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
default void serializeTagAdditions(final JsonObject tagJson) {}
|
||||
|
||||
/**
|
||||
* Adds a tag entry to the remove list.
|
||||
* @param tagEntry The tag entry to add to the remove list
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.function.Function;
|
||||
public interface IGlobalLootModifier {
|
||||
Codec<IGlobalLootModifier> DIRECT_CODEC = Codec.lazyInitialized(() -> ForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS.get().getCodec().dispatch(IGlobalLootModifier::codec, Function.identity()));
|
||||
|
||||
Codec<LootItemCondition[]> LOOT_CONDITIONS_CODEC = LootItemConditions.DIRECT_CODEC.listOf().xmap(list -> list.toArray(LootItemCondition[]::new), List::of);
|
||||
Codec<LootItemCondition[]> LOOT_CONDITIONS_CODEC = LootItemCondition.DIRECT_CODEC.listOf().xmap(list -> list.toArray(LootItemCondition[]::new), List::of);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <U> JsonElement getJson(Dynamic<?> dynamic) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
|
||||
@Override
|
||||
protected Map<ResourceLocation, JsonElement> prepare(ResourceManager resources, ProfilerFiller profilerFiller) {
|
||||
var path = new ResourceLocation("forge", FOLDER + "/global_loot_modifiers.json");
|
||||
var path = ResourceLocation.fromNamespaceAndPath("forge", FOLDER + "/global_loot_modifiers.json");
|
||||
|
||||
List<ResourceLocation> toLoad = new ArrayList<>();
|
||||
//read in all data files from forge:loot_modifiers/global_loot_modifiers in order to do layering
|
||||
@@ -50,7 +50,7 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
toLoad.clear();
|
||||
|
||||
for(var entry : GsonHelper.getAsJsonArray(json, "entries")) {
|
||||
ResourceLocation loc = new ResourceLocation(entry.getAsString());
|
||||
ResourceLocation loc = ResourceLocation.parse(entry.getAsString());
|
||||
toLoad.remove(loc); //remove and re-add if needed, to update the ordering.
|
||||
toLoad.add(loc);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public record LootTableIdCondition(ResourceLocation id) implements LootItemCondi
|
||||
|
||||
// TODO Forge Registry at some point?
|
||||
public static final LootItemConditionType TYPE = new LootItemConditionType(CODEC);
|
||||
public static final ResourceLocation UNKNOWN_LOOT_TABLE = new ResourceLocation("forge", "unknown_loot_table");
|
||||
public static final ResourceLocation UNKNOWN_LOOT_TABLE = ResourceLocation.fromNamespaceAndPath("forge", "unknown_loot_table");
|
||||
|
||||
@Override
|
||||
public LootItemConditionType getType() {
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.portal.PortalInfo;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.level.portal.PortalForcer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface for handling the placement of entities during dimension change.
|
||||
* <p>
|
||||
* An implementation of this interface can be used to place the entity
|
||||
* in a safe location, or generate a return portal, for instance.
|
||||
* <p>
|
||||
* See the {@link PortalForcer} class, which has
|
||||
* been patched to implement this interface, for a vanilla example.
|
||||
*/
|
||||
public interface ITeleporter
|
||||
{
|
||||
/**
|
||||
* Called to handle placing the entity in the new world.
|
||||
* <p>
|
||||
* The initial position of the entity will be its
|
||||
* position in the origin world, multiplied horizontally
|
||||
* by the computed cross-dimensional movement factor.
|
||||
* <p>
|
||||
* Note that the supplied entity has not yet been spawned
|
||||
* in the destination world at the time.
|
||||
*
|
||||
* @param entity the entity to be placed
|
||||
* @param currentWorld the entity's origin
|
||||
* @param destWorld the entity's destination
|
||||
* @param yaw the suggested yaw value to apply
|
||||
* @param repositionEntity a function to reposition the entity, which returns the new entity in the new dimension. This is the vanilla implementation of the dimension travel logic. If the supplied boolean is true, it is attempted to spawn a new portal.
|
||||
*
|
||||
* @return the entity in the new World. Vanilla creates for most {@link Entity}s a new instance and copy the data. But <b>you are not allowed</b> to create a new instance for {@link Player}s! Move the player and update its state, see {@link ServerPlayer#changeDimension(ServerLevel, ITeleporter)}
|
||||
*/
|
||||
default Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
|
||||
{
|
||||
return repositionEntity.apply(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PortalInfo. defaultPortalInfo references the
|
||||
* vanilla code and should not be used for your purposes.
|
||||
* Override this method to handle your own logic.
|
||||
* <p>
|
||||
* Return {@code null} to prevent teleporting.
|
||||
*
|
||||
* @param entity The entity teleporting before the teleport
|
||||
* @param destWorld The world the entity is teleporting to
|
||||
* @param defaultPortalInfo A reference to the vanilla method for getting portal info. You should implement your own logic instead of using this
|
||||
*
|
||||
* @return The location, rotation, and motion of the entity in the destWorld after the teleport
|
||||
*/
|
||||
@Nullable
|
||||
default PortalInfo getPortalInfo(Entity entity, ServerLevel destWorld, Function<ServerLevel, PortalInfo> defaultPortalInfo)
|
||||
{
|
||||
return this.isVanilla() ? defaultPortalInfo.apply(destWorld) : new PortalInfo(entity.position(), Vec3.ZERO, entity.getYRot(), entity.getXRot());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this teleporter the vanilla instance.
|
||||
*/
|
||||
default boolean isVanilla()
|
||||
{
|
||||
return this.getClass() == PortalForcer.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when vanilla wants to play the portal sound after teleporting. Return true to play the vanilla sound.
|
||||
* @param player the player
|
||||
* @param sourceWorld the source world
|
||||
* @param destWorld the target world
|
||||
* @return true to play the vanilla sound
|
||||
*/
|
||||
default boolean playTeleportSound(ServerPlayer player, ServerLevel sourceWorld, ServerLevel destWorld)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.entity;
|
||||
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.server.level.ServerEntity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
|
||||
@@ -22,7 +23,7 @@ public abstract class PartEntity<T extends Entity> extends Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket(ServerEntity p_344981_) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,7 @@ import net.minecraftforge.event.entity.living.LivingHealEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSwapItemsEvent;
|
||||
import net.minecraftforge.event.entity.living.LootingLevelEvent;
|
||||
import net.minecraftforge.event.entity.living.MobEffectEvent;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent;
|
||||
import net.minecraftforge.event.entity.living.MobSpawnEvent.AllowDespawn;
|
||||
@@ -798,14 +799,6 @@ public final class ForgeEventFactory {
|
||||
post(new PlayerEvent.ItemSmeltedEvent(player, smelted));
|
||||
}
|
||||
|
||||
public static void onRenderTickStart(float timer) {
|
||||
post(new TickEvent.RenderTickEvent(TickEvent.Phase.START, timer));
|
||||
}
|
||||
|
||||
public static void onRenderTickEnd(float timer) {
|
||||
post(new TickEvent.RenderTickEvent(TickEvent.Phase.END, timer));
|
||||
}
|
||||
|
||||
public static void onPlayerPreTick(Player player) {
|
||||
post(new TickEvent.PlayerTickEvent(TickEvent.Phase.START, player));
|
||||
}
|
||||
@@ -954,8 +947,8 @@ public final class ForgeEventFactory {
|
||||
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 boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, boolean recentlyHit) {
|
||||
return post(new LivingDropsEvent(entity, source, drops, recentlyHit));
|
||||
}
|
||||
|
||||
public static void onLeftClickEmpty(Player player) {
|
||||
@@ -1094,4 +1087,8 @@ public final class ForgeEventFactory {
|
||||
public static GatherComponentsEvent.Item gatherItemComponentsEvent(Item item, DataComponentMap dataComponents) {
|
||||
return fire(new GatherComponentsEvent.Item(item, dataComponents));
|
||||
}
|
||||
|
||||
public static LootingLevelEvent fireLootingLevel(LivingEntity target, @Nullable DamageSource cause, int level) {
|
||||
return fire(new LootingLevelEvent(target, cause, level));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -54,7 +55,7 @@ public class TickEvent extends Event
|
||||
{
|
||||
return this.haveTime.getAsBoolean();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@return the server instance}
|
||||
*/
|
||||
@@ -105,11 +106,27 @@ public class TickEvent extends Event
|
||||
}
|
||||
|
||||
public static class RenderTickEvent extends TickEvent {
|
||||
public final float renderTickTime;
|
||||
public RenderTickEvent(Phase phase, float renderTickTime)
|
||||
{
|
||||
private final DeltaTracker timer;
|
||||
|
||||
private RenderTickEvent(Phase phase, DeltaTracker timer) {
|
||||
super(Type.RENDER, LogicalSide.CLIENT, phase);
|
||||
this.renderTickTime = renderTickTime;
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public DeltaTracker getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
public static class Start extends RenderTickEvent {
|
||||
public Start(DeltaTracker timer) {
|
||||
super(Phase.START, timer);
|
||||
}
|
||||
}
|
||||
|
||||
public static class End extends RenderTickEvent {
|
||||
public End(DeltaTracker timer) {
|
||||
super(Phase.END, timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,39 +34,27 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public class LivingDropsEvent extends LivingEvent
|
||||
{
|
||||
public class LivingDropsEvent extends LivingEvent {
|
||||
private final DamageSource source;
|
||||
private final Collection<ItemEntity> drops;
|
||||
private final int lootingLevel;
|
||||
private final boolean recentlyHit;
|
||||
|
||||
public LivingDropsEvent(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit)
|
||||
{
|
||||
public LivingDropsEvent(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, boolean recentlyHit) {
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.drops = drops;
|
||||
this.lootingLevel = lootingLevel;
|
||||
this.recentlyHit = recentlyHit;
|
||||
}
|
||||
|
||||
public DamageSource getSource()
|
||||
{
|
||||
public DamageSource getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public Collection<ItemEntity> getDrops()
|
||||
{
|
||||
public Collection<ItemEntity> getDrops() {
|
||||
return drops;
|
||||
}
|
||||
|
||||
public int getLootingLevel()
|
||||
{
|
||||
return lootingLevel;
|
||||
}
|
||||
|
||||
public boolean isRecentlyHit()
|
||||
{
|
||||
public boolean isRecentlyHit() {
|
||||
return recentlyHit;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ package net.minecraftforge.event.level;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.block.BaseFireBlock;
|
||||
import net.minecraft.world.level.portal.PortalShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -73,8 +75,10 @@ public class BlockEvent extends Event {
|
||||
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) { // Handle empty block or player unable to break block scenario
|
||||
this.exp = 0;
|
||||
} else {
|
||||
int fortuneLevel = player.getMainHandItem().getEnchantmentLevel(Enchantments.FORTUNE);
|
||||
int silkTouchLevel = player.getMainHandItem().getEnchantmentLevel(Enchantments.SILK_TOUCH);
|
||||
var lookup = level.registryAccess().lookup(Registries.ENCHANTMENT).get();
|
||||
|
||||
int fortuneLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.FORTUNE), player.getMainHandItem());
|
||||
int silkTouchLevel = EnchantmentHelper.getItemEnchantmentLevel(lookup.getOrThrow(Enchantments.SILK_TOUCH), player.getMainHandItem());
|
||||
this.exp = state.getExpDrop(level, level.random, pos, fortuneLevel, silkTouchLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,10 @@ public class DispenseFluidContainer extends DefaultDispenseItemBehavior {
|
||||
|
||||
if (stack.getCount() == 1)
|
||||
return resultStack;
|
||||
else if (((DispenserBlockEntity)source.blockEntity()).addItem(resultStack) < 0)
|
||||
|
||||
source.blockEntity().insertItem(resultStack);
|
||||
|
||||
if (!resultStack.isEmpty())
|
||||
this.dispenseBehavior.dispense(source, resultStack);
|
||||
|
||||
ItemStack stackCopy = stack.copy();
|
||||
@@ -87,8 +90,11 @@ public class DispenseFluidContainer extends DefaultDispenseItemBehavior {
|
||||
|
||||
if (drainedStack.getCount() == 1)
|
||||
return drainedStack;
|
||||
else if (!drainedStack.isEmpty() && ((DispenserBlockEntity)source.blockEntity()).addItem(drainedStack) < 0)
|
||||
|
||||
if (!drainedStack.isEmpty()) {
|
||||
source.blockEntity().insertItem(drainedStack);
|
||||
this.dispenseBehavior.dispense(source, drainedStack);
|
||||
}
|
||||
|
||||
ItemStack stackCopy = drainedStack.copy();
|
||||
stackCopy.shrink(1);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class FluidStack
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
ResourceLocation fluidName = new ResourceLocation(nbt.getString("FluidName"));
|
||||
ResourceLocation fluidName = ResourceLocation.parse(nbt.getString("FluidName"));
|
||||
Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
|
||||
if (fluid == null)
|
||||
{
|
||||
|
||||
@@ -14,10 +14,10 @@ import net.minecraftforge.items.IItemHandler;
|
||||
* Exposes the armor inventory of an {@link LivingEntity} as an {@link IItemHandler} using {@link LivingEntity#getItemBySlot(EquipmentSlot)} and
|
||||
* {@link LivingEntity#setItemSlot(EquipmentSlot, ItemStack)}.
|
||||
*/
|
||||
public class EntityArmorInvWrapper extends EntityEquipmentInvWrapper
|
||||
{
|
||||
public EntityArmorInvWrapper(final LivingEntity entity)
|
||||
{
|
||||
super(entity, EquipmentSlot.Type.ARMOR);
|
||||
public class EntityArmorInvWrapper extends EntityEquipmentInvWrapper {
|
||||
public EntityArmorInvWrapper(final LivingEntity entity) {
|
||||
// some entities may not support setting values in this slot, but we never cared about that before so don't care now.
|
||||
// Modders should implement their own inventory wrappers.
|
||||
super(entity, EquipmentSlot.Type.HUMANOID_ARMOR, EquipmentSlot.Type.ANIMAL_ARMOR);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@ import java.util.List;
|
||||
* Exposes the armor or hands inventory of an {@link LivingEntity} as an {@link IItemHandler} using {@link LivingEntity#getItemBySlot(EquipmentSlot)} and
|
||||
* {@link LivingEntity#setItemSlot(EquipmentSlot, ItemStack)}.
|
||||
*/
|
||||
public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiable
|
||||
{
|
||||
public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiable {
|
||||
/**
|
||||
* The entity.
|
||||
*/
|
||||
@@ -37,17 +36,25 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
* @param entity The entity.
|
||||
* @param slotType The slot type to expose.
|
||||
*/
|
||||
public EntityEquipmentInvWrapper(final LivingEntity entity, final EquipmentSlot.Type slotType)
|
||||
{
|
||||
public EntityEquipmentInvWrapper(final LivingEntity entity, final EquipmentSlot.Type mainType) {
|
||||
this(entity, mainType, (EquipmentSlot.Type[])null);
|
||||
}
|
||||
|
||||
public EntityEquipmentInvWrapper(final LivingEntity entity, final EquipmentSlot.Type mainType, final EquipmentSlot.Type... types) {
|
||||
this.entity = entity;
|
||||
|
||||
final List<EquipmentSlot> slots = new ArrayList<EquipmentSlot>();
|
||||
var slots = new ArrayList<EquipmentSlot>();
|
||||
|
||||
for (final EquipmentSlot slot : EquipmentSlot.values())
|
||||
{
|
||||
if (slot.getType() == slotType)
|
||||
{
|
||||
for (var slot : EquipmentSlot.values()) {
|
||||
if (slot.getType() == mainType)
|
||||
slots.add(slot);
|
||||
else if (types != null && types.length > 0) {
|
||||
for (var type : types) {
|
||||
if (slot.getType() == type) {
|
||||
slots.add(slot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,22 +62,19 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
public int getSlots() {
|
||||
return slots.size();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int slot)
|
||||
{
|
||||
public ItemStack getStackInSlot(final int slot) {
|
||||
return entity.getItemBySlot(validateSlotIndex(slot));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack insertItem(final int slot, @NotNull final ItemStack stack, final boolean simulate)
|
||||
{
|
||||
public ItemStack insertItem(final int slot, @NotNull final ItemStack stack, final boolean simulate) {
|
||||
if (stack.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
@@ -80,8 +84,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
|
||||
int limit = getStackLimit(slot, stack);
|
||||
|
||||
if (!existing.isEmpty())
|
||||
{
|
||||
if (!existing.isEmpty()) {
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
|
||||
return stack;
|
||||
|
||||
@@ -93,16 +96,11 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
|
||||
boolean reachedLimit = stack.getCount() > limit;
|
||||
|
||||
if (!simulate)
|
||||
{
|
||||
if (!simulate) {
|
||||
if (existing.isEmpty())
|
||||
{
|
||||
entity.setItemSlot(equipmentSlot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.grow(reachedLimit ? limit : stack.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
|
||||
@@ -110,8 +108,7 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack extractItem(final int slot, final int amount, final boolean simulate)
|
||||
{
|
||||
public ItemStack extractItem(final int slot, final int amount, final boolean simulate) {
|
||||
if (amount == 0)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
@@ -124,41 +121,31 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
|
||||
final int toExtract = Math.min(amount, existing.getMaxStackSize());
|
||||
|
||||
if (existing.getCount() <= toExtract)
|
||||
{
|
||||
if (existing.getCount() <= toExtract) {
|
||||
if (!simulate)
|
||||
{
|
||||
entity.setItemSlot(equipmentSlot, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
return existing;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (!simulate)
|
||||
{
|
||||
entity.setItemSlot(equipmentSlot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(final int slot)
|
||||
{
|
||||
public int getSlotLimit(final int slot) {
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
return equipmentSlot.getType() == EquipmentSlot.Type.ARMOR ? 1 : 64;
|
||||
return (equipmentSlot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR || equipmentSlot.getType() == EquipmentSlot.Type.ANIMAL_ARMOR) ? 1 : 64;
|
||||
}
|
||||
|
||||
protected int getStackLimit(final int slot, @NotNull final ItemStack stack)
|
||||
{
|
||||
protected int getStackLimit(final int slot, @NotNull final ItemStack stack) {
|
||||
return Math.min(getSlotLimit(slot), stack.getMaxStackSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(final int slot, @NotNull final ItemStack stack)
|
||||
{
|
||||
public void setStackInSlot(final int slot, @NotNull final ItemStack stack) {
|
||||
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
|
||||
if (ItemStack.matches(entity.getItemBySlot(equipmentSlot), stack))
|
||||
return;
|
||||
@@ -166,23 +153,21 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, @NotNull ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected EquipmentSlot validateSlotIndex(final int slot)
|
||||
{
|
||||
protected EquipmentSlot validateSlotIndex(final int slot) {
|
||||
if (slot < 0 || slot >= slots.size())
|
||||
throw new IllegalArgumentException("Slot " + slot + " not in valid range - [0," + slots.size() + ")");
|
||||
|
||||
return slots.get(slot);
|
||||
}
|
||||
|
||||
public static LazyOptional<IItemHandlerModifiable>[] create(LivingEntity entity)
|
||||
{
|
||||
public static LazyOptional<IItemHandlerModifiable>[] create(LivingEntity entity) {
|
||||
@SuppressWarnings("unchecked")
|
||||
LazyOptional<IItemHandlerModifiable>[] ret = new LazyOptional[3];
|
||||
|
||||
ret[0] = LazyOptional.of(() -> new EntityHandsInvWrapper(entity));
|
||||
ret[1] = LazyOptional.of(() -> new EntityArmorInvWrapper(entity));
|
||||
ret[2] = LazyOptional.of(() -> new CombinedInvWrapper(ret[0].orElse(null), ret[1].orElse(null)));
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PlayerArmorInvWrapper extends RangedWrapper
|
||||
EquipmentSlot equ = null;
|
||||
for (EquipmentSlot s : EquipmentSlot.values())
|
||||
{
|
||||
if (s.getType() == EquipmentSlot.Type.ARMOR && s.getIndex() == slot)
|
||||
if (s.getType() == EquipmentSlot.Type.HUMANOID_ARMOR && s.getIndex() == slot)
|
||||
{
|
||||
equ = s;
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.logging;
|
||||
import cpw.mods.modlauncher.log.TransformingThrowablePatternConverter;
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.CrashReportCategory;
|
||||
import net.minecraft.ReportType;
|
||||
import net.minecraft.SystemReport;
|
||||
import net.minecraftforge.fml.CrashReportCallables;
|
||||
import net.minecraftforge.fml.ISystemReportExtender;
|
||||
@@ -65,12 +66,12 @@ public class CrashReportExtender {
|
||||
});
|
||||
final File file1 = new File(topLevelDir, "crash-reports");
|
||||
final File file2 = new File(file1, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-fml.txt");
|
||||
if (crashReport.saveToFile(file2)) {
|
||||
if (crashReport.saveToFile(file2.toPath(), ReportType.CRASH)) {
|
||||
logger.fatal("Crash report saved to {}", file2);
|
||||
} else {
|
||||
logger.fatal("Failed to save crash report");
|
||||
}
|
||||
System.out.print(crashReport.getFriendlyReport());
|
||||
System.out.print(crashReport.getFriendlyReport(ReportType.CRASH));
|
||||
return file2;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class ChannelBuilder {
|
||||
* @param channelName The name of the channel
|
||||
*/
|
||||
public static ChannelBuilder named(String channelName) {
|
||||
return named(new ResourceLocation(channelName));
|
||||
return named(ResourceLocation.parse(channelName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.List;
|
||||
public class ChannelListManager {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public static final ResourceLocation NAME = new ResourceLocation("forge", "channel_registration");
|
||||
public static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "channel_registration");
|
||||
|
||||
static final Channel<CustomPacketPayload> CHANNEL = ChannelBuilder
|
||||
.named(NAME)
|
||||
@@ -44,7 +44,7 @@ public class ChannelListManager {
|
||||
.build();
|
||||
|
||||
private record Register(List<String> channels) implements CustomPacketPayload {
|
||||
private static Type<Register> TYPE = CustomPacketPayload.createType("minecraft:register");
|
||||
private static Type<Register> TYPE = CustomPacketPayload.createType("register");
|
||||
private static StreamCodec<FriendlyByteBuf, Register> CODEC = StreamCodec.of(
|
||||
(buf, v) -> encode(buf, v.channels),
|
||||
buf -> new Register(decode(buf))
|
||||
@@ -57,7 +57,7 @@ public class ChannelListManager {
|
||||
}
|
||||
|
||||
private record Unregister(List<String> channels) implements CustomPacketPayload {
|
||||
private static Type<Unregister> TYPE = CustomPacketPayload.createType("minecraft:unregister");
|
||||
private static Type<Unregister> TYPE = CustomPacketPayload.createType("unregister");
|
||||
private static StreamCodec<FriendlyByteBuf, Unregister> CODEC = StreamCodec.of(
|
||||
(buf, v) -> encode(buf, v.channels),
|
||||
buf -> new Unregister(decode(buf))
|
||||
@@ -153,7 +153,7 @@ public class ChannelListManager {
|
||||
continue;
|
||||
|
||||
try {
|
||||
changed.add(new ResourceLocation(channel));
|
||||
changed.add(ResourceLocation.parse(channel));
|
||||
} catch (ResourceLocationException ex) {
|
||||
// Vanilla packet deserializers now force this to be a resource location, so we should never get this, but just in case.
|
||||
LOGGER.warn("Invalid channel name received: {}. Ignoring", channel);
|
||||
|
||||
Loaded 100 of 941 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user