Fixed some demolition stuff.

This commit is contained in:
Virizion 2015-12-05 20:30:21 -05:00
parent 5b49c4adc3
commit 9144ab7b3f
2 changed files with 84 additions and 42 deletions

View File

@ -1,5 +1,7 @@
package nautilus.game.arcade.game.games.speedbuilder.data;
import java.util.ArrayList;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.hologram.Hologram;
@ -18,16 +20,16 @@ public class DemolitionData
public RecreationData Parent;
public Block Block;
public ArrayList<Block> Blocks;
public Long Start;
private Hologram _hologram;
public DemolitionData(RecreationData parent, Block block)
public DemolitionData(RecreationData parent, ArrayList<Block> blocks)
{
Parent = parent;
Block = block;
Blocks = blocks;
Start = System.currentTimeMillis();
spawnHologram();
@ -35,7 +37,7 @@ public class DemolitionData
public void spawnHologram()
{
_hologram = new Hologram(Parent.Game.Manager.getHologramManager(), Block.getLocation().add(0.5, 0.5, 0.5), "3");
_hologram = new Hologram(Parent.Game.Manager.getHologramManager(), Blocks.get(0).getLocation().add(0.5, 0.5, 0.5), "3");
_hologram.start();
}
@ -57,7 +59,7 @@ public class DemolitionData
_hologram.setText("" + secondsLeft);
if (secondsLeft == 0)
breakBlock();
breakBlocks();
}
public void cancelBreak()
@ -67,47 +69,57 @@ public class DemolitionData
Parent.BlocksForDemolition.remove(this);
}
public void breakBlock()
public void breakBlocks()
{
despawnHologram();
for (ItemStack itemStack : UtilBlock.blockToInventoryItemStacks(Block))
//Effect will play for all blocks even two-parted ones
for (Block block : Blocks)
{
Item item = Block.getWorld().dropItem(Block.getLocation().add(0.5, 0.5, 0.5), itemStack);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
for (Block block : Blocks)
{
if (block.getType() == Material.AIR)
continue;
for (ItemStack itemStack : UtilBlock.blockToInventoryItemStacks(block))
{
Item item = block.getWorld().dropItem(block.getLocation().add(0.5, 0.5, 0.5), itemStack);
Parent.DroppedItems.add(item);
}
//Destroy the other part
if (Block.getType() == Material.BED_BLOCK)
if (block.getType() == Material.BED_BLOCK)
{
Bed bed = (Bed) Block.getState().getData();
Bed bed = (Bed) block.getState().getData();
if (bed.isHeadOfBed())
MapUtil.QuickChangeBlockAt(Block.getRelative(bed.getFacing().getOppositeFace()).getLocation(), Material.AIR);
MapUtil.QuickChangeBlockAt(block.getRelative(bed.getFacing().getOppositeFace()).getLocation(), Material.AIR);
else
MapUtil.QuickChangeBlockAt(Block.getRelative(bed.getFacing()).getLocation(), Material.AIR);
MapUtil.QuickChangeBlockAt(block.getRelative(bed.getFacing()).getLocation(), Material.AIR);
}
else if (Block.getType() == Material.WOODEN_DOOR || Block.getType() == Material.IRON_DOOR_BLOCK || Block.getType() == Material.SPRUCE_DOOR || Block.getType() == Material.BIRCH_DOOR || Block.getType() == Material.JUNGLE_DOOR || Block.getType() == Material.ACACIA_DOOR || Block.getType() == Material.DARK_OAK_DOOR)
else if (block.getType() == Material.WOODEN_DOOR || block.getType() == Material.IRON_DOOR_BLOCK || block.getType() == Material.SPRUCE_DOOR || block.getType() == Material.BIRCH_DOOR || block.getType() == Material.JUNGLE_DOOR || block.getType() == Material.ACACIA_DOOR || block.getType() == Material.DARK_OAK_DOOR)
{
Door door = (Door) Block.getState().getData();
Door door = (Door) block.getState().getData();
if (door.isTopHalf())
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
else
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
}
else if (Block.getType() == Material.DOUBLE_PLANT)
else if (block.getType() == Material.DOUBLE_PLANT)
{
if (Block.getData() > 7)
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
if (block.getData() > 7)
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
else
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
}
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
}
Block.getWorld().playEffect(Block.getLocation(), Effect.STEP_SOUND, Block.getTypeId());
MapUtil.QuickChangeBlockAt(Block.getLocation(), Material.AIR);
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
}
Parent.BlocksForDemolition.remove(this);
}

View File

@ -242,11 +242,41 @@ public class RecreationData
{
for (DemolitionData demolition : BlocksForDemolition)
{
if (demolition.Block.equals(block))
if (demolition.Blocks.contains(block))
return;
}
BlocksForDemolition.add(new DemolitionData(this, block));
ArrayList<Block> blocks = new ArrayList<Block>();
blocks.add(block);
//Add the other part of the block
if (block.getType() == Material.BED_BLOCK)
{
Bed bed = (Bed) block.getState().getData();
if (bed.isHeadOfBed())
blocks.add(block.getRelative(bed.getFacing().getOppositeFace()));
else
blocks.add(block.getRelative(bed.getFacing()));
}
else if (block.getType() == Material.WOODEN_DOOR || block.getType() == Material.IRON_DOOR_BLOCK || block.getType() == Material.SPRUCE_DOOR || block.getType() == Material.BIRCH_DOOR || block.getType() == Material.JUNGLE_DOOR || block.getType() == Material.ACACIA_DOOR || block.getType() == Material.DARK_OAK_DOOR)
{
Door door = (Door) block.getState().getData();
if (door.isTopHalf())
blocks.add(block.getRelative(BlockFace.DOWN));
else
blocks.add(block.getRelative(BlockFace.UP));
}
else if (block.getType() == Material.DOUBLE_PLANT)
{
if (block.getData() > 7)
blocks.add(block.getRelative(BlockFace.DOWN));
else
blocks.add(block.getRelative(BlockFace.UP));
}
BlocksForDemolition.add(new DemolitionData(this, blocks));
}
}