Jump to content

americanman

Members
  • Posts

    32
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

americanman's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Okay, I see. I'll be sure to try that. I've managed to get it to spawn on the client side. Thanks for the help.
  2. I was asking for the method used. Like is it the setInventorySlotContents or something else?
  3. Okay, I'll try to get it to spawn client side. Where should I check to see if the stored itemstacks are null?
  4. I've been working on a tile entity that makes various items in the game. I've managed to get the server to spawn the itemstacks but they are invisible in the slots until the user grabs them. I think maybe I'm only spawning on the server. Also, I've noticed that various itemstacks seem to be around that have a stack size of 0 if I try to grab from the slot after all of the items are gone. It basically shows a value of 0 in red where a number would be if the stack size is more than 1. What is it I'm doing wrong? Anything helps. Block Class: package com.littlepup.xcom.blocks.engineering_block; import com.littlepup.xcom.XcomMain; import com.littlepup.xcom.packets.PacketsMain; import com.littlepup.xcom.packets.XcomGuiHandler; import com.littlepup.xcom.packets.engineering.EngineerToServerMessage; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class BlockEngineeringPanel extends BlockContainer { public BlockEngineeringPanel(Material materialIn) { super(materialIn); this.setBlockUnbreakable(); this.setCreativeTab(XcomMain.xcomTab); this.setUnlocalizedName("engineering_block"); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityEngineerPanel(); } @Override public int getRenderType() { return 3; } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { TileEntityEngineerPanel engineerPanel = (TileEntityEngineerPanel) world.getTileEntity(pos); engineerPanel.setAvailibleProjects(); player.openGui(XcomMain.instance, XcomGuiHandler.engineerPanelGui, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } } TileEntity Class: package com.littlepup.xcom.blocks.engineering_block; import java.util.List; import com.google.common.collect.Lists; import com.littlepup.xcom.blocks.research_block.TileEntityResearchPanel; import com.littlepup.xcom.items.ItemAlienMaterials; import com.littlepup.xcom.items.ItemAlienSpecies; import com.littlepup.xcom.items.ItemAlienTrophy; import com.littlepup.xcom.other.Utilities; import com.littlepup.xcom.packets.PacketsMain; import com.littlepup.xcom.packets.xcom_base.BaseInfoMessage; import com.littlepup.xcom.packets.xcom_base.BaseRequestInfoMessage; import com.littlepup.xcom.projects.XcomEngineeringProjects; import com.littlepup.xcom.projects.engineering.EngineeringProject; import com.littlepup.xcom.projects.research.ResearchProject; import com.littlepup.xcom.xcom_base.XcomBase; import com.littlepup.xcom.xcom_base.XcomBaseCollection; import net.minecraft.client.renderer.texture.ITickable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; public class TileEntityEngineerPanel extends TileEntity implements IInventory, ITickable { public TileEntityEngineerPanel() { this.storedMaterials = new ItemStack[this.getSizeInventory()]; } public int associatedBaseID; public XcomBase associatedBase; public static final int inventorySize = 12; public ItemStack[] storedMaterials = new ItemStack[this.inventorySize]; private ItemStack[] usingMaterials = {null, null, null, null, null, null}; boolean isManufacturing = false; EngineeringProject currentProject; List allProjects = XcomEngineeringProjects.getEngineeringProjects(); public List availibleProjects = Lists.newArrayList(); public int currentProjectID = 0; public long timeNeeded; public int amount = 1; public void updateBaseInfo(int baseID) { this.associatedBaseID = baseID; if(worldObj.isRemote) { BaseRequestInfoMessage askInfoMessage = new BaseRequestInfoMessage(this.getPos(), baseID); PacketsMain.xcom.sendToServer(askInfoMessage); } else { XcomBase base = (XcomBase) XcomBaseCollection.getBaseCollection(worldObj).xcom_bases.get(this.associatedBaseID); this.associatedBase = base; BaseInfoMessage message = new BaseInfoMessage(base, this.getPos()); PacketsMain.xcom.sendToAllAround(message, new TargetPoint(this.getWorld().provider.getDimensionId(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 256.0D)); } this.markDirty(); } @Override public void tick() { if(this.isManufacturing()) { EngineeringProject eProj = this.currentProject; if(eProj.timeCost == 0) { this.endManufacturing(eProj); } else if(this.timeNeeded <= 0) { this.endManufacturing(eProj); } else { this.timeNeeded--; this.markDirty(); } } } public void startManufacturing(EngineeringProject project) { ItemStack[] needed = project.getMaterialsNeeded(); if(needed != null) { for(int l = 0; l < needed.length; l++) { int i1 = ((l + (needed.length * this.amount)) % (needed.length * this.amount)); int used = needed[i1].stackSize * this.amount - this.getStackInSlot(l).stackSize; if(used > 1) { ItemStack stack = new ItemStack(needed[i1].getItem(), used, needed[i1].getMetadata()); this.setInventorySlotContents(l, stack); } else { if(needed[i1].getItem() instanceof ItemAlienMaterials || needed[i1].getItem() instanceof ItemAlienTrophy) { used -= 64; } else { used--; } this.setInventorySlotContents(l, null); } } } if(project.timeCost == 0) { ItemStack[] output = project.getOutput(); if(output != null) { for(int l = 0; l < output.length * this.amount; l++) { int i1 = (l + output.length) % output.length; ItemStack stack; if(output[i1].getHasSubtypes()) { stack = new ItemStack(output[i1].getItem(), 1, output[i1].getMetadata()); } else { stack = new ItemStack(output[i1].getItem(), 1, 0); } this.setInventorySlotContents(l + 6, stack); } } } else { this.currentProject = project; this.timeNeeded = project.timeCost; this.isManufacturing = true; this.markDirty(); } } public void cancelManufacturing(EngineeringProject project) { if(worldObj.isRemote){ System.out.println("The cancelManufacturing method is being called clientSide."); } this.associatedBase.cash += project.getMoneyCost() * this.amount; for(int l = 0; l < 6; l++) { this.setInventorySlotContents(l, this.usingMaterials[l]); } this.isManufacturing = false; this.currentProject = null; this.markDirty(); } public void endManufacturing(EngineeringProject project) { if(worldObj.isRemote) { System.out.println("The endManufacturing method is being called clientside."); } int cashRefund = Utilities.roundDoubles(currentProject.getMoneyCost() * (this.associatedBase.numberWorkshops * 0.10 + this.associatedBase.engineeringAdjBonus)); this.associatedBase.cash += cashRefund; EngineeringProject eProj = this.currentProject; for(int l = 0; l < eProj.getOutput().length * amount; l++) { this.setInventorySlotContents(l + 6, eProj.getOutput()[(eProj.getOutput().length + l) % eProj.getOutput().length]); } this.currentProject = null; this.isManufacturing = false; this.markDirty(); } public int getRoomNeeded(EngineeringProject project) { ItemStack[] stack = project.getOutput(); int slotsNeeded = 0; for(int i2 = 0; i2 < stack.length; i2++) { int maxSize; if(stack[i2].getItem() instanceof ItemAlienMaterials || stack[i2].getItem() instanceof ItemAlienSpecies) { maxSize = 64; } else { maxSize = 1; } slotsNeeded += Math.ceil(amount/maxSize); } return slotsNeeded; } public void setAvailibleProjects() { if(this.worldObj.isRemote || this.associatedBase == null) { this.updateBaseInfo(associatedBaseID); } TileEntityResearchPanel rPanel = (TileEntityResearchPanel) this.worldObj.getTileEntity(associatedBase.rPos); List researched = rPanel.researchedProjects; this.availibleProjects.clear(); for(int i1 = 0; i1 < allProjects.size(); i1++) { ResearchProject needed = ((EngineeringProject) allProjects.get(i1)).getResearchNeeded(); if(needed == null) { this.availibleProjects.add(allProjects.get(i1)); } else { if(researched.contains(needed)) { this.availibleProjects.add(allProjects.get(i1)); } } } } public boolean isManufacturing() { return this.isManufacturing; } @Override public String getName() { return ""; } @Override public boolean hasCustomName() { return false; } @Override public int getSizeInventory() { return this.inventorySize; } @Override public ItemStack getStackInSlot(int index) { ItemStack[] stack = this.storedMaterials; if(index >= stack.length) { index -= 36; } return this.storedMaterials[index]; } @Override public ItemStack decrStackSize(int index, int count) { if(this.getStackInSlot(index) != null) { ItemStack stack; if(this.getStackInSlot(index).stackSize <= count) { stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); this.markDirty(); return stack; } else { stack = this.getStackInSlot(index).splitStack(count); if(this.getStackInSlot(index).stackSize <= 0) { this.setInventorySlotContents(index, null); } else { this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return stack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int index) { ItemStack stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); return stack; } @Override public void setInventorySlotContents(int index, ItemStack stack) { if(index < 0 || index >= this.getSizeInventory()) { return; } if (stack != null && stack.stackSize > this.getInventoryStackLimit()) stack.stackSize = this.getInventoryStackLimit(); if (stack != null && stack.stackSize == 0) stack = null; this.storedMaterials[index] = stack; this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return Utilities.getDistance(player.getPosition(), this.getPos()) < 8.0D; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) {} @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) {} @Override public int getFieldCount() { return 0; } @Override public void clear() { for(int i = 0; i < this.getSizeInventory(); i++) { this.setInventorySlotContents(i, null); } } @Override public void writeToNBT(NBTTagCompound nbtParent) { super.writeToNBT(nbtParent); nbtParent.setInteger("baseID", this.associatedBaseID); NBTTagList tag_list = new NBTTagList(); for(int l = 0; l < this.storedMaterials.length; ++l) { if(this.storedMaterials[l] != null) { NBTTagCompound item = new NBTTagCompound(); item.setInteger("slot", l); this.storedMaterials[l].writeToNBT(item); tag_list.appendTag(item); } } nbtParent.setTag("stored", tag_list); for(int l = 0; l < nbtParent.getTagList("stored", 10).tagCount(); l++) { NBTTagList list = nbtParent.getTagList("stored", 10); NBTTagCompound nbt = list.getCompoundTagAt(l); } } @Override public void readFromNBT(NBTTagCompound nbtParent) { super.readFromNBT(nbtParent); this.associatedBaseID = nbtParent.getInteger("baseID"); this.storedMaterials = new ItemStack[this.getSizeInventory()]; NBTTagList nbtList = (NBTTagList) nbtParent.getTag("stored"); if(nbtList != null) { for(int i1 = 0; i1 < nbtList.tagCount(); ++i1) { NBTTagCompound compound = nbtList.getCompoundTagAt(i1); int i2 = compound.getInteger("slot"); if(i2 >= 0 && i2 < this.inventorySize) { this.storedMaterials[i2] = ItemStack.loadItemStackFromNBT(compound); } } } } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { this.readFromNBT(packet.getNbtCompound()); } @Override public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); int meta = this.getBlockMetadata(); return new S35PacketUpdateTileEntity(this.getPos(), meta, nbt); } @Override public IChatComponent getDisplayName() { return new ChatComponentText("Engineering"); } } Gui Class: package com.littlepup.xcom.blocks.engineering_block; import java.util.List; import com.littlepup.xcom.packets.PacketsMain; import com.littlepup.xcom.packets.engineering.EngineerToServerMessage; import com.littlepup.xcom.projects.engineering.EngineeringProject; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiEngineerPanel extends GuiContainer { public GuiEngineerPanel(World world, EntityPlayer player, TileEntity tileEntity) { super(new ContainerEngineerPanel(world, player, tileEntity)); this.ePanel = (TileEntityEngineerPanel) tileEntity; EngineerToServerMessage updateProjectsMessage = new EngineerToServerMessage((TileEntityEngineerPanel) world.getTileEntity(ePanel.getPos()), -1, true); PacketsMain.xcom.sendToServer(updateProjectsMessage); this.availibleProjects = this.ePanel.availibleProjects; } private final ResourceLocation engineeringGui = new ResourceLocation("xcom:textures/gui/engineer_panel.png"); TileEntityEngineerPanel ePanel; List availibleProjects; @Override public void actionPerformed(GuiButton button) { EngineerToServerMessage message = null; switch(button.id) { case 0: message = new EngineerToServerMessage(this.ePanel, 0, false); break; case 1: message = new EngineerToServerMessage(this.ePanel, 1, false); break; case 2: this.ePanel.amount--; message = new EngineerToServerMessage(this.ePanel, 2, false); break; case 3: this.ePanel.amount++; message = new EngineerToServerMessage(this.ePanel, 3, false); break; case 4: this.ePanel.currentProjectID--; message = new EngineerToServerMessage(this.ePanel, 4, false); break; case 5: this.ePanel.currentProjectID++; message = new EngineerToServerMessage(this.ePanel, 5, false); break; default: message = new EngineerToServerMessage(); break; } PacketsMain.xcom.sendToServer(message); this.inventorySlots.detectAndSendChanges(); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(engineeringGui); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); } private void drawTimeRemaining(long ticks) { if(ticks != 0) { int days = MathHelper.floor_double(ticks / 24000); int min = MathHelper.floor_double((ticks - days * 24000)/1200); int sec = MathHelper.floor_double((ticks - (days * 24000 + min * 1200))/20); this.fontRendererObj.drawString("D: " + days, 130, 20, 80000); this.fontRendererObj.drawString("M: " + min, 130, 30, 80000); this.fontRendererObj.drawString("S: " + sec, 130, 40, 80000); } } @Override public void initGui() { super.initGui(); this.buttonList.add(new GuiButton(0, this.guiLeft + 45, this.guiTop + 15, 36, 12, "BEGIN")); this.buttonList.add(new GuiButton(1, this.guiLeft + 45, this.guiTop + 27, 36, 12, "CANCEL")); this.buttonList.add(new GuiButton(2, this.guiLeft + 45, this.guiTop + 39, 12, 12, "-")); this.buttonList.add(new GuiButton(3, this.guiLeft + 69, this.guiTop + 39, 12, 12, "+")); this.buttonList.add(new GuiButton(4, this.guiLeft + 85, this.guiTop + 58, 9, 12, "<")); this.buttonList.add(new GuiButton(5, this.guiLeft + 118, this.guiTop + 58, 9, 12, ">")); } @Override public void updateScreen() { super.updateScreen(); if(this.ePanel.isManufacturing()) { ((GuiButton)this.buttonList.get(0)).enabled = false; ((GuiButton)this.buttonList.get(1)).enabled = true; this.drawTimeRemaining(this.ePanel.currentProject.timeCost); } else { ((GuiButton)this.buttonList.get(0)).enabled = true; ((GuiButton)this.buttonList.get(1)).enabled = false; if(this.ePanel.currentProjectID == 0) { ((GuiButton)(this.buttonList.get(4))).enabled = false; } if(this.ePanel.currentProjectID == this.availibleProjects.size() - 1) { ((GuiButton)(this.buttonList.get(5))).enabled = false; } if(this.ePanel.currentProjectID != 0 && this.ePanel.currentProjectID != this.availibleProjects.size() - 1) { ((GuiButton)(this.buttonList.get(4))).enabled = true; ((GuiButton)(this.buttonList.get(5))).enabled = true; } if(this.ePanel.amount == 1) { ((GuiButton)(this.buttonList.get(2))).enabled = false; } else if(this.ePanel.getRoomNeeded((EngineeringProject) this.availibleProjects.get(ePanel.currentProjectID)) > 6) { ((GuiButton)(this.buttonList.get(3))).enabled = false; } else { ((GuiButton)(this.buttonList.get(2))).enabled = true; ((GuiButton)(this.buttonList.get(3))).enabled = true; } } } } Container Class: package com.littlepup.xcom.blocks.engineering_block; import com.littlepup.xcom.other.Utilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class ContainerEngineerPanel extends Container { public ContainerEngineerPanel(World world, EntityPlayer player, TileEntity tileEntity) { this.ePanel = (TileEntityEngineerPanel) tileEntity; worldObj = world; usingPlayer = player; playerInv = player.inventory; panelInv = (IInventory) tileEntity; ePanel = (TileEntityEngineerPanel) tileEntity; this.addSlots(); } World worldObj; IInventory playerInv; IInventory panelInv; EntityPlayer usingPlayer; TileEntityEngineerPanel ePanel; @Override public void addCraftingToCrafters(ICrafting crafting) { super.addCraftingToCrafters(crafting); crafting.func_175173_a(this, this.panelInv); } private void addSlots() { /*Slots 0-35 are the player's inventory * Note: since the engineer panel and player's inventory are * seperate, the slots can have the same ID if needed. * Slots 36-41 are the engineer panel's input * Slots 42-49 are the engineer panel's output */ //Player's non-hotbar inventory for(int x = 0; x < 9; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(playerInv, x * 3 + y, 8 + x * 18, 84 + y * 18)); } } //Player's hotbar inventory for(int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x + 27, 8 + x * 18, 142)); } //Engineer panel block's input inventory for(int x = 0; x < 2; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(panelInv, x * 3 + y + 36, 9 + x * 18, 16 + y * 18)); } } //Engineer panel block's output inventory for(int x = 0; x < 2; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(panelInv, x * 3 + y + 42, 133 + x * 18, 16 + y * 18)); } } } @Override public boolean canInteractWith(EntityPlayer player) { return Utilities.getDistance(player.getPosition(), ePanel.getPos()) < 8.0D; } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { ItemStack stack1 = null; Slot slot = this.getSlot(slotID); IInventory inventory = slot.inventory; if(slot != null && slot.getHasStack()) { ItemStack stack2 = slot.getStack(); stack1 = stack2.copy(); //The slot is in the tile entity if(slotID >= 36) { if(!this.mergeItemStack(stack1, 36, 50, false)) { return null; } } else if(!this.mergeItemStack(stack1, 36, 50, false)) { return null; } if(stack1.stackSize == 0) { this.putStackInSlot(slotID, null); } else { slot.onSlotChanged(); } } return stack1; } }
  5. I've been using this website and some of the linked ones. They've been very useful. http://jabelarminecraft.blogspot.com/
  6. Okay, I'll look into using the IMessage and IMessageHandler. Thanks for the help.
  7. There hasn't been any now that you mention it. I've been trying to use the writeToNBT and readFromNBT methods from the TileEntity class. Is that wrong? Should I be using the custom forge packets or something like that? Thanks for the help.
  8. I'm trying to make a tile entity that when one presses a button on it, it will make an item. Whenever I try to take the item or click it for that matter, it disappears. Also, I've been reading on how the "server" in Minecraft should handle everything to prevent hacking. I'm not sure if I'm doing that right and I was hoping for some help on resolving this issue with the items disappearing and just being sure that hacking won't happen with my mod. Thanks to anyone that helps. Block Class: package com.littlepup.xcom.blocks.engineering_block; import com.littlepup.xcom.XcomMain; import com.littlepup.xcom.packets.XcomGuiHandler; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class BlockEngineeringPanel extends BlockContainer { public BlockEngineeringPanel(Material materialIn) { super(materialIn); this.setBlockUnbreakable(); this.setCreativeTab(XcomMain.xcomTab); this.setUnlocalizedName("engineering_block"); } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityEngineerPanel(); } @Override public int getRenderType() { return 3; } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { player.openGui(XcomMain.instance, XcomGuiHandler.engineerPanelGui, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } } TileEntity Class package com.littlepup.xcom.blocks.engineering_block; import java.util.List; import com.google.common.collect.Lists; import com.littlepup.xcom.blocks.control_block.TileEntityControlPanel; import com.littlepup.xcom.blocks.research_block.TileEntityResearchPanel; import com.littlepup.xcom.items.ItemAlienMaterials; import com.littlepup.xcom.items.ItemAlienSpecies; import com.littlepup.xcom.items.ItemAlienTrophy; import com.littlepup.xcom.projects.EngineeringProject; import com.littlepup.xcom.projects.ResearchProject; import com.littlepup.xcom.projects.XcomEngineeringProjects; import com.littlepup.xcom.utilities.Utilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.server.gui.IUpdatePlayerListBox; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import net.minecraft.world.IInteractionObject; public class TileEntityEngineerPanel extends TileEntity implements IInventory, IUpdatePlayerListBox, IInteractionObject { public TileEntityEngineerPanel() { this.storedMaterials = new ItemStack[this.getSizeInventory()]; } public TileEntityControlPanel associatedBase; public ItemStack[] storedMaterials; private ItemStack[] usingMaterials = {null, null, null, null, null, null}; boolean isManufacturing = false; EngineeringProject currentProject; List allProjects = XcomEngineeringProjects.getEngineeringProjects(); List availibleProjects; long timeNeeded; int amount = 1; int assocX = -1; int assocY = -1; int assocZ = -1; public void setControlBlock(BlockPos pos) { this.assocX = pos.getX(); this.assocY = pos.getY(); this.assocZ = pos.getZ(); System.out.println("The associated block position is " + assocX + ", " + assocY + ", " + assocZ); this.worldObj.markBlockForUpdate(this.getPos()); this.markDirty(); } @Override public void update() { if(this.isManufacturing()) { EngineeringProject eProj = this.currentProject; if(eProj.timeCost == 0) { this.endManufacturing(eProj); } else if(this.timeNeeded <= 0) { this.endManufacturing(eProj); } else { this.timeNeeded--; } } } public void startManufacturing(EngineeringProject project) { ItemStack[] needed = project.getMaterialsNeeded(); if(needed != null) { for(int l = 0; l < needed.length; l++) { int i1 = ((l + (needed.length * this.amount)) % (needed.length * this.amount)); int used = needed[i1].stackSize * this.amount - this.getStackInSlot(l).stackSize; if(used > 1) { ItemStack stack = new ItemStack(needed[i1].getItem(), used, needed[i1].getMetadata()); this.setInventorySlotContents(l, stack); } else { if(needed[i1].getItem() instanceof ItemAlienMaterials || needed[i1].getItem() instanceof ItemAlienTrophy) { used -= 64; } else { used--; } this.setInventorySlotContents(l, null); } } } else { System.out.println("No materials were needed."); } if(project.timeCost == 0) { ItemStack[] output = project.getOutput(); if(output != null) { for(int l = 0; l < output.length * this.amount; l++) { int i1 = (l + output.length) % output.length; System.out.println("The value of the i1 variable is " + i1); ItemStack stack; if(output[i1].getHasSubtypes()) { stack = new ItemStack(output[i1].getItem(), 1, output[i1].getMetadata()); } else { stack = new ItemStack(output[i1].getItem(), 1, 0); } this.setInventorySlotContents(l + 6, stack); System.out.println("The tile entity slot " + l + " has a/an " + this.getStackInSlot(l + 6).getItem().getUnlocalizedName()); } } else { System.out.println("The project output is null."); } } else { this.currentProject = project; this.timeNeeded = project.timeCost; this.isManufacturing = true; this.worldObj.markBlockForUpdate(this.getPos()); this.markDirty(); } } public void cancelManufacturing(EngineeringProject project) { this.associatedBase.cash += project.getMoneyCost() * this.amount; for(int l = 0; l < 6; l++) { this.setInventorySlotContents(l, this.usingMaterials[l]); } this.isManufacturing = false; this.currentProject = null; } public void endManufacturing(EngineeringProject project) { int cashRefund = Utilities.roundDoubles(currentProject.getMoneyCost() * this.associatedBase.numberWorkshops * 0.10); this.associatedBase.cash += cashRefund; EngineeringProject eProj = this.currentProject; for(int l = 0; l < eProj.getOutput().length * amount; l++) { this.setInventorySlotContents(l + 6, eProj.getOutput()[(eProj.getOutput().length + l) % eProj.getOutput().length]); } this.currentProject = null; this.isManufacturing = false; } public int getRoomNeeded(EngineeringProject project) { ItemStack[] stack = project.getOutput(); int slotsNeeded = 0; for(int i2 = 0; i2 < stack.length; i2++) { int maxSize; if(stack[i2].getItem() instanceof ItemAlienMaterials || stack[i2].getItem() instanceof ItemAlienSpecies) { maxSize = 64; } else { maxSize = 1; } slotsNeeded += Math.ceil(amount/maxSize); } return slotsNeeded; } public List getAvailibleProjects() { System.out.println("The associatedBasePos coordinates are " + assocX + ", " + assocY + ", " + assocZ); this.associatedBase = (TileEntityControlPanel) this.worldObj.getTileEntity(new BlockPos(this.assocX, this.assocY, this.assocZ)); BlockPos rPanelL = new BlockPos(this.associatedBase.rPanelPosX, this.associatedBase.rPanelPosY, this.associatedBase.rPanelPosZ); List researched = ((TileEntityResearchPanel)(this.worldObj.getTileEntity(rPanelL))).researchedProjects; List projects = Lists.newArrayList(); for(int i1 = 0; i1 < allProjects.size(); i1++) { ResearchProject needed = ((EngineeringProject) allProjects.get(i1)).getResearchNeeded(); if(needed == null) { projects.add(allProjects.get(i1)); } else { if(researched.contains(needed)) { projects.add(allProjects.get(i1)); } } } return projects; } public boolean isManufacturing() { return this.isManufacturing; } @Override public String getName() { return ""; } @Override public boolean hasCustomName() { return false; } @Override public int getSizeInventory() { return 12; } @Override public ItemStack getStackInSlot(int index) { ItemStack[] stack = this.storedMaterials; if(index >= stack.length) { index -= 36; } return this.storedMaterials[index]; } @Override public ItemStack decrStackSize(int index, int count) { if(this.getStackInSlot(index) != null) { ItemStack stack; if(this.getStackInSlot(index).stackSize <= count) { stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); this.markDirty(); return stack; } else { stack = this.getStackInSlot(index).splitStack(count); if(this.getStackInSlot(index).stackSize <= 0) { this.setInventorySlotContents(index, null); } else { this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return stack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int index) { ItemStack stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); return stack; } @Override public void setInventorySlotContents(int index, ItemStack stack) { if(index < 0 || index > this.getSizeInventory()) { return; } if (stack != null && stack.stackSize > this.getInventoryStackLimit()) stack.stackSize = this.getInventoryStackLimit(); if (stack != null && stack.stackSize == 0) stack = null; this.storedMaterials[index] = stack; this.worldObj.markBlockForUpdate(this.getPos()); this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return Utilities.getDistance(player.getPosition(), this.getPos()) < 8.0D; } @Override public void openInventory(EntityPlayer player) {} @Override public void closeInventory(EntityPlayer player) {} @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) {} @Override public int getFieldCount() { return 0; } @Override public void clear() { for(int i = 0; i < this.getSizeInventory(); i++) { this.setInventorySlotContents(i, null); } } @Override public Container createContainer(InventoryPlayer pInventory, EntityPlayer player) { if(!this.worldObj.isRemote) { return new ContainerEngineerPanel(this.worldObj, player, this); } return null; } @Override public String getGuiID() { return "xcom:engineer_panel"; } @Override public void writeToNBT(NBTTagCompound nbtParent) { System.out.println("The writeToNBT is being called."); super.writeToNBT(nbtParent); nbtParent.setInteger("associatedX", this.assocX); nbtParent.setInteger("associatedY", this.assocY); nbtParent.setInteger("associatedZ", this.assocZ); System.out.println("The tile entity's nbt associated BlockPos is being set to " + this.assocX + ", " + this.assocY + ", " + this.assocZ); NBTTagList tag_list = new NBTTagList(); for(int l = 0; l < this.storedMaterials.length; ++l) { if(this.storedMaterials[l] != null) { NBTTagCompound item = new NBTTagCompound(); item.setInteger("slot", l); this.storedMaterials[l].writeToNBT(item); tag_list.appendTag(item); } else { System.out.println("The storedMaterial at " + l + " is null."); } } nbtParent.setTag("stored", tag_list); for(int l = 0; l < nbtParent.getTagList("stored", 10).tagCount(); l++) { NBTTagList list = nbtParent.getTagList("stored", 10); NBTTagCompound nbt = list.getCompoundTagAt(l); System.out.println("The item " + ItemStack.loadItemStackFromNBT(nbt).getItem().getUnlocalizedName() + " in slot " + l); } if(this.worldObj != null) { if(this.worldObj.isRemote) { System.out.println("This was all for a client tile entity."); } else { System.out.println("This was all for a server tile entity."); } } } @Override public void readFromNBT(NBTTagCompound nbtParent) { super.readFromNBT(nbtParent); this.assocX = nbtParent.getInteger("associatedX"); this.assocY = nbtParent.getInteger("associatedY"); this.assocZ = nbtParent.getInteger("associatedZ"); this.storedMaterials = new ItemStack[this.getSizeInventory()]; NBTTagList nbtList = (NBTTagList) nbtParent.getTag("stored"); if(nbtList != null) { System.out.println("The are " + nbtList.tagCount() + " tags in the list."); for(int i1 = 0; i1 < nbtList.tagCount(); ++i1) { NBTTagCompound compound = nbtList.getCompoundTagAt(i1); int i2 = compound.getInteger("slot"); System.out.println("The slot number is " + i2); if(i2 >= 0 && i2 < this.storedMaterials.length) { this.storedMaterials[i1] = ItemStack.loadItemStackFromNBT(compound); System.out.println("The itemstack is being loaded at slot" + i1); } } } else { System.out.println("The nbtList variable in readFromNBT is null."); } if(this.worldObj != null) { if(this.worldObj.isRemote) { System.out.println("This was all for a client tile entity."); } else { System.out.println("This was all for a server tile entity."); } } } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { this.readFromNBT(packet.getNbtCompound()); System.out.println("The onDataPacket method is done."); } @Override public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); int meta = this.getBlockMetadata(); System.out.println("The getDescriptionPacket method is almost done."); return new S35PacketUpdateTileEntity(this.getPos(), meta, nbt); } @Override public IChatComponent getDisplayName() { return new ChatComponentText("Engineering"); } } Gui Class: package com.littlepup.xcom.blocks.engineering_block; import java.util.List; import com.littlepup.xcom.projects.EngineeringProject; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Slot; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiEngineerPanel extends GuiContainer { public GuiEngineerPanel(World world, EntityPlayer player, TileEntity tileEntity) { super(new ContainerEngineerPanel(world, player, tileEntity)); this.ePanel = (TileEntityEngineerPanel) tileEntity; this.availibleProjects = this.ePanel.getAvailibleProjects(); System.out.println("The amount of availible projects is " + availibleProjects.size()); for(int l = 0; l < availibleProjects.size(); l++) { String title = ((EngineeringProject)this.availibleProjects.get(l)).getDescription()[0]; System.out.println("The availible projects are " + l + " " + title); } } private final ResourceLocation engineeringGui = new ResourceLocation("xcom:textures/gui/engineer_panel.png"); TileEntityEngineerPanel ePanel; int currentProjectID = 0; List availibleProjects; @Override public void actionPerformed(GuiButton button) { switch(button.id) { case 0: this.ePanel.startManufacturing((EngineeringProject)(availibleProjects.get(currentProjectID))); if(this.ePanel.getWorld().isRemote) { System.out.println("This is a client world."); } else { System.out.println("This is a server world."); } this.ePanel.markDirty(); System.out.println("The project " + ((EngineeringProject)(availibleProjects.get(currentProjectID))).getDescription()[0] + " has been decided on."); break; case 1: this.ePanel.cancelManufacturing((EngineeringProject)(availibleProjects.get(currentProjectID))); System.out.println("The project " + ((EngineeringProject)(availibleProjects.get(currentProjectID))).getDescription()[0] + "has been canceled."); break; case 2: this.ePanel.amount--; System.out.println("The new amount is " + this.ePanel.amount); break; case 3: this.ePanel.amount++; System.out.println("The new amount is " + this.ePanel.amount); break; case 4: this.currentProjectID--; System.out.println("The new project ID is " + this.currentProjectID); break; case 5: this.currentProjectID++; System.out.println("The new project ID is " + this.currentProjectID); break; } } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(engineeringGui); int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); } private void drawTimeRemaining(long ticks) { if(ticks != 0) { int days = MathHelper.floor_double(ticks / 24000); int min = MathHelper.floor_double((ticks - days * 24000)/1200); int sec = MathHelper.floor_double((ticks - (days * 24000 + min * 1200))/20); this.fontRendererObj.drawString("D: " + days, 130, 20, 80000); this.fontRendererObj.drawString("M: " + min, 130, 30, 80000); this.fontRendererObj.drawString("S: " + sec, 130, 40, 80000); } } @Override public void initGui() { super.initGui(); this.buttonList.add(new GuiButton(0, this.guiLeft + 45, this.guiTop + 15, 36, 12, "BEGIN")); this.buttonList.add(new GuiButton(1, this.guiLeft + 45, this.guiTop + 27, 36, 12, "CANCEL")); this.buttonList.add(new GuiButton(2, this.guiLeft + 45, this.guiTop + 39, 12, 12, "-")); this.buttonList.add(new GuiButton(3, this.guiLeft + 69, this.guiTop + 39, 12, 12, "+")); this.buttonList.add(new GuiButton(4, this.guiLeft + 85, this.guiTop + 58, 9, 12, "<")); this.buttonList.add(new GuiButton(5, this.guiLeft + 118, this.guiTop + 58, 9, 12, ">")); } @Override public void updateScreen() { super.updateScreen(); if(this.ePanel.isManufacturing()) { this.drawTimeRemaining(this.ePanel.currentProject.timeCost); } else { ((GuiButton)this.buttonList.get(1)).enabled = false; if(this.currentProjectID == 0) { ((GuiButton)(this.buttonList.get(4))).enabled = false; } else if(this.currentProjectID == this.availibleProjects.size() - 1) { ((GuiButton)(this.buttonList.get(5))).enabled = false; } else { ((GuiButton)(this.buttonList.get(4))).enabled = true; ((GuiButton)(this.buttonList.get(5))).enabled = true; } if(this.ePanel.amount == 1) { ((GuiButton)(this.buttonList.get(2))).enabled = false; } else if(this.ePanel.getRoomNeeded((EngineeringProject) this.availibleProjects.get(currentProjectID)) > 6) { ((GuiButton)(this.buttonList.get(3))).enabled = false; } else { ((GuiButton)(this.buttonList.get(2))).enabled = true; ((GuiButton)(this.buttonList.get(3))).enabled = true; } } } } Container Class: package com.littlepup.xcom.blocks.engineering_block; import com.littlepup.xcom.utilities.Utilities; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ContainerEngineerPanel extends Container { public ContainerEngineerPanel(World world, EntityPlayer player, TileEntity tileEntity) { this.ePanel = (TileEntityEngineerPanel) tileEntity; this.playerInv = player.inventory; this.panelInv = (IInventory) tileEntity; this.addSlots(); } IInventory playerInv; IInventory panelInv; TileEntityEngineerPanel ePanel; @Override public void addCraftingToCrafters(ICrafting crafting) { super.addCraftingToCrafters(crafting); crafting.func_175173_a(this, this.ePanel); } private void addSlots() { /*Slots 0-35 are the player's inventory * Note: since the engineer panel and player's inventory are * seperate, the slots can have the same ID if needed. * Slots 36-41 are the engineer panel's input * Slots 42-49 are the engineer panel's output */ //Player's non-hotbar inventory for(int x = 0; x < 9; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(playerInv, x * 3 + y, 8 + x * 18, 84 + y * 18)); } } //Player's hotbar inventory for(int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x + 27, 8 + x * 18, 142)); } //Engineer panel block's input inventory for(int x = 0; x < 2; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(panelInv, x * 3 + y + 36, 9 + x * 18, 16 + y * 18)); } } //Engineer panel block's output inventory for(int x = 0; x < 2; ++x) { for(int y = 0; y < 3; ++y) { this.addSlotToContainer(new Slot(panelInv, x * 3 + y + 42, 133 + x * 18, 16 + y * 18)); } } } @Override public boolean canInteractWith(EntityPlayer player) { return Utilities.getDistance(player.getPosition(), ePanel.getPos()) < 8.0D; } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { System.out.println("The transferStackInSlot is being called in the container."); ItemStack stack1 = null; Slot slot = this.getSlot(slotID); IInventory inventory = slot.inventory; if(slot != null && slot.getHasStack()) { ItemStack stack2 = slot.getStack(); stack1 = stack2.copy(); //The slot is in the tile entity if(slotID >= 36) { System.out.println("The slot is thought to be in the tile entity."); if(!this.mergeItemStack(stack1, 36, 50, false)) { System.out.println("The slot's itemstack cannot be merged."); return null; } } else if(!this.mergeItemStack(stack1, 36, 50, false)) { System.out.println("The slot's itemstack cannot be merged."); return null; } if(stack1.stackSize == 0) { System.out.println("The stack size is thought to be zero."); this.putStackInSlot(slotID, null); } else { slot.onSlotChanged(); } } return stack1; } }
  9. I am definitely not an experienced modder. That said though, if I were you, I would start be creating an entity for your black hole. Have it collect certain entities that are nearby and change their motion towards the black hole and same with the item entities. Considering what black holes do in real life it should also damage the entities nearby too maybe. You can add a counter to the black hole maybe to see how much stuff it has collected and have that add to the power of it. The closest vanilla thing to this idea would be in the explosion class in the world folder. It might be worthwhile to look there too. All this said, I'm not that experienced of a modder though. If someone else comes along that's more experienced, their advice would be worth way more than mine.
  10. I think I fixed it. There were too many metadata states. Thanks for pointing that out.
  11. Sorry, I'm kind of new to this. If it's not possible to get more than 16 different states in a block, I'll try fixing that first. I'm really only trying to get a different texture to show based off of the meta data and it will form a different shape based off of the blocks around it. Should I be just using the metadata for the texture only and changing the shape based off of the blocks around it maybe? Honestly, I'm really new to this.
  12. I've managed to get my metadata block into the game's creative tabs and it will go into the world with the game crashing. However, the game keeps giving me this message about my block model not being found. I've looked at some tutorials and tried troubleshooting the issue but I can't seem to get it to render in the game without the purple and black texture. I'm only trying to make the "undamaged" variant of the block right now and will work on the other variants once that one works. Here's the code: Error message: [12:13:34] [Client thread/ERROR] [FML]: Model definition for location xcom:alien_alloy_wall#damage_level=undamaged not found Block Class package com.littlepup.xcom.blocks; import java.util.List; import com.littlepup.xcom.XcomMain; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.Explosion; import net.minecraft.world.World; public class AlienAlloyWall extends Block implements IMetaBlockName { public AlienAlloyWall(Material material) { super(material); this.setUnlocalizedName("alien_alloy_wall"); this.setCreativeTab(XcomMain.xcomTab); this.setHardness(2.0F); this.setResistance(250.0F); this.setDefaultState(this.blockState.getBaseState().withProperty(DAMAGE_LEVEL, AlienAlloyWallTypes.UNDAMAGED)); } public static final PropertyEnum DAMAGE_LEVEL = PropertyEnum.create("damage_level", AlienAlloyWall.AlienAlloyWallTypes.class); //Contains different types of alien alloy blocks public enum AlienAlloyWallTypes implements IStringSerializable { UNDAMAGED(0, "undamaged"), SLIGHTLY_DAMAGED(1, "slightly_damaged"), SOMEWHAT_DAMAGED(2, "somewhat_damaged"), MODERATELY_DAMAGED(3, "moderately_damaged"), VERY_DAMAGED(4, "very_damaged"); private int ID; private String name; private AlienAlloyWallTypes(int ID, String name) { this.ID = ID; this.name = name; } @Override public String getName() { return name; } @Override public String toString() { return getName(); } public int getID() { return ID; } } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {DAMAGE_LEVEL}); } @Override public IBlockState getStateFromMeta(int meta) { AlienAlloyWallTypes type; switch(meta) { case 0: type = AlienAlloyWallTypes.UNDAMAGED; break; case 1: type = AlienAlloyWallTypes.SLIGHTLY_DAMAGED; break; case 2: type = AlienAlloyWallTypes.SOMEWHAT_DAMAGED; break; case 3: type = AlienAlloyWallTypes.MODERATELY_DAMAGED; break; case 4: type = AlienAlloyWallTypes.VERY_DAMAGED; break; default: type = null; System.out.println("AlienAlloyWall.getStateFromMeta() is having trouble."); break; } return getDefaultState().withProperty(DAMAGE_LEVEL, type); } @Override public int getMetaFromState(IBlockState state) { AlienAlloyWallTypes type = (AlienAlloyWallTypes) state.getValue(DAMAGE_LEVEL); return type.getID(); } @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); } public void getSubBlocks(Item item, CreativeTabs tab, List list) { for(int i = 0; i < 5; i++ ) { list.add(new ItemStack(item, 1, i)); } } @Override public String getSpecialName(ItemStack stack) { int meta = stack.getItemDamage(); String type; switch(meta) { case 0: type = AlienAlloyWall.AlienAlloyWallTypes.UNDAMAGED.toString(); break; case 1: type = AlienAlloyWall.AlienAlloyWallTypes.SLIGHTLY_DAMAGED.toString(); break; case 2: type = AlienAlloyWall.AlienAlloyWallTypes.SOMEWHAT_DAMAGED.toString(); break; case 3: type = AlienAlloyWall.AlienAlloyWallTypes.MODERATELY_DAMAGED.toString(); break; case 4: type = AlienAlloyWall.AlienAlloyWallTypes.VERY_DAMAGED.toString(); break; default: type = null; System.out.println("Error in AlienAlloyWall enum types."); break; } return type; } @Override public boolean isOpaqueCube() { return false; } @Override public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { EnumFacing direction = placer.getHorizontalFacing().rotateY(); AlienAlloyWallTypes type = (AlienAlloyWallTypes) getStateFromMeta(meta).getValue(DAMAGE_LEVEL); return super.onBlockPlaced(world, pos, direction, hitX, hitY, hitZ, meta, placer).withProperty(DAMAGE_LEVEL, type); } @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos) { return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos))); } @Override public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) { IBlockState state = world.getBlockState(pos); int meta = getMetaFromState(state); IBlockState newType = state.cycleProperty(DAMAGE_LEVEL); if(meta <= 3) { world.setBlockState(pos, newType); } else { world.setBlockToAir(pos); } } } Blockstates json file { "variants": { "damage_level=undamaged,facing=up": { "model": "xcom:alien_alloy_wall_undamaged" }, "damage_level=undamaged,facing=down": { "model": "xcom:alien_alloy_wall_undamaged", "x": 180}, "damage_level=undamaged,facing=east": { "model": "xcom:alien_alloy_wall_undamaged", "x": 90 }, "damage_level=undamaged,facing=west": { "model": "xcom:alien_alloy_wall_undamaged", "x": 270 }, "damage_level=undamaged,facing=north": { "model": "xcom:alien_alloy_wall_undamaged", "y": 90 }, "damage_level=undamaged,facing=south": { "model": "xcom:alien_alloy_wall_undamaged", "y": 270 } } } Registration public final class BlocksMain { public static Block alien_alloy_wall = new AlienAlloyWall(Material.iron); public static void addMetadataBlocks() { GameRegistry.registerBlock(alien_alloy_wall, MetaBlocks.class, "alien_alloy_wall"); } public static void addMetadataBlockRenderers() { //Meta-data-block model name variations ModelBakery.addVariantName(Item.getItemFromBlock(BlocksMain.alien_alloy_wall), "xcom:alien_alloy_wall_undamaged"); //Registers the block renderer(s) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(alien_alloy_wall), 0, new ModelResourceLocation(XcomMain.MODID + ":" + "alien_ally_wall_undamaged", "inventory")); } } Thanks to anyone who helps.
  13. Thank you for the help. Although I'm still confused on how to get the metadata value from the entity class to the render class I am using. If this is just a java question I won't push anyone, but I really am stumped on how to get that value into the render class.
  14. Sorry to bother people again, but I was having some of the same troubles with the IEntityAdditionalSpawnData in terms of the value having 0 no matter what. If this is a java question I won't push you on it but I was wondering how I would get the classes to sync. Also, is there anything else I'm doing wrong here? Here is the render class (embarrassed that happened) and the new entity class. Entity class: package com.littlepup.xcom_mod.entities; import io.netty.buffer.ByteBuf; import java.util.Iterator; import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import com.littlepup.xcom_mod.items.ItemGrenades; import com.littlepup.xcom_mod.items.ItemsMain; import com.littlepup.xcom_mod.other.Utilities; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; public class XcomEntityGrenade extends EntityThrowable implements IEntityAdditionalSpawnData { int x, y, z; Block block; int ticksInGround; int ticksInAir; int metadata; public XcomEntityGrenade(World world) { super(world); } public XcomEntityGrenade(World world, EntityLivingBase entityLivingBase, int metadataL) { super(world, entityLivingBase); this.metadata = metadataL; } public XcomEntityGrenade(World world, double posX, double posY, double posZ) { super(world, posX, posY, posZ); } @Override protected void onImpact(MovingObjectPosition moveObjPos) { x = moveObjPos.blockX; y = moveObjPos.blockY; z = moveObjPos.blockZ; } @Override public void writeSpawnData(ByteBuf addedData) { addedData.capacity(addedData.capacity() + 10); addedData.writerIndex(addedData.capacity() - 10); addedData.writeInt(this.metadata); addedData.writerIndex(addedData.writerIndex() - 1); System.out.println("entity written data " + metadata); } @Override public void readSpawnData(ByteBuf addedData) { addedData.readerIndex(addedData.capacity() - 10); int l = addedData.getInt(addedData.readerIndex()); System.out.println("entity written data " + l); } } Render class (basically the same as render snowball) package com.littlepup.xcom_mod.renderers; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.EntityPotion; import net.minecraft.item.Item; import net.minecraft.item.ItemPotion; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionHelper; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.littlepup.xcom_mod.items.ItemGrenades; import com.littlepup.xcom_mod.items.ItemsMain; import com.littlepup.xcom_mod.other.Utilities; @SideOnly(Side.CLIENT) public class RenderGrenade extends Render { private int metadata; Item grenades = ItemsMain.grenades; public RenderGrenade() { } public void doRender(Entity entity, double d1, double d2, double d3, float f, float f1) { IIcon iicon = grenades.getIconFromDamage(metadata); System.out.println("metadata from render class" + metadata); if (iicon != null) { GL11.glPushMatrix(); GL11.glTranslatef((float)d1, (float)d2, (float)d3); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glScalef(0.5F, 0.5F, 0.5F); this.bindEntityTexture(entity); Tessellator tessellator = Tessellator.instance; this.func_77026_a(tessellator, iicon); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); } } /** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(Entity entity) { return TextureMap.locationItemsTexture; } private void func_77026_a(Tessellator p_77026_1_, IIcon p_77026_2_) { float f = p_77026_2_.getMinU(); float f1 = p_77026_2_.getMaxU(); float f2 = p_77026_2_.getMinV(); float f3 = p_77026_2_.getMaxV(); float f4 = 1.0F; float f5 = 0.5F; float f6 = 0.25F; GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); p_77026_1_.startDrawingQuads(); p_77026_1_.setNormal(0.0F, 1.0F, 0.0F); p_77026_1_.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3); p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3); p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2); p_77026_1_.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2); p_77026_1_.draw(); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.