made progress with lumberjack implementation, #1869

This commit is contained in:
SpaceToad 2014-06-07 18:56:07 +02:00
parent 87c18afb76
commit 9e58783add
5 changed files with 233 additions and 0 deletions

View file

@ -37,6 +37,7 @@ import buildcraft.core.Version;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.robots.RobotIntegrationRecipe;
import buildcraft.core.robots.boards.BoardRobotLumberjackNBT;
import buildcraft.core.robots.boards.BoardRobotPickerNBT;
import buildcraft.silicon.BlockLaser;
import buildcraft.silicon.BlockLaserTable;
@ -108,6 +109,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
RedstoneBoardRegistry.instance = new ImplRedstoneBoardRegistry();
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotPickerNBT.instance, 10);
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotLumberjackNBT.instance, 10);
}
@Mod.EventHandler

View file

@ -10,16 +10,21 @@ package buildcraft.core.render;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import buildcraft.BuildCraftSilicon;
import buildcraft.core.EntityLaser;
@ -56,12 +61,19 @@ public class RenderRobot extends Render implements IItemRenderer {
box.render(factor);
// GL11.glTranslated(0.5, 0, 0);
GL11.glRotatef(robot.worldObj.getTotalWorldTime() % 45 + 90, 1, 0, 0);
doRenderItemAtHand(robot, new ItemStack(Items.diamond_axe));
// GL11.glTranslated(-0.5, 0, 0);
if (robot.laser.isVisible) {
robot.laser.head.x = robot.posX;
robot.laser.head.y = robot.posY;
robot.laser.head.z = robot.posZ;
RenderLaser.doRenderLaser(renderManager.renderEngine, robot.laser, EntityLaser.LASER_TEXTURES [1]);
} else {
}
GL11.glEnable(GL11.GL_LIGHTING);
@ -118,4 +130,104 @@ public class RenderRobot extends Render implements IItemRenderer {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
/**
* This is a refactor from the code of RenderPlayer.
*/
public void doRenderItemAtHand(EntityRobot robot, ItemStack currentItem) {
ItemStack itemstack1 = currentItem;
float f3, f5;
if (itemstack1 != null) {
GL11.glPushMatrix();
// this.modelBipedMain.bipedRightArm.postRender(0.0625F);
GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
// if (par1AbstractClientPlayer.fishEntity != null)
// {
// itemstack1 = new ItemStack(Items.stick);
// }
EnumAction enumaction = EnumAction.none;
// if (par1AbstractClientPlayer.getItemInUseCount() > 0)
// {
// enumaction = itemstack1.getItemUseAction();
// }
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack1, ItemRenderType.EQUIPPED);
boolean is3D = customRenderer != null && customRenderer.shouldUseRenderHelper(ItemRenderType.EQUIPPED,
itemstack1,
ItemRendererHelper.BLOCK_3D);
if (is3D || itemstack1.getItem() instanceof ItemBlock
&& RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemstack1.getItem()).getRenderType())) {
f3 = 0.5F;
GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
f3 *= 0.75F;
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(-f3, -f3, f3);
} else if (itemstack1.getItem() == Items.bow) {
f3 = 0.625F;
GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(f3, -f3, f3);
GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
} else if (itemstack1.getItem().isFull3D()) {
f3 = 0.625F;
if (itemstack1.getItem().shouldRotateAroundWhenRendering()) {
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, -0.125F, 0.0F);
}
/*
* if (par1AbstractClientPlayer.getItemInUseCount() > 0 &&
* enumaction == EnumAction.block) { GL11.glTranslatef(0.05F,
* 0.0F, -0.1F); GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F);
* GL11.glRotatef(-10.0F, 1.0F, 0.0F, 0.0F);
* GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F); }
*/
GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
GL11.glScalef(f3, -f3, f3);
GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
} else {
f3 = 0.375F;
GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
GL11.glScalef(f3, f3, f3);
GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);
}
float f4;
int k;
float f12;
if (itemstack1.getItem().requiresMultipleRenderPasses()) {
for (k = 0; k < itemstack1.getItem().getRenderPasses(itemstack1.getItemDamage()); ++k) {
int i = itemstack1.getItem().getColorFromItemStack(itemstack1, k);
f12 = (i >> 16 & 255) / 255.0F;
f4 = (i >> 8 & 255) / 255.0F;
f5 = (i & 255) / 255.0F;
GL11.glColor4f(f12, f4, f5, 1.0F);
this.renderManager.itemRenderer.renderItem(robot, itemstack1, k);
}
} else {
k = itemstack1.getItem().getColorFromItemStack(itemstack1, 0);
float f11 = (k >> 16 & 255) / 255.0F;
f12 = (k >> 8 & 255) / 255.0F;
f4 = (k & 255) / 255.0F;
GL11.glColor4f(f11, f12, f4, 1.0F);
this.renderManager.itemRenderer.renderItem(robot, itemstack1, 0);
}
GL11.glPopMatrix();
}
}
}

View file

@ -40,6 +40,8 @@ public class EntityRobot extends EntityLiving implements
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png");
public static final ResourceLocation ROBOT_TRANSPORT = new ResourceLocation("buildcraft",
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_picker.png");
public static final ResourceLocation ROBOT_FACTORY = new ResourceLocation("buildcraft",
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_factory.png");
private static ResourceLocation defaultTexture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_base.png");

View file

@ -0,0 +1,41 @@
package buildcraft.core.robots.boards;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.boards.IRedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardNBT;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.core.robots.EntityRobot;
public class BoardRobotLumberjack implements IRedstoneBoardRobot<EntityRobot> {
private NBTTagCompound data;
private RedstoneBoardNBT board;
private int range;
private boolean initialized = false;
public BoardRobotLumberjack(NBTTagCompound nbt) {
data = nbt;
board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt);
}
@Override
public void updateBoard(EntityRobot robot) {
if (robot.worldObj.isRemote) {
return;
}
if (!initialized) {
range = data.getInteger("range");
initialized = true;
}
}
@Override
public RedstoneBoardRobotNBT getNBTHandler() {
return BoardRobotLumberjackNBT.instance;
}
}

View file

@ -0,0 +1,76 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.robots.boards;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import buildcraft.api.boards.IRedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.NBTUtils;
import buildcraft.core.utils.StringUtils;
public final class BoardRobotLumberjackNBT extends RedstoneBoardRobotNBT {
public static BoardRobotLumberjackNBT instance = new BoardRobotLumberjackNBT();
public IIcon icon;
private BoardRobotLumberjackNBT() {
}
@Override
public String getID() {
return "buildcraft:boardRobotLumberjack";
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
list.add(StringUtils.localize("buildcraft.boardRobotLumberjack"));
NBTTagCompound nbt = NBTUtils.getItemData(stack);
list.add(StringUtils.localize("buildcraft.boardDetail.range") + ": " + nbt.getInteger("range"));
}
@Override
public IRedstoneBoardRobot create(NBTTagCompound nbt) {
return new BoardRobotLumberjack(nbt);
}
@Override
public IIcon getIcon(NBTTagCompound nbt) {
return icon;
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:board_blue");
}
@Override
public void createRandomBoard(NBTTagCompound nbt) {
int range = (int) Math.floor(nextFloat(10) * 500) + 10;
nbt.setInteger("range", range);
}
@Override
public ResourceLocation getRobotTexture() {
return EntityRobot.ROBOT_FACTORY;
}
}