diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GogglesModel.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GogglesModel.java index 0702465f7..9ba2b63dd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GogglesModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GogglesModel.java @@ -2,12 +2,12 @@ package com.simibubi.create.content.contraptions.goggles; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.block.render.WrappedBakedModel; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; +import net.minecraftforge.client.model.BakedModelWrapper; -public class GogglesModel extends WrappedBakedModel { +public class GogglesModel extends BakedModelWrapper { public GogglesModel(IBakedModel template) { super(template); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java index cde75cafc..668cbad48 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltModel.java @@ -3,12 +3,12 @@ package com.simibubi.create.content.contraptions.relays.belt; import static com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CASING_PROPERTY; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Random; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity.CasingType; +import com.simibubi.create.foundation.block.render.QuadHelper; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -30,14 +30,16 @@ public class BeltModel extends BakedModelWrapper { @Override public List getQuads(BlockState state, Direction side, Random rand, IModelData extraData) { - List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData)); + List quads = super.getQuads(state, side, rand, extraData); if (!extraData.hasProperty(CASING_PROPERTY)) return quads; CasingType type = extraData.getData(CASING_PROPERTY); if (type == CasingType.NONE || type == CasingType.BRASS) return quads; + quads = new ArrayList<>(quads); SpriteShiftEntry spriteShift = AllSpriteShifts.ANDESIDE_BELT_CASING; + VertexFormat format = DefaultVertexFormats.BLOCK; for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); @@ -48,10 +50,7 @@ public class BeltModel extends BakedModelWrapper { TextureAtlasSprite original = quad.getSprite(); TextureAtlasSprite target = spriteShift.getTarget(); - BakedQuad newQuad = new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), - quad.getTintIndex(), quad.getFace(), target, quad.hasShade()); - - VertexFormat format = DefaultVertexFormats.BLOCK; + BakedQuad newQuad = QuadHelper.clone(quad); int[] vertexData = newQuad.getVertexData(); for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { @@ -61,9 +60,9 @@ public class BeltModel extends BakedModelWrapper { float u = Float.intBitsToFloat(vertexData[uIndex]); float v = Float.intBitsToFloat(vertexData[vIndex]); vertexData[uIndex] = - Float.floatToRawIntBits(target.getInterpolatedU((SuperByteBuffer.getUnInterpolatedU(original, u)))); + Float.floatToRawIntBits(target.getInterpolatedU(SuperByteBuffer.getUnInterpolatedU(original, u))); vertexData[vIndex] = - Float.floatToRawIntBits(target.getInterpolatedV((SuperByteBuffer.getUnInterpolatedV(original, v)))); + Float.floatToRawIntBits(target.getInterpolatedV(SuperByteBuffer.getUnInterpolatedV(original, v))); } quads.set(i, newQuad); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 1624eb195..6280c7bb7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -495,7 +495,7 @@ public class BeltTileEntity extends KineticTileEntity implements LightUpdateList return empty; } - public static ModelProperty CASING_PROPERTY = new ModelProperty<>(); + public static final ModelProperty CASING_PROPERTY = new ModelProperty<>(); @Override public IModelData getModelData() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java index b0d587c34..28b3c46a6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import com.simibubi.create.foundation.block.render.WrappedBakedModel; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.VirtualEmptyModelData; @@ -15,11 +14,12 @@ import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockDisplayReader; +import net.minecraftforge.client.model.BakedModelWrapper; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelProperty; -public class BracketedKineticBlockModel extends WrappedBakedModel { +public class BracketedKineticBlockModel extends BakedModelWrapper { private static ModelProperty BRACKET_PROPERTY = new ModelProperty<>(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java index 8a9e75a53..bde917413 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java @@ -7,22 +7,23 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollVal import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.item.ItemStack; import net.minecraft.util.math.vector.Vector3f; public class WrenchItemRenderer extends CustomRenderedItemModelRenderer { @Override - protected void render(ItemStack stack, WrenchModel model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { - renderer.render(model.getBakedModel(), light); + protected void render(ItemStack stack, WrenchModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + renderer.render(model.getOriginalModel(), light); float xOffset = -1/16f; ms.translate(-xOffset, 0, 0); ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(ScrollValueHandler.getScroll(AnimationTickHolder.getPartialTicks()))); ms.translate(xOffset, 0, 0); - + renderer.render(model.getPartial("gear"), light); } - + } diff --git a/src/main/java/com/simibubi/create/content/curiosities/symmetry/client/SymmetryWandItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/symmetry/client/SymmetryWandItemRenderer.java index 69e68f142..51cd757ba 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/symmetry/client/SymmetryWandItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/symmetry/client/SymmetryWandItemRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3f; @@ -13,21 +14,21 @@ import net.minecraft.util.math.vector.Vector3f; public class SymmetryWandItemRenderer extends CustomRenderedItemModelRenderer { @Override - protected void render(ItemStack stack, SymmetryWandModel model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { + protected void render(ItemStack stack, SymmetryWandModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { float worldTime = AnimationTickHolder.getRenderTime() / 20; int maxLight = 0xF000F0; - renderer.render(model.getBakedModel(), light); + renderer.render(model.getOriginalModel(), light); renderer.renderSolidGlowing(model.getPartial("core"), maxLight); renderer.renderGlowing(model.getPartial("core_glow"), maxLight); float floating = MathHelper.sin(worldTime) * .05f; float angle = worldTime * -10 % 360; - + ms.translate(0, floating, 0); ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle)); - + renderer.renderGlowing(model.getPartial("bits"), maxLight); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/DeforesterItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/DeforesterItemRenderer.java index 46712178b..6e8d3fcfd 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/DeforesterItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/DeforesterItemRenderer.java @@ -6,25 +6,25 @@ import com.simibubi.create.foundation.item.PartialItemModelRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.item.ItemStack; import net.minecraft.util.math.vector.Vector3f; public class DeforesterItemRenderer extends CustomRenderedItemModelRenderer { @Override - protected void render(ItemStack stack, DeforesterModel model, PartialItemModelRenderer renderer, + protected void render(ItemStack stack, DeforesterModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { int maxLight = 0xF000F0; float worldTime = AnimationTickHolder.getRenderTime(); - - renderer.renderSolid(model.getBakedModel(), light); + + renderer.renderSolid(model.getOriginalModel(), light); renderer.renderSolidGlowing(model.getPartial("core"), maxLight); renderer.renderGlowing(model.getPartial("core_glow"), maxLight); - + float angle = worldTime * -.5f % 360; ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle)); renderer.renderSolid(model.getPartial("gear"), light); } - } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java index 2f09786c6..2869afcea 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java @@ -19,13 +19,12 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer extends CustomRenderedItemModelRenderer { @Override - protected void render(ItemStack stack, M model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { + protected void render(ItemStack stack, M model, PartialItemModelRenderer renderer, TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { // Block indicator - if (model.getCurrentPerspective() == TransformType.GUI && stack.hasTag() && stack.getTag() + if (transformType == TransformType.GUI && stack.hasTag() && stack.getTag() .contains("BlockUsed")) renderBlockUsed(stack, ms, buffer, light, overlay); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java index e59924335..7f4f11104 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java @@ -20,6 +20,7 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.item.ItemStack; import net.minecraft.util.HandSide; import net.minecraft.util.math.MathHelper; @@ -28,14 +29,14 @@ import net.minecraft.util.math.vector.Vector3f; public class BlockzapperItemRenderer extends ZapperItemRenderer { @Override - protected void render(ItemStack stack, BlockzapperModel model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { - super.render(stack, model, renderer, ms, buffer, light, overlay); + protected void render(ItemStack stack, BlockzapperModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + super.render(stack, model, renderer, transformType, ms, buffer, light, overlay); float pt = AnimationTickHolder.getPartialTicks(); float worldTime = AnimationTickHolder.getRenderTime() / 20; - renderer.render(model.getBakedModel(), light); + renderer.render(model.getOriginalModel(), light); renderComponent(stack, model, Body, renderer, light); renderComponent(stack, model, Amplifier, renderer, light); renderComponent(stack, model, Retriever, renderer, light); diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItemRenderer.java index 88b5e5c86..9c2369935 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperItemRenderer.java @@ -12,6 +12,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.item.ItemStack; import net.minecraft.util.HandSide; import net.minecraft.util.math.MathHelper; @@ -20,14 +21,14 @@ import net.minecraft.util.math.vector.Vector3f; public class WorldshaperItemRenderer extends ZapperItemRenderer { @Override - protected void render(ItemStack stack, WorldshaperModel model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { - super.render(stack, model, renderer, ms, buffer, light, overlay); + protected void render(ItemStack stack, WorldshaperModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + super.render(stack, model, renderer, transformType, ms, buffer, light, overlay); float pt = AnimationTickHolder.getPartialTicks(); float worldTime = AnimationTickHolder.getRenderTime() / 20; - renderer.renderSolid(model.getBakedModel(), light); + renderer.renderSolid(model.getOriginalModel(), light); ClientPlayerEntity player = Minecraft.getInstance().player; boolean leftHanded = player.getPrimaryHand() == HandSide.LEFT; diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java index cc2430a0c..3ed787c7e 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Random; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext; +import com.simibubi.create.foundation.block.render.QuadHelper; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; @@ -23,7 +24,7 @@ import net.minecraftforge.client.model.data.ModelProperty; public class CTModel extends BakedModelWrapperWithData { - protected static ModelProperty CT_PROPERTY = new ModelProperty<>(); + protected static final ModelProperty CT_PROPERTY = new ModelProperty<>(); private ConnectedTextureBehaviour behaviour; private class CTData { @@ -42,7 +43,7 @@ public class CTModel extends BakedModelWrapperWithData { return indices[face.getIndex()]; } } - + public CTModel(IBakedModel originalModel, ConnectedTextureBehaviour behaviour) { super(originalModel); this.behaviour = behaviour; @@ -69,10 +70,13 @@ public class CTModel extends BakedModelWrapperWithData { @Override public List getQuads(BlockState state, Direction side, Random rand, IModelData extraData) { - List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData)); + List quads = super.getQuads(state, side, rand, extraData); if (!extraData.hasProperty(CT_PROPERTY)) return quads; CTData data = extraData.getData(CT_PROPERTY); + quads = new ArrayList<>(quads); + + VertexFormat format = DefaultVertexFormats.BLOCK; for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); @@ -86,9 +90,7 @@ public class CTModel extends BakedModelWrapperWithData { if (index == -1) continue; - BakedQuad newQuad = new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), - quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.hasShade()); - VertexFormat format = DefaultVertexFormats.BLOCK; + BakedQuad newQuad = QuadHelper.clone(quad); int[] vertexData = newQuad.getVertexData(); for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { @@ -100,6 +102,7 @@ public class CTModel extends BakedModelWrapperWithData { vertexData[uIndex] = Float.floatToRawIntBits(spriteShift.getTargetU(u, index)); vertexData[vIndex] = Float.floatToRawIntBits(spriteShift.getTargetV(v, index)); } + quads.set(i, newQuad); } return quads; diff --git a/src/main/java/com/simibubi/create/foundation/block/render/BakedModelBuiltInRenderer.java b/src/main/java/com/simibubi/create/foundation/block/render/BakedModelBuiltInRenderer.java deleted file mode 100644 index c995c35f5..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/render/BakedModelBuiltInRenderer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.simibubi.create.foundation.block.render; - -import net.minecraft.client.renderer.model.IBakedModel; - -public class BakedModelBuiltInRenderer extends WrappedBakedModel { - - public BakedModelBuiltInRenderer(IBakedModel template) { - super(template); - } - - @Override - public boolean isBuiltInRenderer() { - return true; - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java b/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java index b220ac0a1..c860bb29e 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.block.render; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Random; @@ -23,8 +22,8 @@ import net.minecraftforge.client.model.data.ModelProperty; public class ColoredVertexModel extends BakedModelWrapper { + private static final ModelProperty POSITION_PROPERTY = new ModelProperty<>(); private IBlockVertexColor color; - private static ModelProperty POSITION_PROPERTY = new ModelProperty<>(); public ColoredVertexModel(IBakedModel originalModel, IBlockVertexColor color) { super(originalModel); @@ -38,27 +37,28 @@ public class ColoredVertexModel extends BakedModelWrapper { @Override public List getQuads(BlockState state, Direction side, Random rand, IModelData extraData) { - List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData)); - if (!extraData.hasProperty(POSITION_PROPERTY)) - return quads; + List quads = super.getQuads(state, side, rand, extraData); if (quads.isEmpty()) return quads; - + if (!extraData.hasProperty(POSITION_PROPERTY)) + return quads; + BlockPos data = extraData.getData(POSITION_PROPERTY); + quads = new ArrayList<>(quads); + // Optifine might've rejigged vertex data VertexFormat format = DefaultVertexFormats.BLOCK; int colorIndex = 0; - for (int j = 0; j < format.getElements().size(); j++) { - VertexFormatElement e = format.getElements().get(j); - if (e.getUsage() == VertexFormatElement.Usage.COLOR) - colorIndex = j; + for (int elementId = 0; elementId < format.getElements().size(); elementId++) { + VertexFormatElement element = format.getElements().get(elementId); + if (element.getUsage() == VertexFormatElement.Usage.COLOR) + colorIndex = elementId; } - int colorOffset = format.getOffset(colorIndex) / 4; - BlockPos data = extraData.getData(POSITION_PROPERTY); - + int colorOffset = format.getOffset(colorIndex) / 4; + for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); - BakedQuad newQuad = new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), - quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.hasShade()); + + BakedQuad newQuad = QuadHelper.clone(quad); int[] vertexData = newQuad.getVertexData(); for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { diff --git a/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModel.java b/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModel.java index 8d0c411e1..6df4c426b 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModel.java @@ -9,18 +9,18 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.Create; import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; +import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.model.ModelRotation; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.model.BakedModelWrapper; @SuppressWarnings("deprecation") -public abstract class CustomRenderedItemModel extends WrappedBakedModel { +public abstract class CustomRenderedItemModel extends BakedModelWrapper { protected String basePath; protected Map partials = new HashMap<>(); - protected TransformType currentPerspective; protected ItemStackTileEntityRenderer renderer; public CustomRenderedItemModel(IBakedModel template, String basePath) { @@ -29,25 +29,30 @@ public abstract class CustomRenderedItemModel extends WrappedBakedModel { this.renderer = createRenderer(); } - public final List getModelLocations() { - return partials.keySet().stream().map(this::getPartialModelLocation).collect(Collectors.toList()); - } - - public ItemStackTileEntityRenderer getRenderer() { - return renderer; - } - - public abstract ItemStackTileEntityRenderer createRenderer(); - @Override public boolean isBuiltInRenderer() { return true; } @Override - public IBakedModel handlePerspective(TransformType cameraTransformType, MatrixStack mat) { - currentPerspective = cameraTransformType; - return super.handlePerspective(cameraTransformType, mat); + public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat) { + // Super call returns originalModel, but we want to return this, else ISTER won't be used. + super.handlePerspective(cameraTransformType, mat); + return this; + } + + public final IBakedModel getOriginalModel() { + return originalModel; + } + + public ItemStackTileEntityRenderer getRenderer() { + return renderer; + } + + public abstract ItemStackTileEntityRenderer createRenderer(); + + public final List getModelLocations() { + return partials.keySet().stream().map(this::getPartialModelLocation).collect(Collectors.toList()); } protected void addPartials(String... partials) { @@ -70,10 +75,6 @@ public abstract class CustomRenderedItemModel extends WrappedBakedModel { return new ResourceLocation(Create.ID, "item/" + basePath + "/" + name); } - public TransformType getCurrentPerspective() { - return currentPerspective; - } - public IBakedModel getPartial(String name) { return partials.get(name); } diff --git a/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModelRenderer.java b/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModelRenderer.java index a9874eea3..ee201c94c 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModelRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/CustomRenderedItemModelRenderer.java @@ -9,25 +9,23 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.item.ItemStack; -public class CustomRenderedItemModelRenderer extends ItemStackTileEntityRenderer { +public abstract class CustomRenderedItemModelRenderer extends ItemStackTileEntityRenderer { @Override @SuppressWarnings("unchecked") - public void render(ItemStack stack, ItemCameraTransforms.TransformType p_239207_2_, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + public void render(ItemStack stack, ItemCameraTransforms.TransformType transformType, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { M mainModel = ((M) Minecraft.getInstance() .getItemRenderer() .getItemModelWithOverrides(stack, null, null)); - PartialItemModelRenderer renderer = PartialItemModelRenderer.of(stack, p_239207_2_, ms, buffer, overlay); + PartialItemModelRenderer renderer = PartialItemModelRenderer.of(stack, transformType, ms, buffer, overlay); ms.push(); ms.translate(0.5F, 0.5F, 0.5F); - render(stack, mainModel, renderer, ms, buffer, light, overlay); + render(stack, mainModel, renderer, transformType, ms, buffer, light, overlay); ms.pop(); } - protected void render(ItemStack stack, M model, PartialItemModelRenderer renderer, MatrixStack ms, - IRenderTypeBuffer buffer, int light, int overlay) { - - } + protected abstract void render(ItemStack stack, M model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, + MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay); } diff --git a/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java b/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java new file mode 100644 index 000000000..81ece13f1 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/render/QuadHelper.java @@ -0,0 +1,16 @@ +package com.simibubi.create.foundation.block.render; + +import java.util.Arrays; + +import net.minecraft.client.renderer.model.BakedQuad; + +public final class QuadHelper { + + private QuadHelper() {} + + public static BakedQuad clone(BakedQuad quad) { + return new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), + quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.hasShade()); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java b/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java deleted file mode 100644 index cf545c8ee..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.simibubi.create.foundation.block.render; - -import java.util.List; -import java.util.Random; - -import com.mojang.blaze3d.matrix.MatrixStack; - -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; -import net.minecraft.client.renderer.model.ItemOverrideList; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.Direction; -import net.minecraftforge.client.model.data.EmptyModelData; -import net.minecraftforge.client.model.data.IModelData; - -public class WrappedBakedModel implements IBakedModel { - - protected IBakedModel template; - - public WrappedBakedModel(IBakedModel template) { - this.template = template; - } - - @Override - public IBakedModel getBakedModel() { - return template; - } - - @Override - public boolean isAmbientOcclusion() { - return template.isAmbientOcclusion(); - } - - @Override - public boolean isGui3d() { - return template.isGui3d(); - } - - @Override - public boolean isBuiltInRenderer() { - return template.isBuiltInRenderer(); - } - - @Override - public TextureAtlasSprite getParticleTexture(IModelData data) { - return template.getParticleTexture(data); - } - - @Override - public ItemOverrideList getOverrides() { - return template.getOverrides(); - } - - @Override - public IBakedModel handlePerspective(TransformType cameraTransformType, MatrixStack mat) { - template.handlePerspective(cameraTransformType, mat); - return this; - } - - @Override - public List getQuads(BlockState state, Direction side, Random rand) { - return getQuads(state, side, rand, EmptyModelData.INSTANCE); - } - - @Override - public List getQuads(BlockState state, Direction side, Random rand, IModelData data) { - return template.getQuads(state, side, rand, data); - } - - @Override - public TextureAtlasSprite getParticleTexture() { - return getParticleTexture(EmptyModelData.INSTANCE); - } - - @Override - public boolean isSideLit() { - return template.isSideLit(); - } -} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 3982f6206..f5b2f4588 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -51,6 +51,10 @@ public com.mojang.blaze3d.platform.GlStateManager$BooleanState field_179201_b #f # GameRenderer public net.minecraft.client.renderer.GameRenderer func_215311_a(Lnet/minecraft/client/renderer/ActiveRenderInfo;FZ)D #getFOVModifier +# FirstPersonRenderer +public net.minecraft.client.renderer.FirstPersonRenderer field_187467_d # itemStackMainHand +public net.minecraft.client.renderer.FirstPersonRenderer field_187468_e # itemStackOffHand + # IResizeCallback public net.minecraft.util.palette.IResizeCallback