Item rendering for robot.
This commit is contained in:
@@ -2,19 +2,15 @@ package li.cil.oc2.client.renderer.entity;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.entity.model.RobotModel;
|
||||
import li.cil.oc2.common.entity.RobotEntity;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
||||
import net.minecraft.client.renderer.entity.model.EntityModel;
|
||||
import net.minecraft.client.renderer.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
|
||||
private final RobotModel model = new RobotModel();
|
||||
@@ -29,7 +25,7 @@ public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
|
||||
|
||||
@Override
|
||||
public ResourceLocation getEntityTexture(final RobotEntity entity) {
|
||||
return new ResourceLocation(API.MOD_ID, "textures/entity/robot/robot.png");
|
||||
return RobotModel.ROBOT_ENTITY_TEXTURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,49 +54,4 @@ public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
|
||||
// super.renderName(entity, new StringTextComponent("hi"), matrixStack, buffer, packedLight);
|
||||
// }
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final class RobotModel extends EntityModel<RobotEntity> {
|
||||
private final ModelRenderer topRenderer;
|
||||
private final ModelRenderer baseRenderer;
|
||||
private final ModelRenderer coreRenderer;
|
||||
private float baseY, topY;
|
||||
private final float[] topRotation = new float[3];
|
||||
|
||||
public RobotModel() {
|
||||
topRenderer = new ModelRenderer(this, 1, 1)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-7, 8, -7, 14, 6, 14);
|
||||
baseRenderer = new ModelRenderer(this, 1, 23)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-7, 0, -7, 14, 7, 14);
|
||||
coreRenderer = new ModelRenderer(this, 1, 34)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-6, 7, -6, 12, 1, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationAngles(final RobotEntity entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks, final float netHeadYaw, final float headPitch) {
|
||||
final RobotEntity.AnimationState state = entity.getAnimationState();
|
||||
baseY = state.baseRenderOffsetY;
|
||||
topY = state.topRenderOffsetY;
|
||||
topRotation[1] = state.topRenderRotationY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final MatrixStack matrixStack, final IVertexBuilder buffer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) {
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0, topY, 0);
|
||||
matrixStack.rotate(TransformationHelper.quatFromXYZ(topRotation, true));
|
||||
topRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
matrixStack.pop();
|
||||
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0, baseY, 0);
|
||||
baseRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
coreRenderer.render(matrixStack, buffer, LightTexture.packLight(15, 15), packedOverlay);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package li.cil.oc2.client.renderer.entity.model;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.common.entity.RobotEntity;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.entity.model.EntityModel;
|
||||
import net.minecraft.client.renderer.model.ModelRenderer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
public final class RobotModel extends EntityModel<RobotEntity> {
|
||||
public static final ResourceLocation ROBOT_ENTITY_TEXTURE = new ResourceLocation(API.MOD_ID, "textures/entity/robot/robot.png");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final ModelRenderer topRenderer;
|
||||
private final ModelRenderer baseRenderer;
|
||||
private final ModelRenderer coreRenderer;
|
||||
private float baseY, topY;
|
||||
private final float[] topRotation = new float[3];
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RobotModel() {
|
||||
topRenderer = new ModelRenderer(this, 1, 1)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-7, 8, -7, 14, 6, 14);
|
||||
baseRenderer = new ModelRenderer(this, 1, 23)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-7, 0, -7, 14, 7, 14);
|
||||
coreRenderer = new ModelRenderer(this, 1, 34)
|
||||
.setTextureSize(64, 64)
|
||||
.addBox(-6, 7, -6, 12, 1, 12);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void setRotationAngles(final RobotEntity entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks, final float netHeadYaw, final float headPitch) {
|
||||
final RobotEntity.AnimationState state = entity.getAnimationState();
|
||||
baseY = state.baseRenderOffsetY;
|
||||
topY = state.topRenderOffsetY;
|
||||
topRotation[1] = state.topRenderRotationY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final MatrixStack matrixStack, final IVertexBuilder buffer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) {
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0, topY, 0);
|
||||
matrixStack.rotate(TransformationHelper.quatFromXYZ(topRotation, true));
|
||||
topRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
matrixStack.pop();
|
||||
|
||||
matrixStack.push();
|
||||
matrixStack.translate(0, baseY, 0);
|
||||
baseRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
coreRenderer.render(matrixStack, buffer, LightTexture.packLight(15, 15), packedOverlay);
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package li.cil.oc2.client.renderer.entity.model;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -0,0 +1,28 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import li.cil.oc2.client.renderer.entity.model.RobotModel;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class RobotItemStackRenderer extends ItemStackTileEntityRenderer {
|
||||
private final RobotModel model = new RobotModel();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void func_239207_a_(final ItemStack stack, final ItemCameraTransforms.TransformType transformType, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int combinedLight, final int combinedOverlay) {
|
||||
matrixStack.push();
|
||||
|
||||
matrixStack.translate(0.5, 0, 0.5);
|
||||
|
||||
final IVertexBuilder builder = buffer.getBuffer(model.getRenderType(RobotModel.ROBOT_ENTITY_TEXTURE));
|
||||
model.render(matrixStack, builder, combinedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package li.cil.oc2.common.item;
|
||||
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.tileentity.RobotItemStackRenderer;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.block.Blocks;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -30,7 +31,7 @@ public final class Items {
|
||||
|
||||
public static final RegistryObject<Item> BUS_INTERFACE_ITEM = register(Constants.BUS_INTERFACE_ITEM_NAME, BusInterfaceItem::new);
|
||||
public static final RegistryObject<Item> NETWORK_CABLE_ITEM = register(Constants.NETWORK_CABLE_ITEM_NAME, NetworkCableItem::new);
|
||||
public static final RegistryObject<Item> ROBOT_ITEM = register(Constants.ROBOT_ENTITY_NAME, RobotItem::new);
|
||||
public static final RegistryObject<Item> ROBOT_ITEM = register(Constants.ROBOT_ENTITY_NAME, RobotItem::new, commonProperties().setISTER(() -> RobotItemStackRenderer::new));
|
||||
|
||||
public static final RegistryObject<Item> MEMORY_ITEM = register(Constants.MEMORY_ITEM_NAME, MemoryItem::new, new Item.Properties());
|
||||
public static final RegistryObject<Item> HARD_DRIVE_ITEM = register(Constants.HARD_DRIVE_ITEM_NAME, HardDriveItem::new, new Item.Properties());
|
||||
|
||||
@@ -44,6 +44,8 @@ public final class ItemModels extends ItemModelProvider {
|
||||
simple(Items.FLASH_MEMORY_ITEM, "items/flash_memory");
|
||||
simple(Items.REDSTONE_INTERFACE_CARD_ITEM, "items/redstone_interface_card");
|
||||
simple(Items.NETWORK_INTERFACE_CARD_ITEM, "items/network_interface_card");
|
||||
|
||||
withExistingParent(Constants.ROBOT_ENTITY_NAME, "template_shulker_box");
|
||||
}
|
||||
|
||||
private <T extends Item> ItemModelBuilder simple(final RegistryObject<T> item, final String texturePath) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"item.oc2.flash_memory": "Flash Memory",
|
||||
"item.oc2.redstone_interface_card": "Redstone Interface Card",
|
||||
"item.oc2.network_interface_card": "Network Interface Card",
|
||||
"item.oc2.robot": "Robot",
|
||||
|
||||
"entity.oc2.robot": "Robot",
|
||||
|
||||
|
||||
3
src/main/resources/assets/oc2/models/item/robot.json
Normal file
3
src/main/resources/assets/oc2/models/item/robot.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "minecraft:item/template_shulker_box"
|
||||
}
|
||||
Reference in New Issue
Block a user