Copper armor fixes

- Add backtank layer to all player models
- Only add backtank layer if entity renderer returns BipedModel
- Make copper armor considered to be worn only when in the correct armor
slot
This commit is contained in:
PepperBell 2021-07-25 14:08:46 -07:00
parent 74d57f38fe
commit 1d6da03799
3 changed files with 30 additions and 21 deletions

View file

@ -35,6 +35,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.settings.GraphicsFanciness;
@ -112,7 +113,8 @@ public class CreateClient {
((IReloadableResourceManager) resourceManager).registerReloadListener(new ResourceReloadHandler());
event.enqueueWork(() -> {
CopperBacktankArmorLayer.register();
registerLayerRenderers(Minecraft.getInstance()
.getEntityRenderDispatcher());
});
}
@ -174,6 +176,10 @@ public class CreateClient {
modelRegistry.put(location, factory.apply(modelRegistry.get(location)));
}
protected static void registerLayerRenderers(EntityRendererManager renderManager) {
CopperBacktankArmorLayer.registerOnAll(renderManager);
}
public static CustomItemModels getCustomItemModels() {
if (customItemModels == null)
customItemModels = new CustomItemModels();

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.curiosities.armor;
import com.simibubi.create.Create;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ItemStack;
@ -14,10 +15,10 @@ public class CopperArmorItem extends ArmorItem {
}
public boolean isWornBy(Entity entity) {
for (ItemStack itemStack : entity.getArmorSlots())
if (itemStack.getItem() == this)
return true;
return false;
if (!(entity instanceof LivingEntity))
return false;
LivingEntity livingEntity = (LivingEntity) entity;
return livingEntity.getItemBySlot(slot).getItem() == this;
}
@Override

View file

@ -21,7 +21,9 @@ import net.minecraft.client.renderer.IRenderTypeBuffer.Impl;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.IEntityRenderer;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.client.renderer.entity.PlayerRenderer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.client.renderer.entity.model.EntityModel;
@ -35,41 +37,37 @@ import net.minecraft.util.text.StringTextComponent;
public class CopperBacktankArmorLayer<T extends LivingEntity, M extends EntityModel<T>> extends LayerRenderer<T, M> {
private LivingRenderer<T, M> renderer;
public CopperBacktankArmorLayer(LivingRenderer<T, M> renderer) {
public CopperBacktankArmorLayer(IEntityRenderer<T, M> renderer) {
super(renderer);
this.renderer = renderer;
renderer.addLayer(this);
}
@Override
public void render(MatrixStack ms, IRenderTypeBuffer buffer, int light, LivingEntity entity, float yaw, float pitch,
float pt, float p_225628_8_, float p_225628_9_, float p_225628_10_) {
if (entity.getPose() == Pose.SLEEPING)
return;
if (!AllItems.COPPER_BACKTANK.get()
.isWornBy(entity))
return;
M entityModel = renderer.getModel();
M entityModel = getParentModel();
if (!(entityModel instanceof BipedModel))
return;
ms.pushPose();
BipedModel<?> model = (BipedModel<?>) entityModel;
RenderType renderType = Atlases.cutoutBlockSheet();
BlockState renderedState = AllBlocks.COPPER_BACKTANK.getDefaultState()
.setValue(CopperBacktankBlock.HORIZONTAL_FACING, Direction.SOUTH);
RenderType renderType = Atlases.cutoutBlockSheet();
SuperByteBuffer backtank = CreateClient.BUFFER_CACHE.renderBlock(renderedState);
SuperByteBuffer cogs =
CreateClient.BUFFER_CACHE.renderPartial(AllBlockPartials.COPPER_BACKTANK_COGS, renderedState);
ms.pushPose();
model.body.translateAndRotate(ms);
ms.translate(-1 / 2f, 10 / 16f, 1f);
ms.scale(1, -1, -1);
backtank.forEntityRender()
.light(light)
.renderInto(ms, buffer.getBuffer(renderType));
@ -89,18 +87,22 @@ public class CopperBacktankArmorLayer<T extends LivingEntity, M extends EntityMo
ms.popPose();
}
public static void register() {
EntityRendererManager renderManager = Minecraft.getInstance()
.getEntityRenderDispatcher();
registerOn(renderManager.defaultPlayerRenderer);
public static void registerOnAll(EntityRendererManager renderManager) {
for (PlayerRenderer renderer : renderManager.getSkinMap().values())
registerOn(renderer);
for (EntityRenderer<?> renderer : renderManager.renderers.values())
registerOn(renderer);
}
private static void registerOn(EntityRenderer<?> entityRenderer) {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void registerOn(EntityRenderer<?> entityRenderer) {
if (!(entityRenderer instanceof LivingRenderer))
return;
new CopperBacktankArmorLayer<>((LivingRenderer<?, ?>) entityRenderer);
LivingRenderer<?, ?> livingRenderer = (LivingRenderer<?, ?>) entityRenderer;
if (!(livingRenderer.getModel() instanceof BipedModel))
return;
CopperBacktankArmorLayer<?, ?> layer = new CopperBacktankArmorLayer<>(livingRenderer);
livingRenderer.addLayer((CopperBacktankArmorLayer) layer);
}
public static void renderRemainingAirOverlay(MatrixStack ms, Impl buffers, int light, int overlay, float pt) {