Jump to content

Cephrus

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by Cephrus

  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)?
  15. I made the changes to only use ItemStack but it still doesn't display the int[] values in game.
  16. I really don't think HashMap wants to work for me. public static Map<Object, Integer[]> atomicMass = new HashMap<Object, Integer[]>(); public static void registerItem(Item item, int protons, int neutrons, int electrons) { //registerItem(item, new AtomicMass(protons, neutrons, electrons)); Integer[] i = new Integer[5]; i[1] = protons; i[2] = neutrons; i[3] = electrons; i[4] = protons + neutrons; atomicMass.put(item, i); } This is the code I am currently using. I create a HashMap/Map to store the item Object and the proton/neutron/electron/mass Integer[] values. I use the method also there to register items into this HashMap at PreInit. I also use a similar method for Blocks and ItemStacks, the only difference being the Item changes. @SubscribeEvent public void tooltip(ItemTooltipEvent event) { Integer[] mval = AtomicRegister.getStuffies(event.itemStack); if(mval != null) { event.toolTip.add("Atomic Mass: " + mval[4]); event.toolTip.add("Protons: " + mval[1]); event.toolTip.add("Neutrons: " + mval[2]); event.toolTip.add("Electrons: " + mval[3]); } } I then use an event to try to post these values to a tooltip. However, the NullPointerException occurs on the first tooltip adding line "event.toolTip.add("Atomic Mass: " + mval[4]);" I added the !=null check to stop this, but now the tooltip doesn't show up even on the Items/Blocks I had registered.
  17. I'm creating a mod, and in order for me to control it I want to stop any mod from altering it's recipes or functions. I want to see if a mod is altering the crafting array, and which mod is doing it. My current setup involves cloning the list and storing it in a separate class during pre-initialization, then during initialization check to see if they are the same. The problem with that solution is it's unclear which mod is altering the array, and also mods may add their own recipes during pre-initialization, which would indicate a flaw. Also, if the mod that alters the array loads before my mod, then the clone of the array will be the same as the altered array, meaning that the mod could get around the checks. How would I go about doing this while allowing mods that add recipes during pre-init (which they shouldn't be doing) not trigger the check?
  18. Yea I probably did. package tk.cephlab.supernatural; import java.util.HashMap; import java.util.logging.Level; import org.lwjgl.input.Keyboard; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; /** * Custom Player Handler Class * * This class is used for registering any custom handles for the player who * currently is supernatural. * * TL;DR: Pretty much it adds the features of a supernatural to the player when * they are supernatural. * * @author XCephrusX * */ public class SupernaturalPlayerHandler { public HashMap<SupernaturalPlayerHandler, String> superMap = new HashMap<SupernaturalPlayerHandler, String>(); public HashMap<EntityPlayer, SupernaturalPlayerHandler> playerToSupernatural = new HashMap<EntityPlayer, SupernaturalPlayerHandler>(); public static SupernaturalPlayerHandler playerHandler; public static final SupernaturalPlayerHandlerVampire supernaturalVampire = new SupernaturalPlayerHandlerVampire(); public SupernaturalPlayerHandler(String name) { this.superMap.put(this, name); playerHandler = this; } /** * DO NOT USE THIS CONSTRUCTOR! IT IS ONLY USED FOR INITIALIZATION! */ public SupernaturalPlayerHandler() { playerHandler = this; } public static SupernaturalPlayerHandler instance() { if(playerHandler != null) { return playerHandler; } else return null; } /** * * Converts specified player into supernatural handler specified. * Requires EntityPlayer class, and SupernaturalPlayerHandler. * * @param player * @param playerHandler */ public void convertPlayerToSupernatural(EntityPlayer player, SupernaturalPlayerHandler playerHandler) { player.addChatMessage("Conversion invoked"); if(!this.playerToSupernatural.containsKey(player)) { this.playerToSupernatural.put(player, playerHandler); player.addChatMessage("Player should be converted."); } else { System.out.println(Level.FINER + "Player is already supernatural, cannot add new supernatural tag to this player."); } } public boolean getIsPlayerSupernatural(EntityPlayer player) { return this.playerToSupernatural.containsKey(player); } public boolean getIsPlayerSupernatural(EntityPlayer player, SupernaturalPlayerHandler handler) { if(this.playerToSupernatural.containsKey(player)) { if(this.playerToSupernatural.get(player) == handler) { return true; } } return false; } public void onTick(Minecraft minecraft) { EntityPlayer player = minecraft.thePlayer; if(this.playerToSupernatural.get(player) !=null) { this.playerToSupernatural.get(player).handlePlayer(player, minecraft); } } public void handlePlayer(EntityPlayer player, Minecraft minecraft) { if(Keyboard.isKeyDown(Keyboard.KEY_ADD) && this.getIsPlayerSupernatural(player)) { player.addChatMessage(player.username + " is a " + this.superMap.get(this.playerToSupernatural.get(player)) + "."); } else if(Keyboard.isKeyDown(Keyboard.KEY_ADD) && !this.getIsPlayerSupernatural(player)) { player.addChatMessage(player.username + "is a human."); } } public static void initializePlayerHandler() { SupernaturalPlayerHandler init = new SupernaturalPlayerHandler(); } }
  19. So in my mod I have a method being called. This method takes the instance of EntityPlayer and also a class (which extends my other class) and adds it to a hashmap. Then, in a method which is executed every tick, it determines whether the instance of the player is in the hashmap, and if it is, gets the class from the hashmap and executed the handlePlayer(EntityPlayer, Minecraft) from it. From there the handlePlayer method will handle certain custom capabilities which the player can do. I have an in-game command which I execute that is supposed to call the method which puts the player and class into the hashmap. I put several println(')'s into several places into the code to determine where the code is faulting. I ultimately determined the code faults on the method that detects the player in the hashmap and executes handlePlayer. I determined the onTickInGame method is in fact working, it's just the getting of the class from the hashmap and the execution of the handlePlayer method which is not.
  20. I added the override to my class and when I tested the override out it stopped rendering the whole world for a split second then crashed with several NullPointerExceptions. This is the code eclipse pointed me to which was causing the exceptions (apparently) Code: if(myClass.instance().myMethod(playerBeingRendered, myOtherClass.instance())) Which returns a boolean if the player has a trait I assign in a different class.
  21. I added the override to my class and when I tested the override out it stopped rendering the whole world for a split second then crashed with several NullPointerExceptions. This is the code eclipse pointed me to which was causing the exceptions (apparently) if(myClass.instance().myMethod(playerBeingRendered, myOtherClass.instance())) Which returns a boolean if the player has a trait I assign in a different class.
  22. There is no javadoc on RenderPlayerEvent.Pre, so would .entityPlayer be the player rendering, or the player whose client is rendering the player? If not, how would I determine which player is rendering the other player?
  23. I need to stop rendering the whole player, but only to certain players.
×
×
  • Create New...

Important Information

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