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

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.curiosities.armor;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -14,10 +15,10 @@ public class CopperArmorItem extends ArmorItem {
} }
public boolean isWornBy(Entity entity) { public boolean isWornBy(Entity entity) {
for (ItemStack itemStack : entity.getArmorSlots()) if (!(entity instanceof LivingEntity))
if (itemStack.getItem() == this) return false;
return true; LivingEntity livingEntity = (LivingEntity) entity;
return false; return livingEntity.getItemBySlot(slot).getItem() == this;
} }
@Override @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.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager; 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.LivingRenderer;
import net.minecraft.client.renderer.entity.PlayerRenderer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer; import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.client.renderer.entity.model.BipedModel; import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.client.renderer.entity.model.EntityModel; 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> { public class CopperBacktankArmorLayer<T extends LivingEntity, M extends EntityModel<T>> extends LayerRenderer<T, M> {
private LivingRenderer<T, M> renderer; public CopperBacktankArmorLayer(IEntityRenderer<T, M> renderer) {
public CopperBacktankArmorLayer(LivingRenderer<T, M> renderer) {
super(renderer); super(renderer);
this.renderer = renderer;
renderer.addLayer(this);
} }
@Override @Override
public void render(MatrixStack ms, IRenderTypeBuffer buffer, int light, LivingEntity entity, float yaw, float pitch, 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_) { float pt, float p_225628_8_, float p_225628_9_, float p_225628_10_) {
if (entity.getPose() == Pose.SLEEPING) if (entity.getPose() == Pose.SLEEPING)
return; return;
if (!AllItems.COPPER_BACKTANK.get() if (!AllItems.COPPER_BACKTANK.get()
.isWornBy(entity)) .isWornBy(entity))
return; return;
M entityModel = renderer.getModel(); M entityModel = getParentModel();
if (!(entityModel instanceof BipedModel)) if (!(entityModel instanceof BipedModel))
return; return;
ms.pushPose();
BipedModel<?> model = (BipedModel<?>) entityModel; BipedModel<?> model = (BipedModel<?>) entityModel;
RenderType renderType = Atlases.cutoutBlockSheet();
BlockState renderedState = AllBlocks.COPPER_BACKTANK.getDefaultState() BlockState renderedState = AllBlocks.COPPER_BACKTANK.getDefaultState()
.setValue(CopperBacktankBlock.HORIZONTAL_FACING, Direction.SOUTH); .setValue(CopperBacktankBlock.HORIZONTAL_FACING, Direction.SOUTH);
RenderType renderType = Atlases.cutoutBlockSheet();
SuperByteBuffer backtank = CreateClient.BUFFER_CACHE.renderBlock(renderedState); SuperByteBuffer backtank = CreateClient.BUFFER_CACHE.renderBlock(renderedState);
SuperByteBuffer cogs = SuperByteBuffer cogs =
CreateClient.BUFFER_CACHE.renderPartial(AllBlockPartials.COPPER_BACKTANK_COGS, renderedState); CreateClient.BUFFER_CACHE.renderPartial(AllBlockPartials.COPPER_BACKTANK_COGS, renderedState);
ms.pushPose();
model.body.translateAndRotate(ms); model.body.translateAndRotate(ms);
ms.translate(-1 / 2f, 10 / 16f, 1f); ms.translate(-1 / 2f, 10 / 16f, 1f);
ms.scale(1, -1, -1); ms.scale(1, -1, -1);
backtank.forEntityRender() backtank.forEntityRender()
.light(light) .light(light)
.renderInto(ms, buffer.getBuffer(renderType)); .renderInto(ms, buffer.getBuffer(renderType));
@ -89,18 +87,22 @@ public class CopperBacktankArmorLayer<T extends LivingEntity, M extends EntityMo
ms.popPose(); ms.popPose();
} }
public static void register() { public static void registerOnAll(EntityRendererManager renderManager) {
EntityRendererManager renderManager = Minecraft.getInstance() for (PlayerRenderer renderer : renderManager.getSkinMap().values())
.getEntityRenderDispatcher(); registerOn(renderer);
registerOn(renderManager.defaultPlayerRenderer);
for (EntityRenderer<?> renderer : renderManager.renderers.values()) for (EntityRenderer<?> renderer : renderManager.renderers.values())
registerOn(renderer); registerOn(renderer);
} }
private static void registerOn(EntityRenderer<?> entityRenderer) { @SuppressWarnings({ "rawtypes", "unchecked" })
public static void registerOn(EntityRenderer<?> entityRenderer) {
if (!(entityRenderer instanceof LivingRenderer)) if (!(entityRenderer instanceof LivingRenderer))
return; 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) { public static void renderRemainingAirOverlay(MatrixStack ms, Impl buffers, int light, int overlay, float pt) {