diff --git a/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java b/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java index a4edab55..84019156 100644 --- a/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java +++ b/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java @@ -18,6 +18,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import wayoftime.bloodmagic.tile.TileExplosiveCharge; import wayoftime.bloodmagic.tile.TileShapedExplosive; public class BlockShapedExplosive extends Block @@ -110,7 +111,7 @@ public class BlockShapedExplosive extends Block @Override public void onBlockHarvested(World world, BlockPos blockPos, BlockState blockState, PlayerEntity player) { - TileShapedExplosive tile = (TileShapedExplosive) world.getTileEntity(blockPos); + TileExplosiveCharge tile = (TileExplosiveCharge) world.getTileEntity(blockPos); if (tile != null && !world.isRemote) tile.dropSelf(); diff --git a/src/main/java/wayoftime/bloodmagic/common/item/block/ItemBlockShapedCharge.java b/src/main/java/wayoftime/bloodmagic/common/item/block/ItemBlockShapedCharge.java index c2f4aaaa..1069a834 100644 --- a/src/main/java/wayoftime/bloodmagic/common/item/block/ItemBlockShapedCharge.java +++ b/src/main/java/wayoftime/bloodmagic/common/item/block/ItemBlockShapedCharge.java @@ -14,7 +14,7 @@ import net.minecraft.util.SoundEvents; import net.minecraft.world.World; import wayoftime.bloodmagic.anointment.AnointmentHolder; import wayoftime.bloodmagic.entity.projectile.EntityShapedCharge; -import wayoftime.bloodmagic.tile.TileShapedExplosive; +import wayoftime.bloodmagic.tile.TileExplosiveCharge; public class ItemBlockShapedCharge extends BlockItem { @@ -60,9 +60,9 @@ public class ItemBlockShapedCharge extends BlockItem if (holder != null) { TileEntity tile = context.getWorld().getTileEntity(context.getPos()); - if (tile instanceof TileShapedExplosive) + if (tile instanceof TileExplosiveCharge) { - ((TileShapedExplosive) tile).setAnointmentHolder(holder); + ((TileExplosiveCharge) tile).setAnointmentHolder(holder); } } diff --git a/src/main/java/wayoftime/bloodmagic/entity/projectile/EntityShapedCharge.java b/src/main/java/wayoftime/bloodmagic/entity/projectile/EntityShapedCharge.java index 5c6c8455..83af441d 100644 --- a/src/main/java/wayoftime/bloodmagic/entity/projectile/EntityShapedCharge.java +++ b/src/main/java/wayoftime/bloodmagic/entity/projectile/EntityShapedCharge.java @@ -24,7 +24,7 @@ import wayoftime.bloodmagic.anointment.AnointmentHolder; import wayoftime.bloodmagic.common.block.BlockShapedExplosive; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; import wayoftime.bloodmagic.common.registries.BloodMagicEntityTypes; -import wayoftime.bloodmagic.tile.TileShapedExplosive; +import wayoftime.bloodmagic.tile.TileExplosiveCharge; public class EntityShapedCharge extends ThrowableEntity { @@ -75,9 +75,9 @@ public class EntityShapedCharge extends ThrowableEntity { this.getEntityWorld().setBlockState(blockpos, fallTile.with(BlockShapedExplosive.ATTACHED, faceHit)); TileEntity tile = this.getEntityWorld().getTileEntity(blockpos); - if (tile instanceof TileShapedExplosive) + if (tile instanceof TileExplosiveCharge) { - ((TileShapedExplosive) tile).setAnointmentHolder(holder); + ((TileExplosiveCharge) tile).setAnointmentHolder(holder); } this.setDead(); } else diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java b/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java index 1838a831..7fb18391 100644 --- a/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java +++ b/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java @@ -11,7 +11,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.loot.LootContext; @@ -30,7 +29,7 @@ import net.minecraft.world.server.ServerWorld; import net.minecraftforge.registries.ObjectHolder; import wayoftime.bloodmagic.common.block.BlockShapedExplosive; -public class TileDeforesterCharge extends TileShapedExplosive +public class TileDeforesterCharge extends TileExplosiveCharge { @ObjectHolder("bloodmagic:deforester_charge") public static TileEntityType TYPE; @@ -50,16 +49,16 @@ public class TileDeforesterCharge extends TileShapedExplosive public int maxLogs = 128; - public TileDeforesterCharge(TileEntityType type, int explosionRadius, int explosionDepth) + public TileDeforesterCharge(TileEntityType type, int maxLogs) { - super(type, explosionRadius, explosionDepth); -// this.explosionRadius = explosionRadius; -// this.explosionDepth = explosionDepth; + super(type); + + this.maxLogs = maxLogs; } public TileDeforesterCharge() { - this(TYPE, 1, 3); + this(TYPE, 128); } @Override @@ -174,7 +173,7 @@ public class TileDeforesterCharge extends TileShapedExplosive ItemStack toolStack = this.getHarvestingTool(); world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F); - int numParticles = explosionDepth * (explosionRadius + 1); + int numParticles = 10; ((ServerWorld) this.world).spawnParticle(ParticleTypes.EXPLOSION, pos.getX() + 0.5 + explosiveDirection.getXOffset(), pos.getY() + 0.5 + explosiveDirection.getYOffset(), pos.getZ() + 0.5 + explosiveDirection.getZOffset(), numParticles, 1.0D, 1.0D, 1.0D, 0); @@ -219,28 +218,6 @@ public class TileDeforesterCharge extends TileShapedExplosive } } - private static void handleExplosionDrops(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos) - { - int i = dropPositionArray.size(); - - for (int j = 0; j < i; ++j) - { - Pair pair = dropPositionArray.get(j); - ItemStack itemstack = pair.getFirst(); - if (ItemEntity.canMergeStacks(itemstack, stack)) - { - ItemStack itemstack1 = ItemEntity.mergeStacks(itemstack, stack, 16); - dropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond())); - if (stack.isEmpty()) - { - return; - } - } - } - - dropPositionArray.add(Pair.of(stack, pos)); - } - @Override public void deserialize(CompoundNBT tag) { diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileExplosiveCharge.java b/src/main/java/wayoftime/bloodmagic/tile/TileExplosiveCharge.java new file mode 100644 index 00000000..19136d3c --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/tile/TileExplosiveCharge.java @@ -0,0 +1,98 @@ +package wayoftime.bloodmagic.tile; + +import com.mojang.datafixers.util.Pair; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.inventory.InventoryHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.math.BlockPos; +import wayoftime.bloodmagic.anointment.AnointmentHolder; +import wayoftime.bloodmagic.tile.base.TileTicking; + +public class TileExplosiveCharge extends TileTicking +{ + + public AnointmentHolder anointmentHolder = new AnointmentHolder(); + + public TileExplosiveCharge(TileEntityType type) + { + super(type); + } + + protected static void handleExplosionDrops(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos) + { + int i = dropPositionArray.size(); + + for (int j = 0; j < i; ++j) + { + Pair pair = dropPositionArray.get(j); + ItemStack itemstack = pair.getFirst(); + if (ItemEntity.canMergeStacks(itemstack, stack)) + { + ItemStack itemstack1 = ItemEntity.mergeStacks(itemstack, stack, 16); + dropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond())); + if (stack.isEmpty()) + { + return; + } + } + } + + dropPositionArray.add(Pair.of(stack, pos)); + } + + public ItemStack getHarvestingTool() + { + ItemStack stack = new ItemStack(Items.DIAMOND_PICKAXE); + if (anointmentHolder != null) + anointmentHolder.toItemStack(stack); + return stack; + } + + @Override + public void deserialize(CompoundNBT tag) + { + if (tag.contains("holder")) + { + anointmentHolder = AnointmentHolder.fromNBT(tag.getCompound("holder")); + } + + } + + @Override + public CompoundNBT serialize(CompoundNBT tag) + { + if (anointmentHolder != null) + { + tag.put("holder", anointmentHolder.serialize()); + } + + return tag; + } + + public void setAnointmentHolder(AnointmentHolder holder) + { + this.anointmentHolder = holder; + } + + public void dropSelf() + { + ItemStack stack = new ItemStack(getBlockState().getBlock()); + if (anointmentHolder != null && !anointmentHolder.isEmpty()) + { + anointmentHolder.toItemStack(stack); + } + + InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack); + } + + @Override + public void onUpdate() + { + + } +} \ No newline at end of file diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java b/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java index fe751246..cefdf33f 100644 --- a/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java +++ b/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java @@ -6,11 +6,8 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.loot.LootContext; import net.minecraft.loot.LootParameters; import net.minecraft.nbt.CompoundNBT; @@ -24,21 +21,17 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.registries.ObjectHolder; -import wayoftime.bloodmagic.anointment.AnointmentHolder; import wayoftime.bloodmagic.common.block.BlockShapedExplosive; -import wayoftime.bloodmagic.tile.base.TileTicking; -public class TileShapedExplosive extends TileTicking +public class TileShapedExplosive extends TileExplosiveCharge { @ObjectHolder("bloodmagic:shaped_explosive") - public static TileEntityType TYPE; + public static TileEntityType TYPE; public double internalCounter = 0; public int explosionRadius; public int explosionDepth; - public AnointmentHolder anointmentHolder = new AnointmentHolder(); - public TileShapedExplosive(TileEntityType type, int explosionRadius, int explosionDepth) { super(type); @@ -165,72 +158,19 @@ public class TileShapedExplosive extends TileTicking } } - private static void handleExplosionDrops(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos) - { - int i = dropPositionArray.size(); - - for (int j = 0; j < i; ++j) - { - Pair pair = dropPositionArray.get(j); - ItemStack itemstack = pair.getFirst(); - if (ItemEntity.canMergeStacks(itemstack, stack)) - { - ItemStack itemstack1 = ItemEntity.mergeStacks(itemstack, stack, 16); - dropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond())); - if (stack.isEmpty()) - { - return; - } - } - } - - dropPositionArray.add(Pair.of(stack, pos)); - } - - public ItemStack getHarvestingTool() - { - ItemStack stack = new ItemStack(Items.DIAMOND_PICKAXE); - if (anointmentHolder != null) - anointmentHolder.toItemStack(stack); - return stack; - } - @Override public void deserialize(CompoundNBT tag) { + super.deserialize(tag); internalCounter = tag.getDouble("internalCounter"); - if (tag.contains("holder")) - { - anointmentHolder = AnointmentHolder.fromNBT(tag.getCompound("holder")); - } - } @Override public CompoundNBT serialize(CompoundNBT tag) { + super.serialize(tag); tag.putDouble("internalCounter", internalCounter); - if (anointmentHolder != null) - { - tag.put("holder", anointmentHolder.serialize()); - } return tag; } - - public void setAnointmentHolder(AnointmentHolder holder) - { - this.anointmentHolder = holder; - } - - public void dropSelf() - { - ItemStack stack = new ItemStack(getBlockState().getBlock()); - if (anointmentHolder != null && !anointmentHolder.isEmpty()) - { - anointmentHolder.toItemStack(stack); - } - - InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack); - } -} \ No newline at end of file +}