Jump to content

Cephrus

Members
  • Posts

    31
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed

Cephrus's Achievements

Tree Puncher

Tree Puncher (2/8)

-2

Reputation

  1. Sorry if this question is stupid, I'm a noob at containers. I made an IInventory TileEntity and Container for it and I am experiencing some issues with them. I was following the forge Container guide on the wiki. The main issue is that whenever I add over 9 slots to my inventory, picking up an item instantly returns it to the slot it came from. The inventory has no problem with the first 9, but as soon as I add the tenth, it stops working and doesn't allow items to be moved in its inventory. I am unsure of the cause of this issue. Another weird issue I'm having is right clicking to halve the stack while in the inventory gives whatever the starting item was, and sometimes buttons (when I test with stone). TileEntity package net.cephlab.nm.core.research; 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.tileentity.TileEntity; public class TileEntityResearchTable extends TileEntity implements IInventory { public String customName; public ItemStack[] inventory = new ItemStack[13]; @Override public int getSizeInventory() { return 13; } @Override public ItemStack getStackInSlot(int slot) { return inventory[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack itemStack = getStackInSlot(slot); if (itemStack != null) { if (itemStack.stackSize <= amount) { setInventorySlotContents(slot, null); } else { itemStack = itemStack.splitStack(amount); if (itemStack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return itemStack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { if (inventory[slot] != null) { ItemStack itemStack = inventory[slot]; inventory[slot] = null; return itemStack; } else { return null; } } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inventory[slot] = stack; if(stack != null && stack.stackSize > this.getInventoryStackLimit()) stack.stackSize = this.getInventoryStackLimit(); this.markDirty(); } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory", 0); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound)tagList.getCompoundTagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inventory.length) { inventory[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inventory.length; i++) { ItemStack stack = inventory[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? customName : "researchTable"; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public void openInventory() {} @Override public void closeInventory() {} @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return true; } } Container package net.cephlab.nm.core.research; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerResearcher extends Container { protected TileEntityResearchTable te; public ContainerResearcher(InventoryPlayer inv, TileEntityResearchTable tile) { this.te = tile; this.addSlots(); this.bindPlayerInventory(inv); } @Override public boolean canInteractWith(EntityPlayer player) { return te.isUseableByPlayer(player); } protected void addSlots() { int tmp = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { tmp++; if(tmp > 9) break; addSlotToContainer(new Slot(te, tmp, 62 + j * 18 + 35, 17 + i * 18 - 2)); } } //addSlotToContainer(new Slot(te, 10, 62 + 18 / 3 + 4, 17 + 18 / 3 - ); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 9)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + 9)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); if (slot < te.getSizeInventory()) { if (!this.mergeItemStack(stackInSlot, te.getSizeInventory(), 36 + te.getSizeInventory(), true)) { return null; } } else if (!this.mergeItemStack(stackInSlot, 0, te.getSizeInventory(), false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } return stack; } } Any help is appreciated.
  2. I need to change the size of the sun/moon over time in my mod. From my understanding this is not possible without ASM and modifying the RenderGlobal class. Are there any ways/special renders I can implement that will allow me to avoid ASM when changing the global render? And is it possible to add/remove objects from the sky in the global render? Any and all help is appreciated, -Ceph
  3. 10.13.2.1230 and by using GameRegistry.registerTileEntity() in my preInit method.
  4. I'm adding a series of blocks in my mod that will essentially allow one to wirelessly power RF blocks. I have a couple problems with the code, however. I have this code in one tile (the one powering the block): public void updateTargets() // Updates provider and other blocks in series. { targets.clear(); for(int xOffset = -5; xOffset < 6; xOffset++) { for(int yOffset = -5; yOffset < 6; yOffset++) { for(int zOffset = -5; zOffset < 6; zOffset++) { TileEntity te = worldObj.getTileEntity(xCoord - xOffset, yCoord - yOffset, zCoord - zOffset); if(te != null && te instanceof IRFLaserTarget) { if(te != this) { targets.add((IRFLaserTarget)te); ((IRFLaserTarget)te).updateTargets(); } } else if(te instanceof TileEntityRFLaser) { System.out.println("Found Provider"); provider = (TileEntityRFLaser)te; } } } } } @Override public void updateEntity() // Powers block { for(int xOffset = -3; xOffset < 4; xOffset++) { for(int yOffset = 0; yOffset < -5; yOffset--) { for(int zOffset = -1; zOffset < 1; zOffset++) { TileEntity tile = worldObj.getTileEntity(xCoord - xOffset, yCoord - yOffset, zCoord - zOffset); if(tile instanceof IEnergyReceiver) { if(((IEnergyReceiver)tile).receiveEnergy(ForgeDirection.DOWN, 8000, true) != 0 && provider.storage.extractEnergy(((IEnergyReceiver)tile).receiveEnergy(ForgeDirection.DOWN, 8000, true), true) != 0) { provider.storage.extractEnergy(((IEnergyReceiver)tile).receiveEnergy(ForgeDirection.DOWN, 8000, false), false); } } } } } } The updateEntity() method never executes. I've tried System.out.println()s in several spots and there is nothing happening. I do have my tiles registered and a block for each tile.
  5. I need a way to disable grass growth for my mod. The reason for this is I need to periodically replace grass with dirt, which inevitably grows back into grass. To my knowledge there is no event for this, and I am struggling with determining a way to do this without asm.
  6. Substituting the RNG for randX and randZ also does nothing. By adding a println() call to the grass if() statement produces more action with the RNG than randX and randZ. But nothing happens in the world.
  7. I have this code that executes each worldtick: Random random = new Random(); int randX = random.nextInt(16); //int randY = random.nextInt(256); int randZ = random.nextInt(16); int randY = EAToolkit.getTopBlock(world, randX, randZ); int j1 = random.nextInt(); int i2 = MathHelper.floor_double(focusPlayer.posX); int k2 = MathHelper.floor_double(focusPlayer.posZ); byte byte0 = 7; for(int i3 = -byte0; i3 <= byte0; i3++) { for(int k3 = -byte0; k3 <= byte0; k3++) { int l3 = i3 * 16 + i2; int i4 = k3 * 16 + k2; j1 = j1 * 3 + 0x3c6ef35f; int j4 = j1 >> 2; int k4 = j4 & 0xf; int l4 = j4 >> 8 & 0xf; int i5 = k4 + l3; int j5 = l4 + i4; if(phase >= 1) { blockBuffer++; if(blockBuffer >= 60) { BlockPos blk = new BlockPos(randX, randY, randZ); Chunk chunk = world.getChunkFromChunkCoords(i5 + (int)focusPlayer.posX, j5 + (int)focusPlayer.posZ); Block block = chunk.getBlock(blk); if(block == Blocks.grass) { chunk.setBlockState(blk, Blocks.dirt.getDefaultState()); } if(block == Blocks.leaves) { chunk.setBlockState(blk, Blocks.air.getDefaultState()); } blockBuffer = 0; } } } } It is supposed to get a random block near the player, and if it is either leaves or grass, change the block to air or dirt. However, the code doesn't seem to be working. I have put debug System.out.println() calls in the code for the grass, and it does work, but no grass changes. Any and all help is appreciated.
  8. I have started using WorldServer instead of World for my tickhandler, but MinecraftServer.worldServers has nothing in it. It returns ArrayIndexOutOfBounds for whatever number I put in, and if I use a for() loop to get the first WorldServer I can it always uses the default null variable.
  9. My Tick event: @SubscribeEvent public void onServerTick(TickEvent.ServerTickEvent event) { EAPlugin.internalTick(); for(EAPluginContainer plugin : EALoader.instance().loadedPlugins) { plugin.plugin.onTick(); } } And the code that changes blocks: @Override public void onTick() { if(day <= 4) phase = day; else phase = 4; try { minecraft.theWorld.setBlockState(new BlockPos(minecraft.thePlayer.posX, minecraft.thePlayer.posY, minecraft.thePlayer.posZ), Blocks.dirt.getDefaultState()); } catch(Exception e) { System.err.println("Errorino"); } Random random = new Random(1337); int randX = random.nextInt(); int randZ = random.nextInt(); int randY = EAToolkit.getTopBlock(minecraft.theWorld, randX, randZ); try { if(phase == 1) { blockBuffer++; if(blockBuffer >= 20) { Block block = minecraft.theWorld.getChunkFromChunkCoords(randX, randZ).getBlock(randX, randY, randZ); if(block == Blocks.grass) { minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.dirt.getDefaultState()); } if(block == Blocks.leaves) { minecraft.theWorld.setBlockState(new BlockPos(randX, randY, randZ), Blocks.air.getDefaultState()); } } } } catch(Exception e) { e.printStackTrace(); } } The first setBlockState call is for testing purposes, and right clicking the dirt that is created makes it disappear, breaking it in survival doesn't drop anything but still makes the sound, and world reload removes all dirt and resets my spawn.
  10. I'm currently using the method World.setBlockState() to change blocks in the world. However, these blocks disappear when you right click or reload the world. I'm guessing this has something to do with server/client synchronization, but I don't know for sure. I am using a Server-side Tickhandler.
  11. Switching to using modId is still not working. package tk.cephlab.ea.internal; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; import net.minecraft.world.storage.MapStorage; import tk.cephlab.ea.EALoader; import tk.cephlab.ea.api.EAPlugin; public class EAWorldData extends WorldSavedData { public EAWorldData(String s) { super(s); } public EAWorldData() { super("EAWorldData"); } public static EAWorldData forWorld(World world) { MapStorage storage = world.getPerWorldStorage(); EAWorldData returnable = (EAWorldData)storage.loadData(EAWorldData.class, "EAWorldData"); if(returnable == null) { returnable = new EAWorldData(); storage.setData("EAWorldData", returnable); } return returnable; } @Override public void readFromNBT(NBTTagCompound nbt) { EAPlugin.day = nbt.getInteger("eaDays"); System.out.println("READ"); for(EAPluginContainer plugin : EALoader.instance().getPluginList()) { if(nbt.getString("loadedPlugin" + EALoader.instance().getPluginList().indexOf(plugin)) == null) continue; if(nbt.getString("loadedPlugin" + plugin.container.getModId()) == plugin.container.getModId()) { System.out.println("Loaded"); EALoader.instance().initPlugin(plugin); } } for(EAPluginContainer plugin : EALoader.instance().loadedPlugins) { plugin.plugin.phase = nbt.getInteger(plugin.plugin.getIdentifier() + "_phase"); } } @Override public void writeToNBT(NBTTagCompound nbt) { nbt.setInteger("eaDays", EAPlugin.day); System.out.println("WRITE"); for(EAPluginContainer plugin : EALoader.instance().loadedPlugins) { nbt.setInteger(plugin.plugin.getIdentifier() + "_phase", plugin.plugin.phase); nbt.setString("loadedPlugin" + plugin.container.getModId(), plugin.container.getModId()); } } }
  12. I have a class that extends WorldSavedData in my mod. This class saves data to the NBT telling my mod which components of it to load for each specific world. When I create a world initially, the components that need to load will load. Upon restarting the world, but not Minecraft, the components load again. However, upon a Minecraft restart, the components no longer work. The code for my WorldSavedData class is below: package tk.cephlab.ea.internal; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.WorldSavedData; import tk.cephlab.ea.EALoader; import tk.cephlab.ea.api.EAPlugin; public class EAWorldData extends WorldSavedData { public EAWorldData() { super("EAWorldData"); } @Override public void readFromNBT(NBTTagCompound nbt) { EAPlugin.day = nbt.getInteger("eaDays"); for(EAPlugin plugin : EALoader.instance().getPluginList()) { if(nbt.getString("loadedPlugin" + EALoader.instance().getPluginList().indexOf(plugin)) == null) continue; if(nbt.getString("loadedPlugin" + EALoader.instance().getPluginList().indexOf(plugin)) == plugin.getIdentifier()) { System.out.println("Loaded"); EALoader.instance().initPlugin(plugin); } } for(EAPlugin plugin : EALoader.instance().loadedPlugins) { plugin.phase = nbt.getInteger(plugin.getIdentifier() + "_phase"); } } @Override public void writeToNBT(NBTTagCompound nbt) { nbt.setInteger("eaDays", EAPlugin.day); for(EAPlugin plugin : EALoader.instance().loadedPlugins) { nbt.setInteger(plugin.getIdentifier() + "_phase", plugin.phase); nbt.setString("loadedPlugin" + EALoader.instance().loadedPlugins.indexOf(plugin), plugin.getIdentifier()); } } } Any and all help is appreciated.
  13. How would I go about giving functionality to that button?
  14. I need to add a button to the vanilla GUI class GuiCreateWorld. In order to add this button, I need to move the Survival/Hardcore/Creative button out of the way. How would I go about doing this (preferably without ASM)?
×
×
  • Create New...

Important Information

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