This commit is contained in:
PepperBell 2021-05-01 15:41:03 -07:00
parent c9718b0a1b
commit 9be5a3ec2a
21 changed files with 135 additions and 204 deletions

View file

@ -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<IBakedModel> {
public GogglesModel(IBakedModel template) {
super(template);

View file

@ -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<IBakedModel> {
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData extraData) {
List<BakedQuad> quads = new ArrayList<>(super.getQuads(state, side, rand, extraData));
List<BakedQuad> 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<IBakedModel> {
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<IBakedModel> {
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);

View file

@ -495,7 +495,7 @@ public class BeltTileEntity extends KineticTileEntity implements LightUpdateList
return empty;
}
public static ModelProperty<CasingType> CASING_PROPERTY = new ModelProperty<>();
public static final ModelProperty<CasingType> CASING_PROPERTY = new ModelProperty<>();
@Override
public IModelData getModelData() {

View file

@ -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<IBakedModel> {
private static ModelProperty<BracketedModelData> BRACKET_PROPERTY = new ModelProperty<>();

View file

@ -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<WrenchModel> {
@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);
}
}

View file

@ -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<SymmetryWandModel> {
@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);
}

View file

@ -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<DeforesterModel> {
@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);
}
}

View file

@ -19,13 +19,12 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer<Ext
private static final Vector3d cogRotationOffset = new Vector3d(0, 1 / 16f, 0);
@Override
protected void render(ItemStack stack, ExtendoGripModel model, PartialItemModelRenderer renderer, MatrixStack ms,
IRenderTypeBuffer buffer, int light, int overlay) {
protected void render(ItemStack stack, ExtendoGripModel model, PartialItemModelRenderer renderer, TransformType transformType,
MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
MatrixStacker stacker = MatrixStacker.of(ms);
float animation = 0.25f;
TransformType perspective = model.getCurrentPerspective();
boolean leftHand = perspective == TransformType.FIRST_PERSON_LEFT_HAND;
boolean rightHand = perspective == TransformType.FIRST_PERSON_RIGHT_HAND;
boolean leftHand = transformType == TransformType.FIRST_PERSON_LEFT_HAND;
boolean rightHand = transformType == TransformType.FIRST_PERSON_RIGHT_HAND;
if (leftHand || rightHand)
animation = MathHelper.lerp(AnimationTickHolder.getPartialTicks(),
ExtendoGripRenderHandler.lastMainHandAnimation,
@ -37,7 +36,7 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer<Ext
float oppositeAngle = 180 - extensionAngle;
// grip
renderer.renderSolid(model.getBakedModel(), light);
renderer.renderSolid(model.getOriginalModel(), light);
// bits
ms.push();

View file

@ -35,12 +35,10 @@ public class ExtendoGripRenderHandler {
lastMainHandAnimation = mainHandAnimation;
mainHandAnimation *= MathHelper.clamp(mainHandAnimation, 0.8f, 0.99f);
Minecraft mc = Minecraft.getInstance();
ClientPlayerEntity player = mc.player;
pose = AllBlockPartials.DEPLOYER_HAND_PUNCHING;
if (!AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand()))
if (!AllItems.EXTENDO_GRIP.isIn(getRenderedOffHandStack()))
return;
ItemStack main = player.getHeldItemMainhand();
ItemStack main = getRenderedMainHandStack();
if (main.isEmpty())
return;
if (!(main.getItem() instanceof BlockItem))
@ -60,7 +58,7 @@ public class ExtendoGripRenderHandler {
ClientPlayerEntity player = mc.player;
boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT;
ItemStack offhandItem = player.getHeldItemOffhand();
ItemStack offhandItem = getRenderedOffHandStack();
boolean notInOffhand = !AllItems.EXTENDO_GRIP.isIn(offhandItem);
if (notInOffhand && !AllItems.EXTENDO_GRIP.isIn(heldItem))
return;
@ -138,4 +136,12 @@ public class ExtendoGripRenderHandler {
event.setCanceled(true);
}
private static ItemStack getRenderedMainHandStack() {
return Minecraft.getInstance().getFirstPersonRenderer().itemStackMainHand;
}
private static ItemStack getRenderedOffHandStack() {
return Minecraft.getInstance().getFirstPersonRenderer().itemStackOffHand;
}
}

View file

@ -9,7 +9,6 @@ import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
import net.minecraft.item.ItemStack;
@ -20,15 +19,14 @@ import net.minecraft.util.math.vector.Vector3f;
public class SandPaperItemRenderer extends ItemStackTileEntityRenderer {
@Override
public void render(ItemStack stack, ItemCameraTransforms.TransformType p_239207_2_, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
public void render(ItemStack stack, TransformType transformType, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
ClientPlayerEntity player = Minecraft.getInstance().player;
SandPaperModel mainModel = (SandPaperModel) itemRenderer.getItemModelWithOverrides(stack, Minecraft.getInstance().world, null);
TransformType perspective = mainModel.getCurrentPerspective();
float partialTicks = AnimationTickHolder.getPartialTicks();
boolean leftHand = perspective == TransformType.FIRST_PERSON_LEFT_HAND;
boolean firstPerson = leftHand || perspective == TransformType.FIRST_PERSON_RIGHT_HAND;
boolean leftHand = transformType == TransformType.FIRST_PERSON_LEFT_HAND;
boolean firstPerson = leftHand || transformType == TransformType.FIRST_PERSON_RIGHT_HAND;
ms.push();
ms.translate(.5f, .5f, .5f);
@ -39,7 +37,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer {
if (tag.contains("Polishing")) {
ms.push();
if (perspective == TransformType.GUI) {
if (transformType == TransformType.GUI) {
ms.translate(0.0F, .2f, 1.0F);
ms.scale(.75f, .75f, .75f);
} else {
@ -53,7 +51,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer {
if (time / (float) stack.getUseDuration() < 0.8F) {
float bobbing = -MathHelper.abs(MathHelper.cos(time / 4.0F * (float) Math.PI) * 0.1F);
if (perspective == TransformType.GUI)
if (transformType == TransformType.GUI)
ms.translate(bobbing, bobbing, 0.0F);
else
ms.translate(0.0f, bobbing, 0.0F);
@ -76,7 +74,7 @@ public class SandPaperItemRenderer extends ItemStackTileEntityRenderer {
}
}
itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, light, overlay, mainModel.getBakedModel());
itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, light, overlay, mainModel.getOriginalModel());
ms.pop();
}

View file

@ -18,10 +18,10 @@ import net.minecraft.util.math.MathHelper;
public abstract class ZapperItemRenderer<M extends CustomRenderedItemModel> extends CustomRenderedItemModelRenderer<M> {
@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);
}

View file

@ -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<BlockzapperModel> {
@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);

View file

@ -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<WorldshaperModel> {
@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;

View file

@ -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<CTData> CT_PROPERTY = new ModelProperty<>();
protected static final ModelProperty<CTData> 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<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData extraData) {
List<BakedQuad> quads = new ArrayList<>(super.getQuads(state, side, rand, extraData));
List<BakedQuad> 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;

View file

@ -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;
}
}

View file

@ -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<IBakedModel> {
private static final ModelProperty<BlockPos> POSITION_PROPERTY = new ModelProperty<>();
private IBlockVertexColor color;
private static ModelProperty<BlockPos> POSITION_PROPERTY = new ModelProperty<>();
public ColoredVertexModel(IBakedModel originalModel, IBlockVertexColor color) {
super(originalModel);
@ -38,27 +37,28 @@ public class ColoredVertexModel extends BakedModelWrapper<IBakedModel> {
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData extraData) {
List<BakedQuad> quads = new ArrayList<>(super.getQuads(state, side, rand, extraData));
if (!extraData.hasProperty(POSITION_PROPERTY))
return quads;
List<BakedQuad> 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()) {

View file

@ -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<IBakedModel> {
protected String basePath;
protected Map<String, IBakedModel> 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<ResourceLocation> 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<ResourceLocation> 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);
}

View file

@ -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<M extends CustomRenderedItemModel> extends ItemStackTileEntityRenderer {
public abstract class CustomRenderedItemModelRenderer<M extends CustomRenderedItemModel> 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);
}

View file

@ -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());
}
}

View file

@ -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<BakedQuad> getQuads(BlockState state, Direction side, Random rand) {
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
}
@Override
public List<BakedQuad> 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();
}
}

View file

@ -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