Jump to content

KYPremco

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by KYPremco

  1. Oh sorry i misunderstood it because i tought i could not change the NBTUtils#readBlockState Now i have copied that code in the command and changed Optional<T> optional = p_193590_1_.parseValue(p_193590_3_.getString(p_193590_2_)); To: Optional<T> optional = p_193590_1_.parseValue(p_193590_3_.getString(p_193590_2_).intern()); And it's workign fine now indeed But could i do this more smooth then copy paste that code ?(sorry i'm still a beginner) Full code added:
  2. Ah okay didn't understand the first time, well sad but true. Then i'll just check if they going to cause errors and remove that type of block before passing into the item. I hope not to much blocks have this problem, but thanks for the help anyway
  3. I use NBTUtil#readBlockState & NBTUtil#writeBlockState After some more testeing: not all blocks will let it crash probably only a small amount. But what bugs me is why is it working without the command while it's setup exact the same This is the player data saved, one card from the command left, the other from the block right.
  4. Hello, I want to create a command to give an item with the structure that it get's from a file. This worked properly with all vanilla items, after some tests i tried it with a mod and it crashed. Whenever i use the card wich i get from the command it crashes but if i create it without the file in a block it works, i checked the NBT data of the players inventory and everything is exact the same. What am i doing wrong ? NBTUtil#readBlockState crashes with modBlocks Commands.java - private void giveMemorycard gives error Error log:
  5. The NBT data, it won't save i assume but don't understand why can't find it.
  6. Hey, I want to save my structure on a item so you can put it in a chest or where you want and can rebuild it whenever you want. First i tested out a counter on a item worked fine but when i used the same code in the TileEntity it disappears when i get it out of the container. Loading getting the content out of the item worked well when i already put the number in the item with rightclicking. Screenshots Item MemoryCard: Container (custom inventory): Just the writing code in TileEntityBuilder:
  7. Thank Draco that maded a little bit more clear. I got it working but ended up doing it totally different. If you still see something stupid please tell me. package com.kyproject.mynewmod.tileentity; import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; import java.util.ArrayList; public class TileEntityBuilder extends TileEntity implements ITickable { public ArrayList<BlockPlace> blockStructure = new ArrayList<>(); public ArrayList<BlockPlace> ORGIN = new ArrayList<>(); ItemStackHandler inventory = new ItemStackHandler(9); boolean blockIsBuilding = false; int countBlocks = 0; int counter = 0; public static class BlockPlace { public BlockPos pos; public IBlockState state; public BlockPlace(BlockPos pos, IBlockState state) { this.pos = pos; this.state = state; } } public void createStructure() { ArrayList<BlockPlace> blocks = new ArrayList<>(); for(int x = 0;x < 15;x++) { for(int z = 1;z < 15;z++) { for(int y = 0;y < 15; y++) { if(!worldObj.isAirBlock(pos.add(x,y,z))) { IBlockState state = worldObj.getBlockState(pos.add(x,y,z)).getActualState(worldObj, pos.add(x,y,z)); blocks.add(new BlockPlace(pos.add(x,y,z), state)); } } } } ORGIN = blocks; } public void startStructure() { blockStructure.clear(); blockStructure = (ArrayList<BlockPlace>) ORGIN.clone(); blockIsBuilding = true; countBlocks = 0; counter = 0; } @Override public void update() { if(blockIsBuilding) { if(counter == 0) { if(blockStructure.size() == 0) { blockIsBuilding = false; countBlocks = 0; } else { worldObj.setBlockState(blockStructure.get(0).pos, blockStructure.get(0).state); if(blockStructure.size() - 1 > 1) { worldObj.setBlockState(blockStructure.get(blockStructure.size() - 1).pos, blockStructure.get(blockStructure.size() - 1).state); blockStructure.remove(blockStructure.size() - 1); } blockStructure.remove(0); countBlocks++; } counter = 0; } else { counter++; } System.out.println(countBlocks); } } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); inventory.deserializeNBT(compound.getCompoundTag("inventory")); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("inventory", inventory.serializeNBT()); return super.writeToNBT(compound); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T)inventory : super.getCapability(capability, facing); } }
  8. I have a problem with my mod. It's my first thing i try out but just can't find anywhere an aswer. I want to save a structure that a player build in a 15x15x15 area and then rebuild it. this works for how far i am. But when it's building it changes the direction of the stairs, doors will be bugged and chests didn't test. Also my wood block went from spruce to normal. I activate CreateStructure when i click on the top and startStructure on north side When i use this on WithProperty it crashes and saying that the block (dispenser) doesnt have it public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); Code: package com.kyproject.mynewmod.tileentity; import net.minecraft.block.Block; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; import java.util.ArrayList; public class TileEntityBuilder extends TileEntity implements ITickable { public ArrayList<BlockPlace> blockStructure = new ArrayList<>(); public ArrayList<BlockPlace> ORGIN = new ArrayList<>(); ItemStackHandler inventory = new ItemStackHandler(9); boolean blockIsBuilding = false; int countBlocks = 0; int counter = 0; public static class BlockPlace { public Block block; public BlockPos pos; public IBlockState state; public BlockPlace(BlockPos pos, Block block, IBlockState state) { this.pos = pos; this.block = block; this.state = state; } } public void createStructure() { ArrayList<BlockPlace> blocks = new ArrayList<>(); for(int x = 0;x < 15;x++) { for(int z = 1;z < 15;z++) { for(int y = 0;y < 15; y++) { if(!worldObj.isAirBlock(pos.add(x,y,z))) { blocks.add(new BlockPlace(pos.add(x,y,z),worldObj.getBlockState(pos.add(x,y,z)).getBlock(), worldObj.getBlockState(pos.add(x,y,z)).getBlock().getBlockState().getBaseState())); } } } } ORGIN = blocks; } // Tried this but error occured public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public void startStructure() { blockStructure.clear(); blockStructure = (ArrayList<BlockPlace>) ORGIN.clone(); blockIsBuilding = true; countBlocks = 0; counter = 0; } @Override public void update() { if(blockIsBuilding) { if(counter == 0) { if(blockStructure.size() == 0) { blockIsBuilding = false; countBlocks = 0; } else { worldObj.setBlockState(blockStructure.get(0).pos, blockStructure.get(0).block.getDefaultState()); if(blockStructure.size()- 1 > 1) { worldObj.setBlockState(blockStructure.get(blockStructure.size() - 1).pos, blockStructure.get(blockStructure.size() - 1).block.getDefaultState()); blockStructure.remove(blockStructure.size() - 1); } blockStructure.remove(0); countBlocks++; } counter = 0; } else { counter++; } System.out.println(countBlocks); } } //Some other stuff @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); inventory.deserializeNBT(compound.getCompoundTag("inventory")); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("inventory", inventory.serializeNBT()); return super.writeToNBT(compound); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T)inventory : super.getCapability(capability, facing); } }
×
×
  • Create New...

Important Information

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