perigrine3 Posted March 27, 2019 Share Posted March 27, 2019 I'm making a Giant right now, and I wanted to make it so that, when it walks, trees are "crushed" under it. I figured, "well the Ender Dragon does something like that", so I went into its .class file and found the part for "canEntityDestroy", so I began making a new EntityAI class. Now, my goal is to change the code so that, instead of only preserving Command Blocks, Iron Bars, and the End Gateway, it will preserve everything BUT trees and wood planks. I know I could just add in every type of existing block, but I don't want to do that because I don't have the time (or the sanity) for such endeavors. SO, if anybody has any ideas as to how to make it so that I can list what TO destroy rather than what NOT to destroy, I'd like to hear them. Here's the code from EntityDragon.class: private boolean destroyBlocksInAABB(AxisAlignedBB p_70972_1_) { int i = MathHelper.floor(p_70972_1_.minX); int j = MathHelper.floor(p_70972_1_.minY); int k = MathHelper.floor(p_70972_1_.minZ); int l = MathHelper.floor(p_70972_1_.maxX); int i1 = MathHelper.floor(p_70972_1_.maxY); int j1 = MathHelper.floor(p_70972_1_.maxZ); boolean flag = false; boolean flag1 = false; for (int k1 = i; k1 <= l; ++k1) { for (int l1 = j; l1 <= i1; ++l1) { for (int i2 = k; i2 <= j1; ++i2) { BlockPos blockpos = new BlockPos(k1, l1, i2); IBlockState iblockstate = this.world.getBlockState(blockpos); Block block = iblockstate.getBlock(); if (!block.isAir(iblockstate, this.world, blockpos) && iblockstate.getMaterial() != Material.FIRE) { if (!this.world.getGameRules().getBoolean("mobGriefing")) { flag = true; } else if (block.canEntityDestroy(iblockstate, this.world, blockpos, this) && net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this, blockpos, iblockstate)) { if (block != Blocks.COMMAND_BLOCK && block != Blocks.REPEATING_COMMAND_BLOCK && block != Blocks.CHAIN_COMMAND_BLOCK && block != Blocks.IRON_BARS && block != Blocks.END_GATEWAY) { flag1 = this.world.setBlockToAir(blockpos) || flag1; } else { flag = true; } } else { flag = true; } } } } } if (flag1) { double d0 = p_70972_1_.minX + (p_70972_1_.maxX - p_70972_1_.minX) * (double)this.rand.nextFloat(); double d1 = p_70972_1_.minY + (p_70972_1_.maxY - p_70972_1_.minY) * (double)this.rand.nextFloat(); double d2 = p_70972_1_.minZ + (p_70972_1_.maxZ - p_70972_1_.minZ) * (double)this.rand.nextFloat(); this.world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D); } return flag; } Thanks for your help! Quote Link to comment Share on other sites More sharing options...
perigrine3 Posted March 27, 2019 Author Share Posted March 27, 2019 No. Really? Obviously, that's literally what I said, I just don't know how. Quote Link to comment Share on other sites More sharing options...
loordgek Posted March 27, 2019 Share Posted March 27, 2019 i see what you mean are you using 1.13 ? in 1.13 you can use block.isIn(tag you wat to use) in 1.12.2 you can use the oredict (get the itemstack dropped by the block) Quote Link to comment Share on other sites More sharing options...
perigrine3 Posted March 27, 2019 Author Share Posted March 27, 2019 I'm using 1.12.2. I'm still kinda new to coding, so how would getting the itemstack dropped by the block help me prevent it from being destroyed? Quote Link to comment Share on other sites More sharing options...
DavidM Posted March 27, 2019 Share Posted March 27, 2019 (edited) 7 hours ago, perigrine3 said: so how would getting the itemstack dropped by the block help me prevent it from being destroyed? This is for checking the block's oredict and destroying it if it is wood. This will allow your giant to work with every type of tree. See this if loop thingy? if (block != Blocks.COMMAND_BLOCK && block != Blocks.REPEATING_COMMAND_BLOCK && block != Blocks.CHAIN_COMMAND_BLOCK && block != Blocks.IRON_BARS && block != Blocks.END_GATEWAY) { flag1 = this.world.setBlockToAir(blockpos) || flag1; } else { flag = true; } Locate it in your code and change the condition to match your need. Personally, I would discourage copying from vanilla in this case, as the code you copied can be rewritten to better fit your needs. Edited March 27, 2019 by DavidM I can't use terminologies correctly ; ) 1 Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support. Link to comment Share on other sites More sharing options...
perigrine3 Posted March 27, 2019 Author Share Posted March 27, 2019 I think I figured it out, but I think I'll just replace the items not to break to Dirt/Grass, Stone, Diamond, and Obsidian blocks. If I find anything else I don't want being destroyed, I'll add it in. Quote Link to comment Share on other sites More sharing options...
Cadiboo Posted March 27, 2019 Share Posted March 27, 2019 3 hours ago, perigrine3 said: I think I figured it out, but I think I'll just replace the items not to break to Dirt/Grass, Stone, Diamond, and Obsidian blocks. If I find anything else I don't want being destroyed, I'll add it in. Bedrock maybe? TileEntities maybe? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) 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.