Jump to content

feldim2425

Members
  • Posts

    19
  • Joined

  • Last visited

Everything posted by feldim2425

  1. I don't know if thats a good solution but the way I do it, I give the Y argument a negative number when calling the player.openGui(...) so the Y value in getClientGuiElement() is also negative. (TE's & Blocks should not exist at a negative Y Coordinate) So the X can be set to entity.getEntityId(). And you can get the Entity Object back by calling world.getEntityByID(x) @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(y==-10 && ID == 0){ Entity entity = world.getEntityByID(x); if(entity!=null){ return new EntityGuiContainer(entity) } } return null; } Open with: player.openGui(Mod.instance, 0, world, entity.getEntityId(), -10 , 0);
  2. No the Capabilities are for stuff thats similar to other tile entities and stuff that should be compatible with other mods (like Inventory, FluidTank , ...) Normal data (as you sayed some integer and booleans) are still stored in NBT with the writeToNBT() and readFromNBT() method
  3. Let the BlockEnergyGeneratorCoal class extend BlockContainer and not Block.
  4. I forgot to say, that I want use dynamic colors. If this is possible EDIT: Forgot that it's possible to set a color overlay
  5. Hi. I want to render a gradient rectangle in the world but it doesn't render the gradient. render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); render.pos(length, -beamWidth, beamWidth).color(r2, g2, b2, alpha).endVertex(); render.pos(length, beamWidth, beamWidth).color(r2, g2, b2, alpha).endVertex(); render.pos(0, beamWidth, beamWidth).color(r, g, b, alpha).endVertex(); render.pos(0, -beamWidth, beamWidth).color(r, g, b, alpha).endVertex(); tes.draw(); How can I render a gradient rectangle in the world with the Tessellator and the WorldRenderer?
  6. You also have a problem in the switch-case. You have to check if the id from the getClientGuiObject (id is the first integer value) is equal to your GUI id (you choose 6) switch(id){ case 6: //6 is the GUI id. return new GuiJournalThree(); } return null;
  7. In my code the init function shuold get called in the preInit function in the Main Mod class or in the common proxy.
  8. Does the id is equal to the id from the switch-case in the getClientGuiElement() function? Have you registred the Gui handler? Maybe you also need to check the side, because the Server element is null.
  9. Something like this should work: public class GuiHandler implements IGuiHandler{ public static void init(){ NetworkRegistry.INSTANCE.registerGuiHandler(<Mod instance>, new GuiHandler()); } @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch(id){ case 0: return new GuiJournalThree(); } return null; } }
  10. If nothing works, you can try a GUIHandler and open the gui with player.openGui(<Mod instance>, <GUI-ID>, world, 0, 0, 0); But this is also Server Side. EDIT: Can you post the last crash report / log file?
  11. onItemRightClick() is also called on the ServerSide. On the Server Side Minecraft.getMinecraft().displayGuiScreen() doesn't work. Try: if(world.isRemote){ Minecraft.getMinecraft().displayGuiScreen(new GuiJournalThree()); } return itemstack;
  12. I found the problem it seems like withProperty() for the IUnlistedProperty doesn't change the state, it just returns the new state. For everyone who has the same problem, here is the new method: public IBlockState getExtendedState(IBlockState state) { checkConnections(); return ((IExtendedBlockState) state).withProperty(PROPERTY_CONNECTION, this.connections).withProperty(PROPERTY_TYPE, this.type); } I also use a unlisted Byte property, where the first 6 bits are the 6 sides of the block.
  13. I have a MCMultipart cable. I can write the 6 directions to the Extendet Blockstate without problem, but if I get the Property Value, the function returns null. Cable Class public class PartRfCable extends Multipart implements IOccludingPart, ISlottedPart, ITickable, IEnergyHandler { public static IUnlistedProperty<Boolean>[] sides = PropertyCableConnection.getPropertyList(); public static IProperty<EnumCableType> cableType = new EnumCableType.PropertyCableType(); private HashMap<EnumFacing, Boolean> connections = new HashMap<>(); private boolean updateDone; private EnumCableType type; public PartRfCable(EnumCableType type){ super(); this.type=type; } public PartRfCable(){ super(); } @Override public void addOcclusionBoxes(List<AxisAlignedBB> list) { list.add(AxisAlignedBB.fromBounds(0,0,0,1,1,1)); } @Override public void addSelectionBoxes(List<AxisAlignedBB> list) { list.add(AxisAlignedBB.fromBounds(4F/16F,4F/16F,4F/16F,12F/16F,12F/16F,12F/16F)); } @Override public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) { list.add(AxisAlignedBB.fromBounds(0,0,0,1,1,1)); } @Override public void update() { if(!updateDone){ //onLoaded() gets called before other TE's are loaded => Crash checkConnections(); updateDone =true; } } public String getModelPath() { return RfAdditions.MOD_ID+":rfcable"; } public Material getMaterial() { return Material.iron; } public float getHardness(PartMOP hit) { return 3.0F; } public BlockState createBlockState() { return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[]{cableType} , sides); } @Override public int receiveEnergy(EnumFacing facing, int maxReceive, boolean simulate) { return 0; } @Override public int extractEnergy(EnumFacing facing, int maxExtract, boolean simulate) { return 0; } @Override public int getEnergyStored(EnumFacing facing) { return 0; } @Override public int getMaxEnergyStored(EnumFacing facing) { return 0; } @Override public boolean canConnectEnergy(EnumFacing facing) { return false; } private boolean canConnect(TileEntity handler, EnumFacing face){ if(handler == null) return false; return true; /*else if(handler instanceof IMultipartContainer){ IMultipartContainer container = (IMultipartContainer) handler; Collection<? extends IMultipart> parts = container.getParts(); for (IMultipart p : parts){ if(p instanceof IEnergyConnection) return ((IEnergyConnection)p).canConnectEnergy(face.getOpposite()); } } else if(handler instanceof IEnergyConnection){ return ((IEnergyConnection)handler).canConnectEnergy(face.getOpposite()); }*/ //return false; } public IBlockState getExtendedState(IBlockState state) { for(EnumFacing f : EnumFacing.VALUES){ if(this.getContainer() == null || this.getPos()==null || this.getWorld()==null || sides[f.ordinal()]==null) continue; BlockPos tilepos = getPos().add(f.getFrontOffsetX(), f.getFrontOffsetY(), f.getFrontOffsetY()); ((IExtendedBlockState)state).withProperty(sides[f.ordinal()], true); } if(type!=null){ state.withProperty(cableType,type); } else { state.withProperty(cableType,EnumCableType.CONDUCTIVE_REDSTONE); } Collection<IUnlistedProperty<?>> test = ((IExtendedBlockState) state).getUnlistedNames(); for(IUnlistedProperty<?> t : test){ System.out.println(t.getName()+ " : "+((IExtendedBlockState)state).getValue(t)); // getValue is null } return state; } private void checkConnections(){ connections.clear(); IMultipartContainer container = this.getContainer(); for(EnumFacing facing : EnumFacing.VALUES) { BlockPos changed = container.getPosIn().add(facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetY()); connections.put(facing, canConnect(container.getWorldIn().getTileEntity(changed), facing)); } } public void onNeighborBlockChange(Block block) { super.onNeighborBlockChange(block); checkConnections(); if(this.getContainer() != null && this.getPos()!=null){ getWorld().markBlockForUpdate(getPos()); } } public void onAdded() { super.onAdded(); checkConnections(); } @Override public EnumSet<PartSlot> getSlotMask() { return EnumSet.of(PartSlot.CENTER); } } Property Class public class PropertyCableConnection{ public static IUnlistedProperty<Boolean>[] getPropertyList(){ IUnlistedProperty[] p = new IUnlistedProperty[EnumFacing.VALUES.length]; int i=0; for(EnumFacing f: EnumFacing.VALUES){ p[i]= Properties.toUnlisted(PropertyBool.create(f.getName())); i++; } return p; } public static boolean getSide(EnumFacing face, IBlockState state){ if(!(state instanceof IExtendedBlockState)) return false; Collection<IUnlistedProperty<?>> props = ((IExtendedBlockState)state).getUnlistedNames(); IUnlistedProperty<?> found = null; for (IUnlistedProperty<?> p : props){ if(p.getName() == face.getName() && p.getType()==Boolean.class) found=p; } if(found==null) return false; return ((IExtendedBlockState)state).getValue((IUnlistedProperty<Boolean>) found); // NullPointerException } }
  14. Is there a way in 1.8 to render a item in a item? Like the /dev/null from ExtraUtilities.
  15. Hi. I want to add a additional drop to a Minecart but I can't access the class (Vanilla minecart). Is there an event that triggers on entity or minecart death?
  16. Hi I want to make an Entity (a Minecart) with a Inventory, but the inventory is always empty on Client side. I wrote a Sync Packet for my Entity but the Minecart does not keep the data. Minecart Code: public class ComputerCart extends EntityMinecart implements ISyncEntity, IInventory{ private boolean firstUpdate = true; private int tier = -1; private ItemStack[] inv = new ItemStack[20]; public ComputerCart(World p_i1712_1_) { super(p_i1712_1_); } public ComputerCart(World w, double x, double y, double z, Iterable<Pair<Integer, ItemStack>> components, int tier) { super(w,x,y,z); this.tier=tier; Iterator<Pair<Integer, ItemStack>> list = components.iterator(); while(list.hasNext()){ Pair<Integer, ItemStack> pair = list.next(); if(pair.getKey() < 20 && pair.getValue() != null){ inv[pair.getKey()] = pair.getValue(); } } } public void readEntityFromNBT(NBTTagCompound nbt){ super.readEntityFromNBT(nbt); this.loadInventory((NBTTagList) nbt.getTag("inventory")); } public void writeEntityToNBT(NBTTagCompound nbt){ super.writeEntityToNBT(nbt); nbt.setTag("inventory", this.storeInventory()); } private NBTTagList storeInventory(){ NBTTagList tag = new NBTTagList(); for(int i=0; i < inv.length; i+=1){ NBTTagCompound invslot = new NBTTagCompound(); NBTTagCompound invstack = new NBTTagCompound(); invslot.setInteger("slot", i); if(inv[i] != null) inv[i].writeToNBT(invstack); invslot.setTag("stack", invstack); tag.appendTag(invslot); } return tag; } private void loadInventory(NBTTagList list){ for(int i=0; i < list.tagCount(); i+=1){ NBTTagCompound invslot = list.getCompoundTagAt(i); NBTTagCompound invstack = invslot.getCompoundTag("stack"); int slot = invslot.getInteger("slot"); if(slot<20){ inv[slot] = ItemStack.loadItemStackFromNBT(invstack); } } } public void onUpdate(){ if(this.firstUpdate){ this.firstUpdate=false; if(!this.worldObj.isRemote) { ModNetwork.sendToNearPlayers(new EntitySyncData(this.worldObj.provider.dimensionId, this.getEntityId()), this.posX, this.posY, this.posZ, this.worldObj); } else if(this.worldObj.isRemote){ ModNetwork.channel.sendToServer(new EntitySyncRequest(this.worldObj.provider.dimensionId, this.getEntityId())); } } } @Override public void writeSyncData(NBTTagCompound nbt) { nbt.setTag("inventory", this.storeInventory()); } @Override public void readSyncData(NBTTagCompound nbt) { this.loadInventory((NBTTagList) nbt.getTag("inventory")); int itemcount = 0; for(int i=0;i<this.inv.length;i+=1){ if(this.inv[i]!=null) itemcount+=1; } OCMinecart.logger.log(Level.INFO, "ItemCount: "+itemcount+" Remote: "+this.worldObj.isRemote); } @Override public int getMinecartType() { return -1; } public static EntityMinecart create(World w, double x, double y, double z, Iterable<Pair<Integer, ItemStack>> components, int tier) { return new ComputerCart(w, x, y, z, components, tier); } public boolean interactFirst(EntityPlayer p){ int itemcount = 0; for(int i=0;i<this.inv.length;i+=1){ if(this.inv[i]!=null) itemcount+=1; } OCMinecart.logger.log(Level.INFO, "ItemCount: "+itemcount+" Remote: "+this.worldObj.isRemote); return true; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { if(slot < inv.length) return inv[slot]; return null; } @Override public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) { return null; } @Override public ItemStack getStackInSlotOnClosing(int p_70304_1_) { return null; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { if(slot<20) this.inv[slot] = stack; } @Override public String getInventoryName() { return null; } @Override public int getInventoryStackLimit() { return 64; } @Override public void markDirty() { // TODO Auto-generated method stub } @Override public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { return true; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return true; } } The data from the Sync Packet are correct. Output from the readSyncData() function: [Client thread/INFO] [OC-Minecarts]: ItemCount: 3 Remote: false I don't know why the world is not remote, but the Thread is running on Client Side. Output on RightClick: [Client thread/INFO] [OC-Minecarts]: ItemCount: 0 Remote: true [server thread/INFO] [OC-Minecarts]: ItemCount: 3 Remote: false
  17. Thanks! I added "@Optional.Interface" to the Class and minecraft does not longer crash.
  18. I want to create a TileEntity that can be moved by Spatial Pylons. But if I implement the IMovableTile interface, the game will crash if no AE2 is installed. How can I add a movable TileEntity without require AE2?
×
×
  • Create New...

Important Information

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