From f9139894ee733769330f22c3dd8e86c3f9bdef22 Mon Sep 17 00:00:00 2001 From: OldSerpskiStalker Date: Fri, 8 Nov 2024 13:59:04 +0500 Subject: [PATCH] Finish it later (Block Physics) --- .../DynamicSpawnControl.java | 34 +- .../RealisticBlockPhysics.java | 38 ++ .../entity/EntityRBPFallingBlock.java | 372 ++++++++++++++++++ .../RealisticExplosionPhysics.java | 54 +++ .../event/OnEventWorld.java | 33 ++ .../physics/IExplosionHandler.java | 7 + .../physics/PhysicsHandler.java | 57 +++ .../physics/RBPExplosionHandler.java | 9 + .../physics/VanillaExplosionHandler.java | 14 + 9 files changed, 606 insertions(+), 12 deletions(-) create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/RealisticBlockPhysics.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/entity/EntityRBPFallingBlock.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/RealisticExplosionPhysics.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/event/OnEventWorld.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/IExplosionHandler.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/PhysicsHandler.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/RBPExplosionHandler.java create mode 100644 dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/VanillaExplosionHandler.java diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/DynamicSpawnControl.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/DynamicSpawnControl.java index e7bfd34..550f614 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/DynamicSpawnControl.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/DynamicSpawnControl.java @@ -2,18 +2,15 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.common.event.FMLServerStoppedEvent; +import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import org.imesense.dynamicspawncontrol.core.api.IRecipes; import org.imesense.dynamicspawncontrol.core.field.UniqueField; import org.imesense.dynamicspawncontrol.core.register.*; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.RealisticExplosionPhysics; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.event.OnEventWorld; import org.imesense.dynamicspawncontrol.plugin.webslinger_1_12_2_2_2_4.capability.EventHandler; import org.imesense.dynamicspawncontrol.plugin.webslinger_1_12_2_2_2_4.capability.WebSlingerCapability; import org.imesense.dynamicspawncontrol.ai.zombie.event.OnBreakTorchEvent; @@ -91,7 +88,7 @@ public DynamicSpawnControl() * @throws IllegalAccessException */ @Mod.EventHandler - public synchronized void preInit(FMLPreInitializationEvent fmlPreInitializationEvent) throws IllegalAccessException + public void preInit(FMLPreInitializationEvent fmlPreInitializationEvent) throws IllegalAccessException { globalDirectory = fmlPreInitializationEvent.getModConfigurationDirectory(); @@ -131,7 +128,7 @@ public synchronized void preInit(FMLPreInitializationEvent fmlPreInitializationE * @param fmlInitializationEvent */ @Mod.EventHandler - public synchronized void init(FMLInitializationEvent fmlInitializationEvent) + public void init(FMLInitializationEvent fmlInitializationEvent) { IRecipes = new CraftItemWeb(); @@ -145,11 +142,14 @@ public synchronized void init(FMLInitializationEvent fmlInitializationEvent) * @param fmlPostInitializationEvent */ @Mod.EventHandler - public synchronized void postInit(FMLPostInitializationEvent fmlPostInitializationEvent) + public void postInit(FMLPostInitializationEvent fmlPostInitializationEvent) { //-' TODO: перенести это в отдельную инициализацию MinecraftForge.EVENT_BUS.register(new EventHandler()); MinecraftForge.EVENT_BUS.register(new OnBreakTorchEvent()); + MinecraftForge.EVENT_BUS.register(new OnEventWorld()); + + RealisticExplosionPhysics.postInit(fmlPostInitializationEvent); } /** @@ -157,7 +157,7 @@ public synchronized void postInit(FMLPostInitializationEvent fmlPostInitializati * @param fmlLoadCompleteEvent */ @Mod.EventHandler - public synchronized void onLoadComplete(FMLLoadCompleteEvent fmlLoadCompleteEvent) + public void onLoadComplete(FMLLoadCompleteEvent fmlLoadCompleteEvent) { ParserGenericJsonScript.readRules(); @@ -169,7 +169,7 @@ public synchronized void onLoadComplete(FMLLoadCompleteEvent fmlLoadCompleteEven * @param fmlServerStartingEvent */ @Mod.EventHandler - public synchronized void serverLoad(FMLServerStartingEvent fmlServerStartingEvent) + public void serverLoad(FMLServerStartingEvent fmlServerStartingEvent) { RegisterCommandClass.registerCommands(fmlServerStartingEvent); } @@ -179,11 +179,21 @@ public synchronized void serverLoad(FMLServerStartingEvent fmlServerStartingEven * @param fmlServerStoppedEvent */ @Mod.EventHandler - public synchronized void serverStopped(FMLServerStoppedEvent fmlServerStoppedEvent) + public void serverStopped(FMLServerStoppedEvent fmlServerStoppedEvent) { Cache.Instance.cleanActualCache(); Cache.Instance.cleanBufferCache(); Structure.STRUCTURES_CACHE.clean(); } + + /** + * + * @param fmlServerStoppingEvent + */ + @Mod.EventHandler + public static void onServerShutdown(FMLServerStoppingEvent fmlServerStoppingEvent) + { + RealisticExplosionPhysics.onServerShutdown(fmlServerStoppingEvent); + } } diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/RealisticBlockPhysics.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/RealisticBlockPhysics.java new file mode 100644 index 0000000..5870b7c --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/RealisticBlockPhysics.java @@ -0,0 +1,38 @@ +package org.imesense.dynamicspawncontrol.plugin.RealisticBlockPhysics_1_12_2_2_1_2; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.imesense.dynamicspawncontrol.plugin.RealisticBlockPhysics_1_12_2_2_1_2.entity.EntityRBPFallingBlock; + +import java.util.HashMap; + +public class RealisticBlockPhysics +{ + public static final EntityRBPFallingBlock summonFallingBlock(World worldIn, BlockPos pos, IBlockState blockState) { + return summonFallingBlock(worldIn, pos, blockState, 0.0D, 0.0D, 0.0D); + } + + public static final EntityRBPFallingBlock summonFallingBlock(World worldIn, BlockPos pos, IBlockState blockState, double motionX, double motionY, double motionZ) { + if (getBlockDefinition(worldIn, blockState) == null) { + return null; + } else { + EntityRBPFallingBlock entity = new EntityRBPFallingBlock(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), blockState); + entity.motionX = motionX; + entity.motionY = motionY; + entity.motionZ = motionZ; + return worldIn.spawnEntity(entity) ? entity : null; + } + } + + public static final BlockDefinition getBlockDefinition(World worldIn, IBlockState blockState) { + WorldDefinition worldDef = getWorldDefinition(worldIn); + if (worldDef == null) { + return null; + } else { + BlockDefinition physicsDefMeta = (BlockDefinition)((HashMap)blockDefinitions.get(worldDef)).get(GeneralUtil.getBlockRegistryName(blockState, true)); + BlockDefinition physicsDefAll = (BlockDefinition)((HashMap)blockDefinitions.get(worldDef)).get(GeneralUtil.getBlockRegistryName(blockState, false)); + return physicsDefMeta != null ? physicsDefMeta : physicsDefAll; + } + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/entity/EntityRBPFallingBlock.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/entity/EntityRBPFallingBlock.java new file mode 100644 index 0000000..a3877a4 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/RealisticBlockPhysics_1_12_2_2_1_2/entity/EntityRBPFallingBlock.java @@ -0,0 +1,372 @@ +package org.imesense.dynamicspawncontrol.plugin.RealisticBlockPhysics_1_12_2_2_1_2.entity; + +import com.google.common.collect.Lists; +import io.netty.buffer.ByteBuf; +import java.util.Iterator; +import java.util.List; +import javax.annotation.Nullable; +import net.minecraft.block.Block; +import net.minecraft.block.BlockAnvil; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.BlockDynamicLiquid; +import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.MoverType; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryHelper; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +//import xbigellx.rbp.RealisticBlockPhysics; +//import xbigellx.rbp.eventhandler.RBPFallingBlockEvent; +//import xbigellx.rbp.physics.BlockDefinition; +//import xbigellx.rbp.util.PhysicsUtil; + +public class EntityRBPFallingBlock extends Entity implements IEntityAdditionalSpawnData { + protected static final DataParameter ORIGIN; + private IBlockState fallTile; + private NBTTagCompound tileEntityData; + private int fallTime; + private boolean setBlock = true; + private double prevMotionY = 0.0D; + private BlockDefinition physicsDef; + private int entityDamageMax = 40; + private double entityDamage; + + public EntityRBPFallingBlock(World worldIn) { + super(worldIn); + } + + public EntityRBPFallingBlock(World worldIn, double x, double y, double z, IBlockState blockState) { + super(worldIn); + this.physicsDef = RealisticBlockPhysics.getBlockDefinition(worldIn, blockState); + if (this.physicsDef == null) { + this.setDead(); + } + + this.entityDamage = this.physicsDef.getEntityDamage(); + this.fallTile = blockState; + this.setSize(0.98F, 0.98F); + this.setPosition(x, y + (double)((1.0F - this.height) / 2.0F), z); + this.motionX = 0.0D; + this.motionY = 0.0D; + this.motionZ = 0.0D; + this.prevPosX = x; + this.prevPosY = y; + this.prevPosZ = z; + this.setOrigin(new BlockPos(this)); + TileEntity tileEntity = worldIn.getTileEntity(this.getPosition()); + if (tileEntity != null) { + this.tileEntityData = tileEntity.writeToNBT(new NBTTagCompound()); + if (blockState.getBlock() instanceof BlockContainer) { + if (tileEntity instanceof IInventory) { + ((IInventory)tileEntity).clear(); + } else { + this.tileEntityData = null; + } + } + } + + } + + public void onUpdate() { + if (this.fallTile.getMaterial() == Material.AIR) { + this.setDead(); + } else if (this.physicsDef == null && !this.world.isRemote) { + this.setDead(); + } else { + Block block = this.fallTile.getBlock(); + this.prevMotionY = this.motionY; + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + BlockPos pos; + if (this.fallTime++ == 0) { + pos = new BlockPos(this); + if (this.world.getBlockState(pos).getBlock() == block) { + this.world.setBlockToAir(pos); + } else if (!this.world.isRemote) { + this.setDead(); + return; + } + } + + if (!this.hasNoGravity()) { + this.motionY -= 0.03999999910593033D; + } + + this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); + if (!this.world.isRemote) { + pos = new BlockPos(this); + if (!this.onGround) { + if (this.fallTime > 100 && !this.world.isRemote && (pos.getY() < 1 || pos.getY() > 256) || this.fallTime > 600) { + this.setDead(); + } + } else { + IBlockState blockState = this.world.getBlockState(pos); + this.motionX *= 0.699999988079071D; + this.motionY *= 0.699999988079071D; + this.motionZ *= -0.5D; + if (blockState.getBlock() != Blocks.PISTON_EXTENSION) { + if (this.setBlock) { + BlockPos placePos = !PhysicsUtil.canBlockPassThrough(this.world, pos) ? pos.up() : pos; + boolean shouldBreak = Math.abs(this.prevMotionY) >= this.physicsDef.getBreakVelocityMinOnLanded() && Math.random() < this.physicsDef.getBreakChanceOnLanded(); + boolean shouldPlace; + if (!shouldBreak && RealisticBlockPhysics.getConfiguration().getProperty("main", "FallingBlockRelocation").getBoolean()) { + shouldPlace = true; + + while(shouldPlace) { + shouldPlace = false; + if (!PhysicsUtil.canBlockPassThrough(this.world, placePos)) { + placePos = placePos.add(0, 1, 0); + shouldPlace = true; + } + } + } + + this.setPosition((double)placePos.getX(), (double)placePos.getY(), (double)placePos.getZ()); + if (!(this.world.getBlockState(placePos).getBlock() instanceof BlockLiquid) && !(this.world.getBlockState(placePos).getBlock() instanceof BlockDynamicLiquid)) { + this.world.destroyBlock(placePos, PhysicsUtil.randomCrushedBlockDropItem()); + } + + shouldPlace = this.world.mayPlace(block, placePos, true, EnumFacing.UP, (Entity)null); + TileEntity tileEntity; + if (shouldPlace) { + if (RealisticBlockPhysics.getConfiguration().getProperty("main", "FallingBlockSounds").getBoolean()) { + this.world.playSound((EntityPlayer)null, this.getPosition(), this.getBlock().getBlock().getSoundType(this.getBlock(), this.world, this.getPosition(), (Entity)null).getPlaceSound(), SoundCategory.BLOCKS, 1.0F, 1.0F); + } + + if (!shouldBreak) { + BlockPos slideResult = PhysicsUtil.getRandomBlockSlidePos(this.world, this.getPosition(), this.physicsDef.getSlideChanceOnLanded()); + if (slideResult != null) { + this.setPosition((double)slideResult.getX() + 0.5D, (double)slideResult.getY(), (double)slideResult.getZ() + 0.5D); + MinecraftForge.EVENT_BUS.post(new RBPFallingBlockEvent.Slid(this, this.getPosition())); + return; + } + } + + this.setDead(); + this.world.setBlockState(placePos, this.fallTile); + if (block instanceof BlockFalling) { + ((BlockFalling)block).onEndFalling(this.world, pos, this.fallTile, blockState); + } + + if (this.tileEntityData != null && block.hasTileEntity(this.fallTile)) { + tileEntity = this.world.getTileEntity(placePos); + if (tileEntity != null) { + NBTTagCompound nbttagcompound = tileEntity.writeToNBT(new NBTTagCompound()); + Iterator var9 = this.tileEntityData.getKeySet().iterator(); + + while(var9.hasNext()) { + String key = (String)var9.next(); + NBTBase nbtbase = this.tileEntityData.getTag(key); + if (!"x".equals(key) && !"y".equals(key) && !"z".equals(key)) { + nbttagcompound.setTag(key, nbtbase.copy()); + } + } + + tileEntity.readFromNBT(nbttagcompound); + tileEntity.markDirty(); + } + } + + MinecraftForge.EVENT_BUS.post(new RBPFallingBlockEvent.Landed(this)); + if (shouldBreak) { + this.world.destroyBlock(this.getPosition(), PhysicsUtil.randomFallingBlockDropItem()); + } else { + boolean blocksCollide = PhysicsUtil.doBlocksCollide(this.world, this.getPosition(), this.getBlock(), this.getPosition().down(), this.world.getBlockState(this.getPosition().down())); + if (!blocksCollide && this.getBlock().getCollisionBoundingBox(this.world, this.getPosition()) != null) { + this.world.destroyBlock(this.getPosition(), PhysicsUtil.randomFallingBlockDropItem()); + } + } + } else { + this.setDead(); + this.world.playEvent(2001, pos, Block.getStateId(this.getBlock())); + block.dropBlockAsItem(this.world, pos, this.getBlock(), 0); + if (this.tileEntityData != null && block.hasTileEntity(this.fallTile) && block instanceof ITileEntityProvider) { + tileEntity = ((ITileEntityProvider)block).createNewTileEntity(this.world, 0); + tileEntity.readFromNBT(this.tileEntityData); + if (tileEntity instanceof IInventory) { + InventoryHelper.dropInventoryItems(this.world, pos, (IInventory)tileEntity); + } + } + } + } else { + this.setDead(); + } + } + } + } + + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + } + } + + public void fall(float distance, float damageMultiplier) { + Block block = this.fallTile.getBlock(); + if (this.entityDamage > 0.0D) { + int i = MathHelper.ceil(distance - 1.0F); + if (i > 0) { + List list = Lists.newArrayList(this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox())); + boolean flag = block == Blocks.ANVIL; + DamageSource damagesource = flag ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK; + Iterator var8 = list.iterator(); + + while(var8.hasNext()) { + Entity entity = (Entity)var8.next(); + if (entity instanceof EntityLivingBase) { + entity.attackEntityFrom(damagesource, (float)Math.min(MathHelper.floor((double)((float)i) * this.entityDamage), this.entityDamageMax)); + } + } + + if (flag && (double)this.rand.nextFloat() < 0.05000000074505806D + (double)i * 0.05D) { + int j = (Integer)this.fallTile.getValue(BlockAnvil.DAMAGE); + ++j; + if (j > 2) { + this.setBlock = false; + } else { + this.fallTile = this.fallTile.withProperty(BlockAnvil.DAMAGE, j); + } + } + } + } + + } + + public void writeSpawnData(ByteBuf buffer) { + NBTTagCompound compound = new NBTTagCompound(); + this.writeEntityToNBT(compound); + ByteBufUtils.writeTag(buffer, compound); + } + + public void readSpawnData(ByteBuf additionalData) { + NBTTagCompound compound = ByteBufUtils.readTag(additionalData); + this.readEntityFromNBT(compound); + } + + public void addEntityCrashInfo(CrashReportCategory category) { + super.addEntityCrashInfo(category); + if (this.fallTile != null) { + Block block = this.fallTile.getBlock(); + category.addCrashSection("Immitating block ID", Block.getIdFromBlock(block)); + category.addCrashSection("Immitating block data", block.getMetaFromState(this.fallTile)); + } + + } + + protected void writeEntityToNBT(NBTTagCompound compound) { + Block block = this.fallTile != null ? this.fallTile.getBlock() : Blocks.AIR; + ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(block); + compound.setString("Block", resourcelocation == null ? "" : resourcelocation.toString()); + compound.setByte("Data", (byte)block.getMetaFromState(this.fallTile)); + compound.setInteger("Time", this.fallTime); + compound.setDouble("EntityDamage", this.entityDamage); + compound.setInteger("EntityDamageMax", this.entityDamageMax); + if (this.tileEntityData != null) { + compound.setTag("TileEntityData", this.tileEntityData); + } + + } + + protected void readEntityFromNBT(NBTTagCompound compound) { + int i = compound.getByte("Data") & 255; + if (compound.hasKey("Block", 8)) { + this.fallTile = Block.getBlockFromName(compound.getString("Block")).getStateFromMeta(i); + } else if (compound.hasKey("TileID", 99)) { + this.fallTile = Block.getBlockById(compound.getInteger("TileID")).getStateFromMeta(i); + } else { + this.fallTile = Block.getBlockById(compound.getByte("Tile") & 255).getStateFromMeta(i); + } + + this.fallTime = compound.getInteger("Time"); + Block block = this.fallTile.getBlock(); + if (compound.hasKey("HurtEntities", 99)) { + this.entityDamage = compound.getDouble("EntityDamage"); + this.entityDamageMax = compound.getInteger("EntityDamageMax"); + } + + if (compound.hasKey("TileEntityData", 10)) { + this.tileEntityData = compound.getCompoundTag("TileEntityData"); + } + + if (block == null || block.getDefaultState().getMaterial() == Material.AIR) { + this.fallTile = Blocks.SAND.getDefaultState(); + } + + } + + protected void entityInit() { + this.preventEntitySpawning = true; + this.dataManager.register(ORIGIN, BlockPos.ORIGIN); + } + + public boolean canBeCollidedWith() { + return !this.isDead; + } + + @SideOnly(Side.CLIENT) + public boolean canRenderOnFire() { + return false; + } + + public boolean canBeAttackedWithItem() { + return false; + } + + public boolean ignoreItemEntityData() { + return true; + } + + protected boolean canTriggerWalking() { + return false; + } + + @SideOnly(Side.CLIENT) + public World getWorldObj() { + return this.world; + } + + @Nullable + public IBlockState getBlock() { + return this.fallTile; + } + + public void setOrigin(BlockPos pos) { + this.dataManager.set(ORIGIN, pos); + } + + @SideOnly(Side.CLIENT) + public BlockPos getOrigin() { + return (BlockPos)this.dataManager.get(ORIGIN); + } + + static { + ORIGIN = EntityDataManager.createKey(EntityFallingBlock.class, DataSerializers.BLOCK_POS); + } +} \ No newline at end of file diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/RealisticExplosionPhysics.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/RealisticExplosionPhysics.java new file mode 100644 index 0000000..c0cd27f --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/RealisticExplosionPhysics.java @@ -0,0 +1,54 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0; + +import net.minecraft.world.World; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics.IExplosionHandler; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics.PhysicsHandler; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics.RBPExplosionHandler; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics.VanillaExplosionHandler; + +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; + +public final class RealisticExplosionPhysics +{ + public static IExplosionHandler handler; + public static final List physicsHandlers = new ArrayList(); + + public static void postInit(FMLPostInitializationEvent event) { + boolean rbpActive = false; + Iterator var2 = Loader.instance().getActiveModList().iterator(); + + while(var2.hasNext()) { + ModContainer mod = (ModContainer)var2.next(); + if (mod.getModId().equals("rbp") && mod.getName().equals("Realistic Block Physics")) { + rbpActive = true; + } + } + + if (rbpActive) { + handler = new RBPExplosionHandler(); + } else { + handler = new VanillaExplosionHandler(); + } + + } + + public static void onServerShutdown(FMLServerStoppingEvent event) { + physicsHandlers.clear(); + } + + public static final PhysicsHandler getPhysicsHandler(World worldIn) { + for(int i = 0; i < physicsHandlers.size(); ++i) { + if (((PhysicsHandler)physicsHandlers.get(i)).getWorld().equals(worldIn)) { + return (PhysicsHandler)physicsHandlers.get(i); + } + } + + return null; + } +} \ No newline at end of file diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/event/OnEventWorld.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/event/OnEventWorld.java new file mode 100644 index 0000000..9ca8cec --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/event/OnEventWorld.java @@ -0,0 +1,33 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.event; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent.Load; +import net.minecraftforge.event.world.WorldEvent.Unload; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics.PhysicsHandler; + +import static org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.RealisticExplosionPhysics.*; + +public class OnEventWorld +{ + @SubscribeEvent + public static final void onWorldLoaded(Load event) { + if (!event.getWorld().isRemote) { + PhysicsHandler physicsHandler = new PhysicsHandler(event.getWorld(), handler); + MinecraftForge.EVENT_BUS.register(physicsHandler); + physicsHandlers.add(physicsHandler); + } + } + + @SubscribeEvent + public static final void onWorldUnloaded(Unload event) { + if (!event.getWorld().isRemote) { + PhysicsHandler physicsHandler = getPhysicsHandler(event.getWorld()); + if (physicsHandler != null) { + physicsHandlers.remove(physicsHandler); + MinecraftForge.EVENT_BUS.unregister(physicsHandler); + } + + } + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/IExplosionHandler.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/IExplosionHandler.java new file mode 100644 index 0000000..950417a --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/IExplosionHandler.java @@ -0,0 +1,7 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics; + +import net.minecraft.util.math.BlockPos; + +public interface IExplosionHandler { + void handleBlock(PhysicsHandler var1, BlockPos var2, double var3, double var5, double var7); +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/PhysicsHandler.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/PhysicsHandler.java new file mode 100644 index 0000000..0b7348f --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/PhysicsHandler.java @@ -0,0 +1,57 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.block.BlockTNT; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.event.world.ExplosionEvent.Detonate; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class PhysicsHandler { + private final World world; + private final IExplosionHandler explosionHandler; + + public PhysicsHandler(World world, IExplosionHandler explosionHandler) { + this.world = world; + this.explosionHandler = explosionHandler; + } + + @SubscribeEvent + public final void onExplosion(Detonate event) { + if (!event.getWorld().isRemote && event.getWorld().equals(this.world)) { + List affectedBlocks = event.getAffectedBlocks(); + List movedBlocks = new ArrayList(); + + BlockPos pos; + for(int i = 0; i < affectedBlocks.size(); ++i) { + pos = (BlockPos)affectedBlocks.get(i); + boolean aboveExplosion = (double)pos.getY() >= event.getExplosion().getPosition().y; + boolean isTNT = this.world.getBlockState(pos).getBlock() instanceof BlockTNT; + boolean hasTileEntity = this.world.getTileEntity(pos) != null; + if (aboveExplosion && !isTNT && !hasTileEntity) { + double distanceX = (double)pos.getX() - event.getExplosion().getPosition().x; + double distanceZ = (double)pos.getZ() - event.getExplosion().getPosition().z; + double motionX = distanceX / Math.abs(distanceX) * 0.5D; + double motionY = 0.5D; + double motionZ = distanceZ / Math.abs(distanceZ) * 0.5D; + this.explosionHandler.handleBlock(this, pos, motionX, 0.5D, motionZ); + movedBlocks.add(pos); + } + } + + Iterator var19 = movedBlocks.iterator(); + + while(var19.hasNext()) { + pos = (BlockPos)var19.next(); + affectedBlocks.remove(pos); + } + + } + } + + public final World getWorld() { + return this.world; + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/RBPExplosionHandler.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/RBPExplosionHandler.java new file mode 100644 index 0000000..f67809e --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/RBPExplosionHandler.java @@ -0,0 +1,9 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics; + +import net.minecraft.util.math.BlockPos; + +public class RBPExplosionHandler implements IExplosionHandler { + public void handleBlock(PhysicsHandler handler, BlockPos pos, double motionX, double motionY, double motionZ) { + RealisticBlockPhysics.summonFallingBlock(handler.getWorld(), pos, handler.getWorld().getBlockState(pos), motionX, motionY, motionZ); + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/VanillaExplosionHandler.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/VanillaExplosionHandler.java new file mode 100644 index 0000000..0b7e254 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/plugin/realisticexplosionphysics_1_12_2_1_0_0/physics/VanillaExplosionHandler.java @@ -0,0 +1,14 @@ +package org.imesense.dynamicspawncontrol.plugin.realisticexplosionphysics_1_12_2_1_0_0.physics; + +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.util.math.BlockPos; + +public class VanillaExplosionHandler implements IExplosionHandler { + public void handleBlock(PhysicsHandler handler, BlockPos pos, double motionX, double motionY, double motionZ) { + EntityFallingBlock entity = new EntityFallingBlock(handler.getWorld(), (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), handler.getWorld().getBlockState(pos)); + entity.motionX = motionX; + entity.motionY = motionY; + entity.motionZ = motionZ; + handler.getWorld().spawnEntity(entity); + } +}