Jump to content

MiKeY_

Members
  • Posts

    19
  • Joined

  • Last visited

Everything posted by MiKeY_

  1. Thanks for the help! I'll see what I can do with all this
  2. Yay! I thought as much but I was being hopeful. Any suggestions on how I would go about saving a list of blocks to the client so they don't have to keep making the list?
  3. Hi, So I'm trying to use WordSavedData for a client side only mod to store a list of blocks. I've attempted to follow other mods, the mc source and the forge docs but I can't seem to understand why when I restart the world the data saved to the nbt is lost. Heres my WorldSavedData public class BlockStorage extends WorldSavedData { private static final String DATA_KEY = Reference.MOD_NAME + "_BlockData"; private HashMap<String, BlockData> blockStorage = new HashMap<>(); public BlockStorage() { super(DATA_KEY); } public BlockStorage(String name) { super(name); } public static BlockStorage get(World world) { MapStorage storage = world.getMapStorage(); if (storage == null) throw new IllegalStateException("World#getMapStorage returned null. The following WorldSave failed to save data: " + DATA_KEY); BlockStorage instance = (BlockStorage) storage.getOrLoadData(BlockStorage.class, DATA_KEY); if (instance == null) { instance = new BlockStorage(); storage.setData(DATA_KEY, instance); } return instance; } @Override @ParametersAreNonnullByDefault public void readFromNBT(NBTTagCompound nbt) { NBTTagList list = nbt.getTagList("blocks", 10); for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound compound = list.getCompoundTagAt(i); blockStorage.put( compound.getString("key"), new BlockData( compound.getString("entryName"), new OutlineColor( compound.getIntArray("color") ), new ItemStack( compound.getCompoundTag("stack") ), compound.getBoolean("drawing") ) ); } } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { NBTTagList list = new NBTTagList(); blockStorage.forEach( (k, v) -> { NBTTagCompound c = new NBTTagCompound(); c.setString("key", k); c.setString("entryName", v.getEntryName()); c.setIntArray("color", new int[]{v.getOutline().getRed(), v.getOutline().getGreen(), v.getOutline().getBlue()}); c.setBoolean("drawing", v.isDrawing()); c.setTag("stack", v.getItemStack().writeToNBT(new NBTTagCompound())); list.appendTag(c); }); compound.setTag("blocks", list); return compound; } public HashMap<String, BlockData> getBlockStorage() { return blockStorage; } public void setBlockStorage(HashMap<String, BlockData> blockStorage) { this.blockStorage = blockStorage; } } Heres how I access & save to it BlockStorage storage = BlockStorage.get(XRay.mc.player.world); // No blocks exist if( storage == null ) return; storage.getBlockStorage().forEach( (k, v) -> { System.out.println(k); System.out.println(v.toString()); }); // Adding to it BlockStorage storage = BlockStorage.get(mc.player.world); if (storage != null) { storage.setBlockStorage( Controller.getBlockStore().getStore() ); storage.markDirty(); } Any help is appreacheted but if this is something that isn't possible in a single player only mod then any advice on what I should be using instead would be greatly appreachted too ?
  4. Looks like you're not syncing the updates to the server. You'll want to look into this https://mcforge.readthedocs.io/en/latest/networking/simpleimpl/
  5. Thanks, I think I'll keep messing around. I don't want the different directions of the blocks and things and that seems to be what is causing the bigest issues when using getValidStates
  6. I'm getting the point there I'm just gunna force the player to find the block and put it in an inventory slot haha. All I need is a list of all the blocks in the game... I never thought it would be this annoying By any chance do you know how to get a block with no properties at all so I can use withProps on an empty blockState? edit: don't know if this helps, I'm basically just making a list you can search through to select a filter. A bit like StevesFactoryManager worked when you'd want to select the block to use.
  7. I Actually can't remember why I put that there, I'm sure at the time there was a reason I some what thought that it wasn't going to be an easy thing to fix, I'm currently expermeneting with this Collection<IBlockState> blocksList = new ArrayList<>(); Collection<Block> blocks = ForgeRegistries.BLOCKS.getValuesCollection(); blocks.forEach( block -> block.getBlockState().getValidStates().forEach(iBlockState -> { iBlockState.getProperties().forEach( (iProperty, comparable) -> { if( !iProperty.getName().equals("variant") || blocksList.contains(iBlockState) ) return; blocksList.add( iBlockState ); } ); } )); But I only care about the variant of the block or the complete lack of the varient and this code doesn't even close to get what I need it to do. I'm trying to find a way to use withProperty to create a new blockstate that is purely either the variant of the block as default. Things like grass would work fine with their defaults, things like stone, no so much.
  8. To confirm, you are running in debugging mode and not the normal run mode?
  9. Before I start, yes, I know, IBlockState != ItemStack. I have an issue that I'm trying to figure out so it's either finding out how to get the blockstate from the itemstack or it's finding the correct way of doing things. So, I want to have a list of selectable blocks which I have, unfortunately this list is itemstacks and I need blocks / blockstates. Here is how I build my list for ( Block block : ForgeRegistries.BLOCKS ) { NonNullList<ItemStack> subBlocks = NonNullList.create(); block.getSubBlocks( block.getCreativeTabToDisplayOn(), subBlocks ); if ( Blocks.AIR.equals( block ) ) continue; // avoids troubles for( ItemStack subBlock : subBlocks ) { if( subBlock.getItem() == Items.AIR ) continue; Instance.guiBlockList.add( subBlock.isEmpty() ? new ItemStack(block) : subBlock ); } } From this I am then able to create a perfectly suitable gui list that displays all the blocks and their subblocks ( wool, wool:green, wool:yellow, etc ). I then need to add this to a List<IBlockState> where the actual state is important. IBlockState blockState = Block.getBlockFromItem( this.selectBlock.getItem() ).getDefaultState(); I'm currently doing it like this but it's pretty clear that this won't work for what I need due to the defaultState. I've looked into using `getStateForPlacement`but to no avail because I have no world data to give it. I only have an itemstack to work with. Any help is greatly appreciated EDIT: I'm currently working on rewritting my mod to get it off of the old id:meta system so the states crap is somewhat new to me.
  10. Wholesomely. Thanks for that I've sorted the error. Thanks for the suggestion. I make a point of not turning any warning off and figuring out why it's being pinged. I use a lot of different linters for the other languages I use so I'm pretty used to it. Thanks again, I think I've got it from here... Hopefully
  11. Thanks, I just about get that. I should have looked for examples of parseValue is the mc source. By any change is there a way to stop this
  12. I'm really struggling with this part. ( Warning, prototyping code ) String testingBlock = "minecraft:wool[color=yellow]"; BlockResolver blockInfo = new BlockResolver(testingBlock); Block test = ForgeRegistries.BLOCKS.getValue(new ResourceLocation( blockInfo.getDomain() + ":" + blockInfo.getItemName() )); assert test != null; IBlockState state = test.getDefaultState(); for( IProperty prop : state.getPropertyKeys() ) { if( prop.getName().equals( blockInfo.getVariationProp() ) ) { Optional sd = prop.parseValue( blockInfo.getVariationValue() ); if( sd.isPresent() ) { IBlockState newState = state.withProperty(prop, sd.get().toString()); System.out.println(Block.getStateId(newState)); } } } Ignore BlockResolver all it does is parse my block string. I'm going to assume I'm using parseValue wrong or I've completely miss understood. The code as is isn't able to set the property because I get this error Cannot set property PropertyEnum{name=color, clazz=class net.minecraft.item.EnumDyeColor, values=[white, orange, magenta, lightBlue, yellow, lime, pink, gray, silver, cyan, purple, blue, brown, green, red, black]} to yellow on block minecraft:wool, it is not an allowed value I get what the error is saying so I used this to fix this by using EnumDyeColor.YELLOW but of course this isn't a fix. I need this to be dynamic depending on the variation and the prop value
  13. Yeah thats what I was thinking, Thanks for clarifying. Upon the first time you start the mod it will generate a config and in the original instance it would add id: 3 for grass and add it to the gui. It would do the same for id: 12 meta: 2 for orange wool. I'd assume that if I was to use "minecraft:grass" and "minecraft:wool[varient=orange]" and upon startup resolve that to a stateId. That would work fine for other worlds on the same instances. Or should I be resolving the id's upon world load instead?
  14. Would I be wrong in thinking that if I was to say, have a much larger range on my selection, that this would be a lot of logic to run on every tick to detect blocks? Although, I think I could do a lot of that logic on the startup of reading the config to resolve the block states that I need to be searching for. My only worry is that I use defaults as examples like Grass and Wool. I'd assume that these wouldn't change between world? Only between instance or would that depend on mods. I'm not a fan of volatile data. Other than that, Thanks for the info, I'm going to work on refactoring the codebase to use States instead of Id's & Meta.
  15. Say you had a config that contained a few blocks id & metas. Then when you are at your own home in SP you could press a button to highlight those blocks to identify issues with wires or missing blocks or what ever. Kinda like xray but not really. The config is controlled by UI and to add a block you can look at it or hold it in your hand. I can get the state from those two options but how would I store the state in a way that uniquely identifies that block, say it was a chest. Then in my code that gets the state of each blocks in a small radius around you, how I do compare there states to the stored ones. The reason I'm using Id's is because I can store the id: 54 and then get the blocks id and do a if( Block.getIdFromState() == store.getBlock().id ) This an extream simplification of what I am doing but basically I have stored Id's and I need a way of compairing them to the blocks around the player. this works as Id's but if Id's are going I need a way of storing the state to compare that instead of ids. I was only storing meta for edge cases like different wool types.
  16. Is there any good tutorials / documentation on how to use blockStates. To confirm I have no blocks in my mod, no items, no nothing. It's all code based. Basically you can scan a few blocks around you and allows you to add them to a gui. So I don't need to know how the blockState .json stuff works unless that allows me to understand how blockStates are handled for a selection / detection side of things. ( I work on my mod as a very much side project. I can miss mc versions with how little I update / change it. So I stuggle a lot to keep up with the changes in the game and forge )
  17. I had a funny idea I was trying to do something that wouldn't work out in the long run Thanks for you anwser. Yeah, I know... 90% of the codebase is using Id's and I've just not had the heart to rewrite it all. Although the functions arent depercated yet so I'll keep being an awful person until then. I know for block Id's but whats correct thing to be using for metadata? Propreties I'd assume?
  18. Hi, Hopefully this is a simple one, I'm looking to use Block block = state.getBlock(); return new BlockId( Block.getIdFromBlock( block ), block.getMetaFromState( state ) ); When scanning the area around the player for a specific block. When scanning the world I get blocks like a chest with meta:2 because of it's direction, I was wondering if there is a way to either get the meta without the direction of the block or if there is a way to savely figure out when it's directional meta and remove it? Thanks
×
×
  • Create New...

Important Information

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