mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
Merge pull request #1544 from PepperCode1/mc1.16/model-cleanup
Cleanup Models and Custom Item Rendering
This commit is contained in:
commit
4974df5c99
19 changed files with 125 additions and 195 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<>();
|
||||
|
||||
|
|
|
@ -7,15 +7,16 @@ 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);
|
||||
|
|
|
@ -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,12 +14,12 @@ 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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
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()) {
|
||||
|
|
|
@ -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,8 +29,20 @@ public abstract class CustomRenderedItemModel extends WrappedBakedModel {
|
|||
this.renderer = createRenderer();
|
||||
}
|
||||
|
||||
public final List<ResourceLocation> getModelLocations() {
|
||||
return partials.keySet().stream().map(this::getPartialModelLocation).collect(Collectors.toList());
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
|
@ -39,15 +51,8 @@ public abstract class CustomRenderedItemModel extends WrappedBakedModel {
|
|||
|
||||
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 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue