-
Posts
852 -
Joined
-
Last visited
Everything posted by Bektor
-
[1.11.2] [SOLVED] TileEntity null while it shouldn't
Bektor replied to Bektor's topic in Modder Support
public class BlockTransfer extends Block { public BlockTransfer() { super(Material.ROCK); this.setCreativeTab(ModCreativeTabs.mcpowerTab); } @Override public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) { super.onNeighborChange(world, pos, neighbor); // World implements IBlockAccess if(((World)world).isRemote) return; // add direct connections to the tile entity TileEntity tile = world.getTileEntity(pos); if(tile instanceof TileEntityPipeTransferEnergy) { TileEntityPipeTransferEnergy pipe = (TileEntityPipeTransferEnergy) tile; if(world.getTileEntity(neighbor) != null) { // check for all directions TileEntity neighbor_te = world.getTileEntity(neighbor); if(neighbor_te instanceof TileEntityEnergy) pipe.shouldRecalculate = true; else { // check the facing of the block to make sure which side is connected to us for(EnumFacing face : EnumFacing.VALUES) { BlockPos offset = pos.offset(face); if(offset == neighbor) { if(EnergyUtils.hasCapability(neighbor_te, face)) pipe.shouldRecalculate = true; } } } } else { // remove dead objects from the list pipe.shouldRecalculate = true; } } } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityPipeTransferEnergy(); } } public class BlockCable extends BlockConnectorBase { [...] public BlockCable() { super(Material.IRON); this.setHardness(.25f); this.setResistance(3f); this.setCreativeTab(ModCreativeTabs.mcpowerTab); } @Override protected boolean canCableConnect(IBlockAccess worldIn, BlockPos pos, EnumFacing facing) { // 188 72 265 BlockPos posi = pos.offset(facing); IBlockState state = worldIn.getBlockState(posi); TileEntity tile = worldIn.getTileEntity(posi); if(tile != null) return EnergyUtils.hasCapability(tile, facing.getOpposite()); return false; } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { super.onBlockAdded(worldIn, pos, state); TileEntity tile = worldIn.getTileEntity(pos); if(tile != null && tile instanceof TileEntityPipeEnergy) { TileEntityPipeEnergy cable = (TileEntityPipeEnergy) tile; cable.searchNetwork(); } } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tile = worldIn.getTileEntity(pos); if(tile != null && tile instanceof TileEntityPipeEnergy) { TileEntityPipeEnergy cable = (TileEntityPipeEnergy) tile; cable.searchNetwork(); } super.breakBlock(worldIn, pos, state); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { for(final EnumFacing facing : EnumFacing.VALUES) state = state.withProperty(CONNECTED.get(facing.getIndex()), this.canCableConnect(worldIn, pos, facing)); return state; } [...] (Collision box related stuff) @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, CONNECTED.toArray(new IProperty[CONNECTED.size()])); } @Override public int getMetaFromState(IBlockState state) { return 0; } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState(); } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityPipeEnergy(); } } -
[1.11.2] [SOLVED] TileEntity null while it shouldn't
Bektor replied to Bektor's topic in Modder Support
Changed it. Doesn't solve the problem, thought. -
[1.11.2] [SOLVED] TileEntity null while it shouldn't
Bektor replied to Bektor's topic in Modder Support
Oh... hm.. my IDE didn't told me that... With adding super.hasTileEntity it tells me that, thought. Which one should I use then? -
[1.11.2] [SOLVED] TileEntity null while it shouldn't
Bektor replied to Bektor's topic in Modder Support
It exists. IBlockState state = worldIn.getBlockState(posi); TileEntity tile = worldIn.getTileEntity(posi); if(tile != null) return EnergyUtils.hasCapability(tile, facing.getOpposite()); Output using debugger: state BlockStateContainer$StateImplementation (id=15672) justanotherenergy:transfer tile null -
Hi, I've got the following problem: protected boolean canCableConnect(IBlockAccess worldIn, BlockPos pos, EnumFacing facing) { // 188 72 265 BlockPos posi = pos.offset(facing); // correct TileEntity tile = worldIn.getTileEntity(posi); // correct if(tile != null) // why null???? return EnergyUtils.hasCapability(tile, facing.getOpposite()); return false; } (debugging got me to the point that I can write the comments behind the line of code) The method is called in public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { . My problem here is that the tile is null while it shouldn't be null. I checked the positions and the positions match perfectly the one of my transfer pipe. public class BlockTransfer extends Block { @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityPipeTransferEnergy(); } } Why is my method's tile null when my BlockTransfer has a tile entity? Note: the canCableConnect method checks to which blocks the cable can connect to in order to display the correct block state (connected to south, not connected, etc.). Thx in advance. Bektor EDIT: public class BlockTransfer extends Block { @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityPipeTransferEnergy(); } }
-
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
64 sounds like more anyone would want to write. ^^ Isn't there a way to get around manually writing 64 bounding boxes? I don't think that Buildcraft, ExtraUtilities or especially ThermalDynamics manually wrote down 64 bounding boxes in 1.7.10 (no clue how they look in newer versions of MC). -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
Oh, never looked at it so closely (all those numbers in one line). Tought writing down 16 possible bounding boxes which are just used once (when the player hovers over the block).... I feel that this is a lot of work. Isn't there any automated way of doing creating all those bounding boxes? Basically, it's just the simplex bounding boxes already in use for collision + all possible variants of these. Thought this let's me think.... Why does addCollisionBoxToList works perfectly with 6 collision boxes + one base collision box and for getBoundingBox all possible variants (I guess) are also defined resulting in the case of the fence into 16. -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
Because I looked at BlockFence as a reference on how Minecraft does the same think I want to do. (As I had no clue before which method was there for changing the bounding box) And Minecraft got an Array and the index for this error is calculated in getBoundingBoxIdx with bitshifting. Though BlockFence has less possible connections which could change the bounding box. -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
BB is an ArrayList which holds all bounding boxes, so UP, DOWN, WEST, SOUTH etc. All those bounding boxes are created seperatly, but then stored in this ArrayList. The size of BB is 6. Current code iteration (I changed this one class really way too often ^^): private static final ArrayList<AxisAlignedBB> BB = new ArrayList<>(); -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
System.out.println(i + " " + index); [STDOUT]: 0 0 [STDOUT]: 1 0 [STDOUT]: 2 4 [STDOUT]: 3 4 [STDOUT]: 4 4 [STDOUT]: 5 36 -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
Oh, yeah. Didn't noticed that with the size-1. ^^ Thought even when changint the <= size() to <size() it still crashes: private int getBoundingBoxIndex(IBlockState state) { int index = 0; System.out.println(CONNECTED_PROPERTIES.size()); // prints out 6 for(int i = 0; i < CONNECTED_PROPERTIES.size(); i++) { PropertyBool value = (PropertyBool) CONNECTED_PROPERTIES.get(i); if((Boolean)state.getValue(value).booleanValue()) index |= 1 << EnumFacing.getFront(i).getIndex(); } return index; } -
[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException
Bektor replied to Bektor's topic in Modder Support
Hm... I don't quite get why and to what I should change it. EDIT: After debugging I figured out that when the value i is 5 the value index jumps to 36 (I just placed directly under the if-statement a syso statement and put there the breakpoint). Thought why does it jump to 36 there??? And to what would I need to change the for-loop? (4 would also crash) -
Hi there, I've got the problem that I want to set the bounding box which appears when hovering over the block to acount for all possible connections of the block. @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { state = this.getActualState(state, source, pos); return BB.get(this.getBoundingBoxIndex(state)); } private int getBoundingBoxIndex(IBlockState state) { int index = 0; for(int i = 0; i <= CONNECTED.size(); i++) { PropertyBool value = (PropertyBool) CONNECTED.get(i); if((Boolean)state.getValue(value).booleanValue()) index |= 1 << EnumFacing.getFront(i).getIndex(); } return index; } My data (the values NORTH, EAST, UP etc.) is stored in an ImmutableList sorted in D-U-N-S-W-E order. The current code however does not work and results into the following error which occurs in the line BB.get(this.getBoundingBoxIndex(state)); : I guess the problem here is that I just copied over the bit operation from the BlockFence which doesn't need to account for possible connections UP and DOWN. If this is the case, how do I need to change the bit operation? Thx in advance. Bektor
-
Thats as far as I got, but how does the inner of those methods work: Meaning the inner parts of the canFenceConnectTo and canConnectTo etc. methods.
-
Hi, I'm wondering how the fence actually checks if it should connect to another fence or not. I know the fence class got these methods which are beeing called in getActualState. private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing) { Block block = world.getBlockState(pos.offset(facing)).getBlock(); return block.canBeConnectedTo(world, pos.offset(facing), facing.getOpposite()) || canConnectTo(world, pos.offset(facing)); } public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); return block == Blocks.BARRIER ? false : ((!(block instanceof BlockFence) || block.blockMaterial != this.blockMaterial) && !(block instanceof BlockFenceGate) ? (block.blockMaterial.isOpaque() && iblockstate.isFullCube() ? block.blockMaterial != Material.GOURD : false) : true); } My problem is that I don't really get how those methods work, for example the statement if the block is not an instanceof BlockFence. Wouldn't this cause the fence to not be able to connect to any other fence?? Thx in advance. Bektor
-
[1.12.x/1.11.x] [SOLVED] JSON rendering& collision boxes
Bektor replied to Bektor's topic in Modder Support
I never tried it with multipart. I don't even know what's the difference between multipart and the submodel stuff is. I just read about the submodels in the Forge documentation and then applied it to my block even before I looked at other JSONs like the one from the fences. -
[1.12.x/1.11.x] [SOLVED] JSON rendering& collision boxes
Bektor replied to Bektor's topic in Modder Support
I want the submodel to extend the base model to have connections between blocks. Basically think about Minecraft fences. They got one base model and one submodel (except that they don't define it as submodel). My problem is now, to place the submodel at the right position of the base model for the correct connection. The difference however is that Minecraft uses multipart while I am using submodels to achieve the same effect. Hm... how could I solve this the most efficient way? The only problem with this code is that it replaced the whole model while I don't want the model to be replaced, but another model (submodel) beeing added to it. -
Hi, I've got the problem that I've got some JSON model for my block. This model is actually based on submodels to be displayed correctly. Having said that, the base model is a normal cube, just smaller. The submodel extends the base model to one side until it reaches the end of the block. However, with this setup I've got the following problems: How to display a model with it's submodel in inventory? How can I properly align my models to my set collision boxes, as currently it always fails to match on one side (especially the ending points of a cable connection) How can I move the submodel around, as I would have to move it around (I guess) to be always on the correct side of the block, like on the west side or the top side or the south side or the east side etc. The code: Thx in advance. Bektor
-
[1.12.x/1.11.x] [SOLVED] Block connections (Collision, JSON)
Bektor replied to Bektor's topic in Modder Support
Thx, that solved the problem. Thought how am I about to let my item json render my block in the inventory with some submodels added to it? -
[1.12.x/1.11.x] [SOLVED] Block connections (Collision, JSON)
Bektor replied to Bektor's topic in Modder Support
-
[1.12.x/1.11.x] [SOLVED] Block connections (Collision, JSON)
Bektor replied to Bektor's topic in Modder Support
"textures": { "particle": "justanotherenergy:blocks/cable", "texture": "justanotherenergy:blocks/cable", "overlay": "justanotherenergy:blocks/cable" }, Ok, I changed it in cable_base and cable_side, thought the errors still remain. -
[1.12.x/1.11.x] [SOLVED] Block connections (Collision, JSON)
Bektor replied to Bektor's topic in Modder Support
There you go, however I didn't posted the full latest log as there are some errors thrown out which aren't even related to the blocks this thread is about (like missing jsons for copper ingot etc.) I'm also wondering what's causing the JSONSyntaxException as JSONLint - The JSON Validator tells me the JSON files are correct. The code: The texture cable.png can be found in assets.justanotherenergy.textures.blocks. The source code of the block remains the same as before. -
Yeah, but all of this null stuff. I've got the feeling you know more about it then the ones who wrote the books I read a long time ago. (Starting with some Java for kids books and later books for adults) I guess it is better explained in books like "Java ist auch eine Insel", but I've never read those books as most of the Java features those books covered I already learned and I got interested in programming and thus started learning Java even before I could understand English or played Minecraft.
-
Yeah, I know. But if feels somehow as if this makes it more complicated to understand the null stuff. I mean, I know that null has to be casted in this case. Thought I never really thought about C++ nullptr. It's there and that's all I've ever thought about. What it is and all that stuff is the same with Java null, I've just used it like null means nothing assigned to the value. What this nothing is, that's something I've never learned in school nor is it written in any of my Java books and C++ nullptr, might be that it is better described when I get to the point where it is explained. ^^ Which makes sense as if I recall correctly the Java compiler is written in C++ and code of the java API itself references through JNI to C++ stuff? Thought I know for sure that LWJGL does this. I guess when I've got more time I'll look into VS memory display to see what nullptr is there exactly.
-
Which sounds like C++ and not Java. ^^ meaning nullptr I somehow have the feeling that all this Java pointers do not exists there and all of that stuff just makes it more complicated to understand. In my brain its just somehow programmed: Java "no" real pointers, C++ pointers