From ea828a3d7a7d79b8a81bbac23dd4a188bc7e6555 Mon Sep 17 00:00:00 2001 From: Blargerist Date: Fri, 23 Jan 2015 11:01:36 -0600 Subject: [PATCH] 0.931b update. See README.md for changelog. --- README.md | 8 +- blargerist/cake/blockphysics/ModConfig.java | 57 ++- blargerist/cake/blockphysics/ModInfo.java | 2 +- .../asm/modules/ModuleBlockFalling.java | 60 ++- .../blockphysics/events/BPEventHandler.java | 104 +---- .../cake/blockphysics/util/BlockMove.java | 244 +++++++++- .../cake/blockphysics/util/EntityMove.java | 421 ++++++++++++++++++ .../cake/blockphysics/util/MoveDef.java | 6 +- mcmod.info | 2 +- 9 files changed, 764 insertions(+), 140 deletions(-) create mode 100644 blargerist/cake/blockphysics/util/EntityMove.java diff --git a/README.md b/README.md index b260fc6..d7560c8 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,9 @@ Block Physics mod, originally created by id_miner NEW THIS UPDATE: -Fixed config not accepting blocks without metadata. +More defaults added to the config. -Fixed max life timer of falling blocks. Should significantly cut down on the number of blocks being dropped as items. - -Removed client side requirement. Can now run on servers without being on the client. Causes minor visual errors on client without mod, but works fine. - -Added "hurts" option to BlockDef. Controls falling block damage. +Minor logic updates. Many, many things still unimplemented. Currently supports downward movement and sliding. Sturcture checks should be properly working. Configuration working. Mod compatability untested. diff --git a/blargerist/cake/blockphysics/ModConfig.java b/blargerist/cake/blockphysics/ModConfig.java index 52480c3..3ca4842 100644 --- a/blargerist/cake/blockphysics/ModConfig.java +++ b/blargerist/cake/blockphysics/ModConfig.java @@ -45,8 +45,18 @@ public static void init(File file) if (categoryMap == null || categoryMap.keySet().size() == 0) { + config.get("move definitions", "brick", new String[]{"movetype:1", "slidechance:0", "ceiling:1", "smallarc:0", "bigarc:1", "corbel:1", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "cobblestone", new String[]{"movetype:1", "slidechance:0", "ceiling:0", "smallarc:1", "bigarc:1", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "dirt", new String[]{"movetype:1", "slidechance:0", "ceiling:0", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "grass", new String[]{"movetype:2", "slidechance:70", "ceiling:0", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "leaves", new String[]{"movetype:1", "slidechance:0", "ceiling:1", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:1", "attached:2", "floating:0", "branch:0"}).getStringList(); config.get("move definitions", "sand", new String[]{"movetype:2", "slidechance:90", "ceiling:0", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); - config.get("move definitions", "cobblestone", new String[]{"movetype:1", "slidechance:60", "ceiling:0", "smallarc:1", "bigarc:1", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "stone", new String[]{"movetype:1", "slidechance:0", "ceiling:0", "smallarc:2", "bigarc:2", "corbel:0", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "stonebrick", new String[]{"movetype:1", "slidechance:0", "ceiling:0", "smallarc:2", "bigarc:3", "corbel:2", "ncorbel:0", "hanging:0", "attached:0", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "wall", new String[]{"movetype:1", "slidechance:0", "ceiling:1", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:1", "attached:2", "floating:0", "branch:0"}).getStringList(); + config.get("move definitions", "wood", new String[]{"movetype:1", "slidechance:0", "ceiling:1", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:6", "hanging:0", "attached:0", "floating:0", "branch:1"}).getStringList(); + config.get("move definitions", "wool", new String[]{"movetype:1", "slidechance:0", "ceiling:0", "smallarc:0", "bigarc:0", "corbel:0", "ncorbel:0", "hanging:5", "attached:5", "floating:0", "branch:0"}).getStringList(); + categoryMap = config.getCategory("move definitions"); } @@ -68,6 +78,7 @@ public static void init(File file) String floatingblock = null; int floatingmeta = 0; boolean branch = false; + int tree = 0; for (int i = 0; i < properties.length; i++) { @@ -109,6 +120,10 @@ else if (keyString.equals("attached")) { attached = value; } + else if (keyString.equals("tree")) + { + tree = value; + } } else if (keyString.equals("ceiling") || keyString.equals("branch")) { @@ -146,15 +161,31 @@ else if (keyString.equals("floating")) } } } - DefinitionMaps.putMoveDef(id, new MoveDef(id, movetype, slidechance, ceiling, smallarc, bigarc, corbel, ncorbel, hanging, attached, floatingradius, floatingblock, floatingmeta, branch)); + DefinitionMaps.putMoveDef(id, new MoveDef(id, movetype, slidechance, ceiling, smallarc, bigarc, corbel, ncorbel, hanging, attached, floatingradius, floatingblock, floatingmeta, branch, tree)); } categoryMap = config.getCategory("block definitions"); if (categoryMap == null || categoryMap.keySet().size() == 0) { - config.get("block definitions", "sand", new String[]{"canmove:true", "movedef:sand", "supportiveblock:false", "fragile:0", "trapping:true", "mass:1700", "strength:64000", "hurts:true"}).getStringList(); - config.get("block definitions", "sand", new String[]{"canmove:true", "movedef:cobblestone", "supportiveblock:true", "fragile:0", "trapping:false", "mass:2100", "strength:64000", "hurts:true"}).getStringList(); + config.get("block definitions", "brick", new String[]{"canmove:true", "movedef:brick", "supportiveblock:true", "fragile:0", "trapping:false", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "cobblestone", new String[]{"canmove:true", "movedef:cobblestone", "supportiveblock:true", "fragile:0", "trapping:false", "mass:2100", "strength:64000"}).getStringList(); + config.get("block definitions", "dirt", new String[]{"canmove:true", "movedef:dirt", "supportiveblock:false", "fragile:0", "trapping:true", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "dispenser", new String[]{"canmove:no", "movedef:default", "supportiveblock:true", "fragile:0", "trapping:false", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "gemblock", new String[]{"canmove:no", "movedef:default", "supportiveblock:false", "fragile:0", "trapping:false", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "giantmushroom", new String[]{"canmove:false", "movedef:default", "supportiveblock:false", "fragile:1", "trapping:false", "mass:40", "strength:10"}).getStringList(); + config.get("block definitions", "grass", new String[]{"canmove:true", "movedef:grass", "supportiveblock:false", "fragile:0", "trapping:false", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "leaves", new String[]{"canmove:false", "movedef:leaves", "supportiveblock:false", "fragile:1", "trapping:false", "mass:40", "strength:10"}).getStringList(); + config.get("block definitions", "misc", new String[]{"canmove:false", "movedef:default", "supportiveblock:false", "fragile:2", "trapping:false", "mass:10", "strength:0"}).getStringList(); + config.get("block definitions", "piston", new String[]{"canmove:false", "movedef:default", "supportiveblock:true", "fragile:0", "trapping:false", "mass:1500", "strength:64000"}).getStringList(); + config.get("block definitions", "plants", new String[]{"canmove:false", "movedef:default", "supportiveblock:false", "fragile:1", "trapping:false", "mass:10", "strength:0"}).getStringList(); + config.get("block definitions", "sand", new String[]{"canmove:true", "movedef:sand", "supportiveblock:false", "fragile:0", "trapping:true", "mass:1700", "strength:64000"}).getStringList(); + config.get("block definitions", "stone", new String[]{"canmove:true", "movedef:stone", "supportiveblock:true", "fragile:0", "trapping:false", "mass:2500", "strength:64000"}).getStringList(); + config.get("block definitions", "stonebrick", new String[]{"canmove:true", "movedef:stonebrick", "supportiveblock:true", "fragile:0", "trapping:false", "mass:2500", "strength:64000"}).getStringList(); + config.get("block definitions", "wall", new String[]{"canmove:true", "movedef:wall", "supportiveblock:true", "fragile:0", "trapping:false", "mass:700", "strength:64000"}).getStringList(); + config.get("block definitions", "wood", new String[]{"canmove:true", "movedef:wood", "supportiveblock:true", "fragile:1", "trapping:false", "mass:500", "strength:2000"}).getStringList(); + config.get("block definitions", "wool", new String[]{"canmove:true", "movedef:wool", "supportiveblock:false", "fragile:1", "trapping:false", "mass:10", "strength:100"}).getStringList(); + categoryMap = config.getCategory("block definitions"); } @@ -227,8 +258,24 @@ else if (keyString.equals("movedef")) if (categoryMap == null || categoryMap.keySet().size() == 0) { + config.get("blocks", "bricks", new String[]{"minecraft:brick_block"}).getStringList(); + config.get("blocks", "cobblestone", new String[]{"minecraft:cobblestone", "minecraft:mossy_cobblestone", "minecraft:monster_egg:0:1:2:3:4:5"}).getStringList(); + config.get("blocks", "dirt", new String[]{"minecraft:dirt:0:1"}).getStringList(); + config.get("blocks", "dispenser", new String[]{"minecraft:dispenser:0:1:2:3:4:5", "minecraft:piston_extension", "minecraft:furnace:2:3:4:5", "minecraft:lit_furnace:2:3:4:5", "minecraft:dropper:0:1:2:3:4:5"}).getStringList(); + config.get("blocks", "gemblock", new String[]{"minecraft:lapis_block", "minecraft:redstone_block", "minecraft:emerald_block"}).getStringList(); + config.get("blocks", "giantmushroom", new String[]{"minecraft:brown_mushroom_block:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:red_mushroom_block:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15"}).getStringList(); + config.get("blocks", "grass", new String[]{"minecraft:grass:0:1", "minecraft:farmland", "minecraft:clay", "minecraft:mycelium"}).getStringList(); + config.get("blocks", "leaves", new String[]{"minecraft:leaves:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:leaves2:0:1:4:5:8:9:12:13"}).getStringList(); + config.get("blocks", "misc", new String[]{"minecraft:torch:1:2:3:4:5", "minecraft:wheat:0:1:2:3:4:5:6:7", "minecraft:cactus:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:reeds:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:nether_wart:0:1:2:3", "minecraft:cocoa:0:1:2:3", "minecraft:tripwire", "minecraft:string", "minecraft:flower_pot", "minecraft:carrots:0:1:2:3:4:5:6:7", "minecraft:potatoes:0:1:2:3:4:5:6:7"}).getStringList(); + config.get("blocks", "piston", new String[]{"minecraft:piston:0:1:2:3:4:5", "minecraft:sticky_piston:0:1:2:3:4:5"}).getStringList(); + config.get("blocks", "plants", new String[]{"minecraft:sapling:0:1:2:3:4:5", "minecraft:tallgrass", "minecraft:deadbush", "minecraft:yellow_flower", "minecraft:red_flower:0:1:2:3:4:5:6:7:8", "minecraft:double_plant:0:1:2:3:4:5", "minecraft:red_mushroom", "minecraft:brown_mushroom", "minecraft:snow_layer:0:1:2:3:4:5:6:7", "minecraft:glass_pane", "minecraft:pumpkin_seeds:0:1:2:3:4:5:6:7", "minecraft:melon_stem:0:1:2:3:4:5:6:7", "minecraft:vine:0:1:2:4:8", "minecraft:waterlily"}).getStringList(); config.get("blocks", "sand", new String[]{"minecraft:sand:0:1", "minecraft:soul_sand", "minecraft:gravel"}).getStringList(); - config.get("blocks", "cobblestone", new String[]{"minecraft:cobblestone", "minecraft:mossy_cobblestone"}).getStringList(); + config.get("blocks", "stone", new String[]{"minecraft:stone:0:1", "minecraft:sandstone:0:1:2"}).getStringList(); + config.get("blocks", "stonebrick", new String[]{"minecraft:stonebrick:0:1:2:3", "minecraft:quartz_block:0:1:2:3:4"}).getStringList(); + config.get("blocks", "wall", new String[]{"minecraft:cobblestone_wall:0:1"}).getStringList(); + config.get("blocks", "wood", new String[]{"minecraft:log:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:log2:0:1:4:5:8:9:12:13"}).getStringList(); + config.get("blocks", "wool", new String[]{"minecraft:wool:0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", "minecraft:sponge:0:1"}).getStringList(); + categoryMap = config.getCategory("blocks"); } diff --git a/blargerist/cake/blockphysics/ModInfo.java b/blargerist/cake/blockphysics/ModInfo.java index d559fe3..aa84b40 100644 --- a/blargerist/cake/blockphysics/ModInfo.java +++ b/blargerist/cake/blockphysics/ModInfo.java @@ -6,6 +6,6 @@ public final class ModInfo { public static final String MODID = "BlockPhysics"; - public static final String VERSION = "0.92b"; + public static final String VERSION = "0.931b"; public static final Logger Log = LogManager.getLogger(MODID); } \ No newline at end of file diff --git a/blargerist/cake/blockphysics/asm/modules/ModuleBlockFalling.java b/blargerist/cake/blockphysics/asm/modules/ModuleBlockFalling.java index a5f7a2d..4c42fcd 100644 --- a/blargerist/cake/blockphysics/asm/modules/ModuleBlockFalling.java +++ b/blargerist/cake/blockphysics/asm/modules/ModuleBlockFalling.java @@ -23,7 +23,8 @@ public String[] getClassesToTransform() "net.minecraft.block.BlockFalling", "net.minecraft.world.WorldServer", "net.minecraft.block.Block", - "net.minecraft.entity.item.EntityFallingBlock" + "net.minecraft.entity.item.EntityFallingBlock", + "net.minecraft.entity.Entity" }; } @@ -124,6 +125,19 @@ else if (transformedName.equals("net.minecraft.entity.item.EntityFallingBlock")) return ASMHelper.writeClassToBytes(classNode); } + else if (transformedName.equals("net.minecraft.entity.Entity")) + { + ModInfo.Log.info("Transforming class: " + transformedName); + MethodNode methodNode = ASMHelper.findMethodNodeOfClass(classNode, "func_70091_d", "(DDD)V"); + if (methodNode != null) + { + injectIfBlockFalling(methodNode); + } + else + throw new RuntimeException("Could not find moveEntity method in " + transformedName); + + return ASMHelper.writeClassToBytes(classNode); + } return bytes; } @@ -246,11 +260,11 @@ public void insertEntityFallingBlockOnUpdateHook(MethodNode method) AbstractInsnNode target = ASMHelper.findFirstInstruction(method); if (target == null) - throw new RuntimeException("Unexpected instruction patter in EntityFallingBlock.onUpdate"); + throw new RuntimeException("Unexpected instruction pattern in EntityFallingBlock.onUpdate"); InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); - toInject.add(new MethodInsnNode(INVOKESTATIC, "blargerist/cake/blockphysics/events/BPEventHandler", "entityFallingBlockUpdate", "(Lnet/minecraft/entity/item/EntityFallingBlock;)V", false)); + toInject.add(new MethodInsnNode(INVOKESTATIC, "blargerist/cake/blockphysics/util/EntityMove", "onUpdate", "(Lnet/minecraft/entity/item/EntityFallingBlock;)V", false)); toInject.add(new InsnNode(RETURN)); method.instructions.insertBefore(target, toInject); @@ -261,15 +275,15 @@ public void insertFrustumNoClip1(MethodNode method) AbstractInsnNode target = ASMHelper.findLastInstructionWithOpcode(method, RETURN); if (target == null) - throw new RuntimeException("Unexpected instruction patter in EntityFallingBlock.(World)"); + throw new RuntimeException("Unexpected instruction pattern in EntityFallingBlock.(World)"); InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new FieldInsnNode(PUTFIELD, "net/minecraft/entity/item/EntityFallingBlock", "field_70158_ak", "Z")); - toInject.add(new VarInsnNode(ALOAD, 0)); - toInject.add(new InsnNode(ICONST_1)); - toInject.add(new FieldInsnNode(PUTFIELD, "net/minecraft/entity/item/EntityFallingBlock", "field_70145_X", "Z")); + //toInject.add(new VarInsnNode(ALOAD, 0)); + //toInject.add(new InsnNode(ICONST_1)); + //toInject.add(new FieldInsnNode(PUTFIELD, "net/minecraft/entity/item/EntityFallingBlock", "field_70145_X", "Z")); method.instructions.insertBefore(target, toInject); } @@ -279,7 +293,7 @@ public void insertFrustumNoClip2(MethodNode method) AbstractInsnNode target = ASMHelper.findLastInstructionWithOpcode(method, RETURN); if (target == null) - throw new RuntimeException("Unexpected instruction patter in EntityFallingBlock.(World;DDDBlock;I)"); + throw new RuntimeException("Unexpected instruction pattern in EntityFallingBlock.(World;DDDBlock;I)"); InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(ALOAD, 0)); @@ -291,4 +305,34 @@ public void insertFrustumNoClip2(MethodNode method) method.instructions.insertBefore(target, toInject); } + + public void injectIfBlockFalling(MethodNode method) + { + InsnList toFind = new InsnList(); + toFind.add(new VarInsnNode(ALOAD, 0)); + toFind.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/entity/Entity", "func_145775_I", "()V", false)); + + AbstractInsnNode start = ASMHelper.find(method.instructions, toFind); + AbstractInsnNode end = ASMHelper.move(start, 1); + + if (start == null || end == null) + throw new RuntimeException("Unexpected instructions pattern in Entity.moveEntity"); + + InsnList firstInject = new InsnList(); + firstInject.add(new VarInsnNode(ALOAD, 0)); + firstInject.add(new TypeInsnNode(INSTANCEOF, "net/minecraft/entity/item/EntityFallingBlock")); + LabelNode label1 = new LabelNode(); + firstInject.add(new JumpInsnNode(IFEQ, label1)); + firstInject.add(new VarInsnNode(ALOAD, 0)); + firstInject.add(new MethodInsnNode(INVOKESTATIC, "blargerist/cake/blockphysics/util/EntityMove", "checkEntityBlockCollisions", "(Lnet/minecraft/entity/Entity;)V", false)); + LabelNode label2 = new LabelNode(); + firstInject.add(new JumpInsnNode(GOTO, label2)); + firstInject.add(label1); + + InsnList secondInject = new InsnList(); + secondInject.add(label2); + + method.instructions.insertBefore(start, firstInject); + method.instructions.insert(end, secondInject); + } } \ No newline at end of file diff --git a/blargerist/cake/blockphysics/events/BPEventHandler.java b/blargerist/cake/blockphysics/events/BPEventHandler.java index 13161b6..a60bc93 100644 --- a/blargerist/cake/blockphysics/events/BPEventHandler.java +++ b/blargerist/cake/blockphysics/events/BPEventHandler.java @@ -16,8 +16,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.world.BlockEvent.PlaceEvent; +import blargerist.cake.blockphysics.ModInfo; import blargerist.cake.blockphysics.util.BlockMove; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -87,106 +87,8 @@ else if (block == Blocks.fire) } } - public static void entityFallingBlockUpdate(EntityFallingBlock entity) + public static void onFragileBlockCollision(Entity entity, int x, int y, int z) { - if (entity.func_145805_f().getMaterial() == Material.air) - { - entity.setDead(); - } - else - { - entity.prevPosX = entity.posX; - entity.prevPosY = entity.posY; - entity.prevPosZ = entity.posZ; - ++entity.field_145812_b; - entity.motionY -= 0.03999999910593033D; - entity.moveEntity(entity.motionX, entity.motionY, entity.motionZ); - entity.motionX *= 0.9800000190734863D; - entity.motionY *= 0.9800000190734863D; - entity.motionZ *= 0.9800000190734863D; - - if (!entity.worldObj.isRemote) - { - int i = MathHelper.floor_double(entity.posX); - int j = MathHelper.floor_double(entity.posY); - int k = MathHelper.floor_double(entity.posZ); - - if (entity.field_145812_b == 1) - { - if (entity.worldObj.getBlock(i, j, k) != entity.func_145805_f()) - { - entity.setDead(); - return; - } - - entity.worldObj.setBlockToAir(i, j, k); - } - else if (entity.field_145812_b == 4) - { - entity.noClip = false; - } - - if (entity.onGround) - { - entity.motionX *= 0.699999988079071D; - entity.motionZ *= 0.699999988079071D; - entity.motionY *= -0.5D; - - if (entity.worldObj.getBlock(i, j, k) != Blocks.piston_extension) - { - - if (entity.worldObj.canPlaceEntityOnSide(entity.func_145805_f(), i, j, k, true, 1, (Entity)null, (ItemStack)null) && !BlockFalling.func_149831_e(entity.worldObj, i, j - 1, k) && entity.worldObj.setBlock(i, j, k, entity.func_145805_f(), entity.field_145814_a, 3)) - { - entity.setDead(); - - if (entity.func_145805_f() instanceof BlockFalling) - { - ((BlockFalling)entity.func_145805_f()).func_149828_a(entity.worldObj, i, j, k, entity.field_145814_a); - } - - if (entity.field_145810_d != null && entity.func_145805_f() instanceof ITileEntityProvider) - { - TileEntity tileentity = entity.worldObj.getTileEntity(i, j, k); - - if (tileentity != null) - { - NBTTagCompound nbttagcompound = new NBTTagCompound(); - tileentity.writeToNBT(nbttagcompound); - Iterator iterator = entity.field_145810_d.func_150296_c().iterator(); - - while (iterator.hasNext()) - { - String s = (String)iterator.next(); - NBTBase nbtbase = entity.field_145810_d.getTag(s); - - if (!s.equals("x") && !s.equals("y") && !s.equals("z")) - { - nbttagcompound.setTag(s, nbtbase.copy()); - } - } - - tileentity.readFromNBT(nbttagcompound); - tileentity.markDirty(); - } - } - } - else if (entity.field_145813_c && entity.field_145812_b > 600) - { - entity.setDead(); - entity.entityDropItem(new ItemStack(entity.func_145805_f(), 1, entity.func_145805_f().damageDropped(entity.field_145814_a)), 0.0F); - } - } - } - else if (entity.field_145812_b > 100 && !entity.worldObj.isRemote && (j < 1 || j > 256) || entity.field_145812_b > 600) - { - if (entity.field_145813_c) - { - entity.entityDropItem(new ItemStack(entity.func_145805_f(), 1, entity.func_145805_f().damageDropped(entity.field_145814_a)), 0.0F); - } - - entity.setDead(); - } - } - } + entity.worldObj.setBlockToAir(x, y, z); } } \ No newline at end of file diff --git a/blargerist/cake/blockphysics/util/BlockMove.java b/blargerist/cake/blockphysics/util/BlockMove.java index 02c2542..fd3faa5 100644 --- a/blargerist/cake/blockphysics/util/BlockMove.java +++ b/blargerist/cake/blockphysics/util/BlockMove.java @@ -9,6 +9,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import blargerist.cake.blockphysics.ModConfig; +import blargerist.cake.blockphysics.ModInfo; public class BlockMove { @@ -32,17 +33,19 @@ public static void fall(World world, int x, int y, int z) if (blockDef.canMove) { MoveDef moveDef = DefinitionMaps.getMovedef(blockDef.id); - + //TODO use an array to store blocks in the area as they are required, to cut down on use of world.getblock if (!floating(world, x, y, z, moveDef.floatingRadius, moveDef.floatingBlock, moveDef.floatingMeta)) { - boolean canFall = canMoveTo(world, x, y - 1, z, blockDef.mass / 10); + int canFall = canMoveTo(world, x, y - 1, z, blockDef.mass / 10); - if (canFall && (moveDef.moveType == 1 || moveDef.moveType == 2)) + if (canFall != 0 && (moveDef.moveType == 1 || moveDef.moveType == 2)) { if (!hanging(world, x, y, z, moveDef.hanging, blockName, meta)) { if (!attached(world, x, y, z, moveDef.attached, blockName, meta)) { + if (!tree(world, x, y, z, moveDef.tree, blockName, meta)) + { if (!nCorbel(world, x, y, z, moveDef.nCorbel)) { if (!corbel(world, x, y, z, moveDef.corbel, blockName, meta)) @@ -58,6 +61,10 @@ public static void fall(World world, int x, int y, int z) EntityFallingBlock entityfallingblock = new EntityFallingBlock(world, (double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), block, meta); entityfallingblock.func_145806_a(blockDef.hurts); entityfallingblock.noClip = false; + if (canFall == 2) + { + world.setBlockToAir(x, y - 1, z); + } world.spawnEntityInWorld(entityfallingblock); return; } @@ -66,10 +73,10 @@ public static void fall(World world, int x, int y, int z) } } } - } + }} } } - else if (!canFall && moveDef.moveType == 2 && moveDef.slideChance >= (rand.nextInt(100) + 1)) + else if (canFall == 0 && moveDef.moveType == 2 && moveDef.slideChance >= (rand.nextInt(100) + 1)) { String[] slideDirs = new String[8]; int length = 0; @@ -78,25 +85,25 @@ else if (!canFall && moveDef.moveType == 2 && moveDef.slideChance >= (rand.nextI boolean east = false; boolean west = false; - if (canMoveTo(world, x, y, z + 1, blockDef.mass) && canMoveTo(world, x, y - 1, z + 1, blockDef.mass)) + if (canMoveTo(world, x, y, z + 1, blockDef.mass) == 1 && canMoveTo(world, x, y - 1, z + 1, blockDef.mass) == 1) { slideDirs[length] = "north"; length++; north = true; } - if (canMoveTo(world, x, y, z - 1, blockDef.mass) && canMoveTo(world, x, y - 1, z - 1, blockDef.mass)) + if (canMoveTo(world, x, y, z - 1, blockDef.mass) == 1 && canMoveTo(world, x, y - 1, z - 1, blockDef.mass) == 1) { slideDirs[length] = "south"; length++; south = true; } - if (canMoveTo(world, x + 1, y, z, blockDef.mass) && canMoveTo(world, x + 1, y - 1, z, blockDef.mass)) + if (canMoveTo(world, x + 1, y, z, blockDef.mass) == 1 && canMoveTo(world, x + 1, y - 1, z, blockDef.mass) == 1) { slideDirs[length] = "east"; length++; east = true; } - if (canMoveTo(world, x - 1, y, z, blockDef.mass) && canMoveTo(world, x - 1, y - 1, z, blockDef.mass)) + if (canMoveTo(world, x - 1, y, z, blockDef.mass) == 1 && canMoveTo(world, x - 1, y - 1, z, blockDef.mass) == 1) { slideDirs[length] = "west"; length++; @@ -106,22 +113,22 @@ else if (!canFall && moveDef.moveType == 2 && moveDef.slideChance >= (rand.nextI { if ((north || south) && (east || west)) { - if (north && east && canMoveTo(world, x + 1, y, z + 1, blockDef.mass) && canMoveTo(world, x + 1, y - 1, z + 1, blockDef.mass)) + if (north && east && canMoveTo(world, x + 1, y, z + 1, blockDef.mass) == 1 && canMoveTo(world, x + 1, y - 1, z + 1, blockDef.mass) == 1) { slideDirs[length] = "northeast"; length++; } - if (north && west && canMoveTo(world, x - 1, y, z + 1, blockDef.mass) && canMoveTo(world, x - 1, y - 1, z + 1, blockDef.mass)) + if (north && west && canMoveTo(world, x - 1, y, z + 1, blockDef.mass) == 1 && canMoveTo(world, x - 1, y - 1, z + 1, blockDef.mass) == 1) { slideDirs[length] = "northwest"; length++; } - if (south && east && canMoveTo(world, x + 1, y, z - 1, blockDef.mass) && canMoveTo(world, x + 1, y - 1, z - 1, blockDef.mass)) + if (south && east && canMoveTo(world, x + 1, y, z - 1, blockDef.mass) == 1 && canMoveTo(world, x + 1, y - 1, z - 1, blockDef.mass) == 1) { slideDirs[length] = "southeast"; length++; } - if (south && west && canMoveTo(world, x - 1, y, z - 1, blockDef.mass) && canMoveTo(world, x - 1, y - 1, z - 1, blockDef.mass)) + if (south && west && canMoveTo(world, x - 1, y, z - 1, blockDef.mass) == 1 && canMoveTo(world, x - 1, y - 1, z - 1, blockDef.mass) == 1) { slideDirs[length] = "southwest"; length++; @@ -233,22 +240,26 @@ else if (moveDef.moveType == 3) } } - private static boolean canMoveTo(World world, int x, int y, int z, int mass) + public static int canMoveTo(World world, int x, int y, int z, int mass) { Block block = world.getBlock(x, y, z); if (block == Blocks.air) { - return true; + return 1; } if (block.getBlockHardness(world, x, y, z) == -1) { - return false; + return 0; } String blockName = Block.blockRegistry.getNameForObject(block); int meta = world.getBlockMetadata(x, y, z); BlockDef blockDef = DefinitionMaps.getBlockDef(blockName, meta); + if ((blockDef.fragile > 0 && blockDef.strength < mass)) + { + return 2; + } Material material = block.getMaterial(); - return material == Material.air || material == Material.fire || material.isLiquid() || material == Material.plants || material == Material.vine || material == Material.circuits || (blockDef.fragile > 0 && blockDef.strength < mass); + return (material == Material.air || material == Material.fire || material.isLiquid() || material == Material.plants || material == Material.vine || material == Material.circuits) ? 1 : 0; } public static boolean playersWithinRange(World world, int x, int y, int z) @@ -333,6 +344,7 @@ else if (!sameBlock(blockName, meta, blockName2, meta2)) break; } } + for (i = 1; i <= attached; i++) { blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y, z)); @@ -346,6 +358,7 @@ else if (!sameBlock(blockName, meta, blockName2, meta2)) break; } } + for (i = 1; i <= attached; i++) { blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z + i)); @@ -359,6 +372,7 @@ else if (!sameBlock(blockName, meta, blockName2, meta2)) break; } } + for (i = 1; i <= attached; i++) { blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z - i)); @@ -880,9 +894,205 @@ private static boolean branch(World world, int x, int y, int z, String blockName } return false; } + + private static boolean tree(World world, int x, int y, int z, int tree, String blockName, int meta) + { + if (tree <= 0) + { + return false; + } + + String blockName2; + int meta2; + int i; + String blockName3; + int meta3; + int i2; + + for (i = 1; i <= tree; i++) + { + blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x + i, y, z)); + meta2 = world.getBlockMetadata(x + i, y, z); + if (DefinitionMaps.getBlockDef(blockName2, meta2).supportiveBlock) + { + return true; + } + else if (!sameBlock(blockName, meta, blockName2, meta2)) + { + break; + } + else + { + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + i, y + 1, z)); + meta3 = world.getBlockMetadata(x + i, y + 1, z); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + i, y + 1, z)); + meta3 = world.getBlockMetadata(x + i, y - 1, z); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + i, y, z + 1)); + meta3 = world.getBlockMetadata(x + i, y, z + 1); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + i, y, z - 1)); + meta3 = world.getBlockMetadata(x + i, y, z - 1); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + } + } + + for (i = 1; i <= tree; i++) + { + blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y, z)); + meta2 = world.getBlockMetadata(x - i, y, z); + if (DefinitionMaps.getBlockDef(blockName2, meta2).supportiveBlock) + { + return true; + } + else if (!sameBlock(blockName, meta, blockName2, meta2)) + { + break; + } + else + { + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y + 1, z)); + meta3 = world.getBlockMetadata(x - i, y + 1, z); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y - 1, z)); + meta3 = world.getBlockMetadata(x - i, y - 1, z); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y, z + 1)); + meta3 = world.getBlockMetadata(x - i, y, z + 1); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - i, y, z - 1)); + meta3 = world.getBlockMetadata(x - i, y, z - 1); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + } + } + + for (i = 1; i <= tree; i++) + { + blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z + i)); + meta2 = world.getBlockMetadata(x, y, z + i); + if (DefinitionMaps.getBlockDef(blockName2, meta2).supportiveBlock) + { + return true; + } + else if (!sameBlock(blockName, meta, blockName2, meta2)) + { + break; + } + else + { + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x, y + 1, z + i)); + meta3 = world.getBlockMetadata(x, y + 1, z + i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x, y - 1, z + i)); + meta3 = world.getBlockMetadata(x, y - 1, z + i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + 1, y, z + i)); + meta3 = world.getBlockMetadata(x + 1, y, z + i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - 1, y, z + i)); + meta3 = world.getBlockMetadata(x - 1, y, z + i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + } + } + + for (i = 1; i <= tree; i++) + { + blockName2 = Block.blockRegistry.getNameForObject(world.getBlock(x, y, z - i)); + meta2 = world.getBlockMetadata(x, y, z - i); + if (DefinitionMaps.getBlockDef(blockName2, meta2).supportiveBlock) + { + return true; + } + else if (!sameBlock(blockName, meta, blockName2, meta2)) + { + break; + } + else + { + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x, y + 1, z - i)); + meta3 = world.getBlockMetadata(x, y + 1, z - i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x, y - 1, z - i)); + meta3 = world.getBlockMetadata(x, y - 1, z - i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x + 1, y, z - i)); + meta3 = world.getBlockMetadata(x + 1, y, z - i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + blockName3 = Block.blockRegistry.getNameForObject(world.getBlock(x - 1, y, z - i)); + meta3 = world.getBlockMetadata(x - 1, y, z - i); + if (DefinitionMaps.getBlockDef(blockName3, meta3).supportiveBlock) + { + return true; + } + } + } + return false; + } private static boolean sameBlock(String blockName, int blockMetadata, String name, int meta) { + if (blockName.equals(name)) + { + if (blockName.equals("minecraft:leaves") || blockName.equals("minecraft:leaves2")) + { + return iunno(blockMetadata) == iunno(meta); + } + } return blockName.equals(name) && blockMetadata == meta; } + + private static int iunno(int i) + { + while (i > 3) + { + i -= 4; + } + return i; + } } \ No newline at end of file diff --git a/blargerist/cake/blockphysics/util/EntityMove.java b/blargerist/cake/blockphysics/util/EntityMove.java new file mode 100644 index 0000000..a42706a --- /dev/null +++ b/blargerist/cake/blockphysics/util/EntityMove.java @@ -0,0 +1,421 @@ +package blargerist.cake.blockphysics.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import blargerist.cake.blockphysics.ModInfo; +import blargerist.cake.blockphysics.events.BPEventHandler; +import net.minecraft.block.Block; +import net.minecraft.block.BlockFalling; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ReportedException; + +public class EntityMove +{ + public static void onUpdate(EntityFallingBlock entity) + { + if (entity.func_145805_f().getMaterial() == Material.air) + { + entity.setDead(); + } + else + { + entity.prevPosX = entity.posX; + entity.prevPosY = entity.posY; + entity.prevPosZ = entity.posZ; + ++entity.field_145812_b; + entity.motionY -= 0.03999999910593033D; + entity.moveEntity(entity.motionX, entity.motionY, entity.motionZ); + entity.motionX *= 0.9800000190734863D; + entity.motionY *= 0.9800000190734863D; + entity.motionZ *= 0.9800000190734863D; + + if (!entity.worldObj.isRemote) + { + int i = MathHelper.floor_double(entity.posX); + int j = MathHelper.floor_double(entity.posY); + int k = MathHelper.floor_double(entity.posZ); + + if (entity.field_145812_b == 1) + { + if (entity.worldObj.getBlock(i, j, k) != entity.func_145805_f()) + { + entity.setDead(); + return; + } + + entity.worldObj.setBlockToAir(i, j, k); + } + else if (entity.field_145812_b == 4) + { + entity.noClip = false; + } + + if (BlockMove.canMoveTo(entity.worldObj, i, j - 1, k, DefinitionMaps.getBlockDef(Block.blockRegistry.getNameForObject(entity.func_145805_f()), entity.field_145814_a).mass) == 2) + { + entity.worldObj.setBlockToAir(i, j - 1, k); + } + + if (entity.onGround) + { + if (entity.motionX < 0.0025 && entity.motionX > -0.0025 && entity.motionZ < 0.0025 && entity.motionZ > -0.0025) + { + if (entity.posX > Math.round(entity.posX)) + { + ModInfo.Log.info("Entity posX > " + entity.posX); + entity.motionX = 0.07; + } + else if (entity.posX < Math.round(entity.posX)) + { + ModInfo.Log.info("Entity posX < " + entity.posX); + entity.motionX = -0.07; + } + if (entity.posZ > Math.round(entity.posZ)) + { + ModInfo.Log.info("Entity posZ > " + entity.posZ); + entity.motionZ = 0.07; + } + else if (entity.posZ < Math.round(entity.posZ)) + { + ModInfo.Log.info("Entity posZ < " + entity.posZ); + entity.motionZ = -0.07; + } + } + entity.motionX *= 0.899999988079071D; + entity.motionZ *= 0.899999988079071D; + entity.motionY *= -0.5D; + + if (entity.worldObj.getBlock(i, j, k) != Blocks.piston_extension) + { + + if (entity.worldObj.canPlaceEntityOnSide(entity.func_145805_f(), i, j, k, true, 1, (Entity)null, (ItemStack)null) && !BlockFalling.func_149831_e(entity.worldObj, i, j - 1, k) && entity.worldObj.setBlock(i, j, k, entity.func_145805_f(), entity.field_145814_a, 3)) + { + entity.setDead(); + + if (entity.func_145805_f() instanceof BlockFalling) + { + ((BlockFalling)entity.func_145805_f()).func_149828_a(entity.worldObj, i, j, k, entity.field_145814_a); + } + + if (entity.field_145810_d != null && entity.func_145805_f() instanceof ITileEntityProvider) + { + TileEntity tileentity = entity.worldObj.getTileEntity(i, j, k); + + if (tileentity != null) + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + tileentity.writeToNBT(nbttagcompound); + Iterator iterator = entity.field_145810_d.func_150296_c().iterator(); + + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + NBTBase nbtbase = entity.field_145810_d.getTag(s); + + if (!s.equals("x") && !s.equals("y") && !s.equals("z")) + { + nbttagcompound.setTag(s, nbtbase.copy()); + } + } + + tileentity.readFromNBT(nbttagcompound); + tileentity.markDirty(); + } + } + } + else if (entity.field_145813_c && (entity.field_145812_b > 600 || (entity.field_145812_b > 200 && entity.onGround))) + { + entity.setDead(); + entity.entityDropItem(new ItemStack(entity.func_145805_f(), 1, entity.func_145805_f().damageDropped(entity.field_145814_a)), 0.0F); + } + } + } + else if (entity.field_145812_b > 100 && !entity.worldObj.isRemote && (j < 1 || j > 256)) + { + if (entity.field_145813_c) + { + entity.entityDropItem(new ItemStack(entity.func_145805_f(), 1, entity.func_145805_f().damageDropped(entity.field_145814_a)), 0.0F); + } + + entity.setDead(); + } + } + } + } + + public void moveEntity(EntityFallingBlock entity, double p_70091_1_, double p_70091_3_, double p_70091_5_) + { + if (entity.noClip) + { + entity.boundingBox.offset(p_70091_1_, p_70091_3_, p_70091_5_); + entity.posX = (entity.boundingBox.minX + entity.boundingBox.maxX) / 2.0D; + entity.posY = entity.boundingBox.minY + (double)entity.yOffset - (double)entity.ySize; + entity.posZ = (entity.boundingBox.minZ + entity.boundingBox.maxZ) / 2.0D; + } + else + { + entity.worldObj.theProfiler.startSection("move"); + entity.ySize *= 0.4F; + double d3 = entity.posX; + double d4 = entity.posY; + double d5 = entity.posZ; + + double d6 = p_70091_1_; + double d7 = p_70091_3_; + double d8 = p_70091_5_; + AxisAlignedBB axisalignedbb = entity.boundingBox.copy(); + + List list = entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox.addCoord(p_70091_1_, p_70091_3_, p_70091_5_)); + + for (int i = 0; i < list.size(); ++i) + { + p_70091_3_ = ((AxisAlignedBB)list.get(i)).calculateYOffset(entity.boundingBox, p_70091_3_); + } + + entity.boundingBox.offset(0.0D, p_70091_3_, 0.0D); + + if (!entity.field_70135_K && d7 != p_70091_3_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + boolean flag1 = entity.onGround || d7 != p_70091_3_ && d7 < 0.0D; + int j; + + for (j = 0; j < list.size(); ++j) + { + p_70091_1_ = ((AxisAlignedBB)list.get(j)).calculateXOffset(entity.boundingBox, p_70091_1_); + } + + entity.boundingBox.offset(p_70091_1_, 0.0D, 0.0D); + + if (!entity.field_70135_K && d6 != p_70091_1_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + for (j = 0; j < list.size(); ++j) + { + p_70091_5_ = ((AxisAlignedBB)list.get(j)).calculateZOffset(entity.boundingBox, p_70091_5_); + } + + entity.boundingBox.offset(0.0D, 0.0D, p_70091_5_); + + if (!entity.field_70135_K && d8 != p_70091_5_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + double d10; + double d11; + int k; + double d12; + + if (entity.stepHeight > 0.0F && flag1 && entity.ySize < 0.05F && (d6 != p_70091_1_ || d8 != p_70091_5_)) + { + d12 = p_70091_1_; + d10 = p_70091_3_; + d11 = p_70091_5_; + p_70091_1_ = d6; + p_70091_3_ = (double)entity.stepHeight; + p_70091_5_ = d8; + AxisAlignedBB axisalignedbb1 = entity.boundingBox.copy(); + entity.boundingBox.setBB(axisalignedbb); + list = entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox.addCoord(d6, p_70091_3_, d8)); + + for (k = 0; k < list.size(); ++k) + { + p_70091_3_ = ((AxisAlignedBB)list.get(k)).calculateYOffset(entity.boundingBox, p_70091_3_); + } + + entity.boundingBox.offset(0.0D, p_70091_3_, 0.0D); + + if (!entity.field_70135_K && d7 != p_70091_3_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + for (k = 0; k < list.size(); ++k) + { + p_70091_1_ = ((AxisAlignedBB)list.get(k)).calculateXOffset(entity.boundingBox, p_70091_1_); + } + + entity.boundingBox.offset(p_70091_1_, 0.0D, 0.0D); + + if (!entity.field_70135_K && d6 != p_70091_1_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + for (k = 0; k < list.size(); ++k) + { + p_70091_5_ = ((AxisAlignedBB)list.get(k)).calculateZOffset(entity.boundingBox, p_70091_5_); + } + + entity.boundingBox.offset(0.0D, 0.0D, p_70091_5_); + + if (!entity.field_70135_K && d8 != p_70091_5_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + + if (!entity.field_70135_K && d7 != p_70091_3_) + { + p_70091_5_ = 0.0D; + p_70091_3_ = 0.0D; + p_70091_1_ = 0.0D; + } + else + { + p_70091_3_ = (double)(-entity.stepHeight); + + for (k = 0; k < list.size(); ++k) + { + p_70091_3_ = ((AxisAlignedBB)list.get(k)).calculateYOffset(entity.boundingBox, p_70091_3_); + } + + entity.boundingBox.offset(0.0D, p_70091_3_, 0.0D); + } + + if (d12 * d12 + d11 * d11 >= p_70091_1_ * p_70091_1_ + p_70091_5_ * p_70091_5_) + { + p_70091_1_ = d12; + p_70091_3_ = d10; + p_70091_5_ = d11; + entity.boundingBox.setBB(axisalignedbb1); + } + } + + entity.worldObj.theProfiler.endSection(); + entity.worldObj.theProfiler.startSection("rest"); + entity.posX = (entity.boundingBox.minX + entity.boundingBox.maxX) / 2.0D; + entity.posY = entity.boundingBox.minY + (double)entity.yOffset - (double)entity.ySize; + entity.posZ = (entity.boundingBox.minZ + entity.boundingBox.maxZ) / 2.0D; + entity.isCollidedHorizontally = d6 != p_70091_1_ || d8 != p_70091_5_; + entity.isCollidedVertically = d7 != p_70091_3_; + entity.onGround = d7 != p_70091_3_ && d7 < 0.0D; + entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically; + updateFallState(entity, p_70091_3_, entity.onGround); + + if (d6 != p_70091_1_) + { + entity.motionX = 0.0D; + } + + if (d7 != p_70091_3_) + { + entity.motionY = 0.0D; + } + + if (d8 != p_70091_5_) + { + entity.motionZ = 0.0D; + } + + d12 = entity.posX - d3; + d10 = entity.posY - d4; + d11 = entity.posZ - d5; + + try + { + checkEntityBlockCollisions(entity); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Checking entity block collision"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Entity being checked for collision"); + entity.addEntityCrashInfo(crashreportcategory); + throw new ReportedException(crashreport); + } + + entity.worldObj.theProfiler.endSection(); + } + } + + protected void updateFallState(EntityFallingBlock entity, double p_70064_1_, boolean p_70064_3_) + { + if (p_70064_3_) + { + if (entity.fallDistance > 0.0F) + { + entity.fallDistance = 0.0F; + } + } + else if (p_70064_1_ < 0.0D) + { + entity.fallDistance = (float)((double)entity.fallDistance - p_70064_1_); + } + } + + public static void checkEntityBlockCollisions(Entity entity) + { + int i = MathHelper.floor_double(entity.boundingBox.minX + 0.001D); + int j = MathHelper.floor_double(entity.boundingBox.minY + 0.001D); + int k = MathHelper.floor_double(entity.boundingBox.minZ + 0.001D); + int l = MathHelper.floor_double(entity.boundingBox.maxX - 0.001D); + int i1 = MathHelper.floor_double(entity.boundingBox.maxY - 0.001D); + int j1 = MathHelper.floor_double(entity.boundingBox.maxZ - 0.001D); + + if (entity.worldObj.checkChunksExist(i, j, k, l, i1, j1)) + { + for (int k1 = i; k1 <= l; ++k1) + { + for (int l1 = j; l1 <= i1; ++l1) + { + for (int i2 = k; i2 <= j1; ++i2) + { + Block block = entity.worldObj.getBlock(k1, l1, i2); + + int meta = entity.worldObj.getBlockMetadata(k1, l1, i2); + String blockName = Block.blockRegistry.getNameForObject(block); + if (DefinitionMaps.getBlockDef(Block.blockRegistry.getNameForObject(block), entity.worldObj.getBlockMetadata(k1, l1, i2)).fragile > 0) + { + ModInfo.Log.info("Block Fragile: " + blockName); + BPEventHandler.onFragileBlockCollision(entity, k1, l1, i2); + } + else + { + try + { + block.onEntityCollidedWithBlock(entity.worldObj, k1, l1, i2, entity); + } + catch (Throwable throwable) + { + CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Colliding entity with block"); + CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being collided with"); + CrashReportCategory.func_147153_a(crashreportcategory, k1, l1, i2, block, entity.worldObj.getBlockMetadata(k1, l1, i2)); + throw new ReportedException(crashreport); + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/blargerist/cake/blockphysics/util/MoveDef.java b/blargerist/cake/blockphysics/util/MoveDef.java index c48961c..54888a6 100644 --- a/blargerist/cake/blockphysics/util/MoveDef.java +++ b/blargerist/cake/blockphysics/util/MoveDef.java @@ -16,8 +16,9 @@ public class MoveDef public String floatingBlock; public int floatingMeta; public boolean branch; // 0,1 + public int tree; - public MoveDef(String id1, int moveType1, int slideChance1, boolean ceiling1, int smallArc1, int bigArc1, int corbel1, int nCorbel1, int hanging1, int attached1, int floatingRadius1, String floatingBlock1, int floatingMeta1, boolean branch1) + public MoveDef(String id1, int moveType1, int slideChance1, boolean ceiling1, int smallArc1, int bigArc1, int corbel1, int nCorbel1, int hanging1, int attached1, int floatingRadius1, String floatingBlock1, int floatingMeta1, boolean branch1, int tree1) { id = id1; moveType = moveType1; @@ -33,6 +34,7 @@ public MoveDef(String id1, int moveType1, int slideChance1, boolean ceiling1, in floatingBlock = floatingBlock1; floatingMeta = floatingMeta1; branch = branch1; + tree = tree1; } public MoveDef(String id1) @@ -51,6 +53,7 @@ public MoveDef(String id1) floatingBlock = null; floatingMeta = 0; branch = false; + tree = 0; } public static void copyMoveDef(MoveDef def1, MoveDef def2) @@ -68,5 +71,6 @@ public static void copyMoveDef(MoveDef def1, MoveDef def2) def1.floatingBlock = def2.floatingBlock; def1.floatingMeta = def2.floatingMeta; def1.branch = def2.branch; + def1.tree = def2.tree; } } \ No newline at end of file diff --git a/mcmod.info b/mcmod.info index eeca97b..3ab7c1f 100644 --- a/mcmod.info +++ b/mcmod.info @@ -3,7 +3,7 @@ "modid": "BlockPhysics", "name": "BlockPhysics", "description": "Adds physics to blocks. Originally by id_miner.", - "version": "0.93b", + "version": "0.931b", "mcversion": "${mcversion}", "url": "", "updateUrl": "",