mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +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() {
|
||||
|
||||
Reference in new issue
Block a user