feldim2425 Posted January 18, 2016 Share Posted January 18, 2016 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 } } Quote Link to comment Share on other sites More sharing options...
feldim2425 Posted January 18, 2016 Author Share Posted January 18, 2016 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. Quote Link to comment Share on other sites More sharing options...
Choonster Posted January 18, 2016 Share Posted January 18, 2016 I found the problem it seems like withProperty() for the IUnlistedProperty doesn't change the state, it just returns the new state. This is true of the vanilla IBlockState implementation as well, it's immutable. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.