Fixed some demolition stuff.
This commit is contained in:
parent
5b49c4adc3
commit
9144ab7b3f
|
@ -1,5 +1,7 @@
|
||||||
package nautilus.game.arcade.game.games.speedbuilder.data;
|
package nautilus.game.arcade.game.games.speedbuilder.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mineplex.core.common.util.MapUtil;
|
import mineplex.core.common.util.MapUtil;
|
||||||
import mineplex.core.common.util.UtilBlock;
|
import mineplex.core.common.util.UtilBlock;
|
||||||
import mineplex.core.hologram.Hologram;
|
import mineplex.core.hologram.Hologram;
|
||||||
|
@ -18,16 +20,16 @@ public class DemolitionData
|
||||||
|
|
||||||
public RecreationData Parent;
|
public RecreationData Parent;
|
||||||
|
|
||||||
public Block Block;
|
public ArrayList<Block> Blocks;
|
||||||
public Long Start;
|
public Long Start;
|
||||||
|
|
||||||
private Hologram _hologram;
|
private Hologram _hologram;
|
||||||
|
|
||||||
public DemolitionData(RecreationData parent, Block block)
|
public DemolitionData(RecreationData parent, ArrayList<Block> blocks)
|
||||||
{
|
{
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
|
|
||||||
Block = block;
|
Blocks = blocks;
|
||||||
Start = System.currentTimeMillis();
|
Start = System.currentTimeMillis();
|
||||||
|
|
||||||
spawnHologram();
|
spawnHologram();
|
||||||
|
@ -35,7 +37,7 @@ public class DemolitionData
|
||||||
|
|
||||||
public void spawnHologram()
|
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();
|
_hologram.start();
|
||||||
}
|
}
|
||||||
|
@ -57,7 +59,7 @@ public class DemolitionData
|
||||||
_hologram.setText("" + secondsLeft);
|
_hologram.setText("" + secondsLeft);
|
||||||
|
|
||||||
if (secondsLeft == 0)
|
if (secondsLeft == 0)
|
||||||
breakBlock();
|
breakBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelBreak()
|
public void cancelBreak()
|
||||||
|
@ -67,47 +69,57 @@ public class DemolitionData
|
||||||
Parent.BlocksForDemolition.remove(this);
|
Parent.BlocksForDemolition.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void breakBlock()
|
public void breakBlocks()
|
||||||
{
|
{
|
||||||
despawnHologram();
|
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());
|
||||||
|
|
||||||
Parent.DroppedItems.add(item);
|
|
||||||
|
|
||||||
//Destroy the other part
|
|
||||||
if (Block.getType() == Material.BED_BLOCK)
|
|
||||||
{
|
|
||||||
Bed bed = (Bed) Block.getState().getData();
|
|
||||||
|
|
||||||
if (bed.isHeadOfBed())
|
|
||||||
MapUtil.QuickChangeBlockAt(Block.getRelative(bed.getFacing().getOppositeFace()).getLocation(), Material.AIR);
|
|
||||||
else
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
Door door = (Door) Block.getState().getData();
|
|
||||||
|
|
||||||
if (door.isTopHalf())
|
|
||||||
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
|
|
||||||
else
|
|
||||||
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
|
|
||||||
}
|
|
||||||
else if (Block.getType() == Material.DOUBLE_PLANT)
|
|
||||||
{
|
|
||||||
if (Block.getData() > 7)
|
|
||||||
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
|
|
||||||
else
|
|
||||||
MapUtil.QuickChangeBlockAt(Block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.getWorld().playEffect(Block.getLocation(), Effect.STEP_SOUND, Block.getTypeId());
|
for (Block block : Blocks)
|
||||||
|
{
|
||||||
MapUtil.QuickChangeBlockAt(Block.getLocation(), Material.AIR);
|
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)
|
||||||
|
{
|
||||||
|
Bed bed = (Bed) block.getState().getData();
|
||||||
|
|
||||||
|
if (bed.isHeadOfBed())
|
||||||
|
MapUtil.QuickChangeBlockAt(block.getRelative(bed.getFacing().getOppositeFace()).getLocation(), Material.AIR);
|
||||||
|
else
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Door door = (Door) block.getState().getData();
|
||||||
|
|
||||||
|
if (door.isTopHalf())
|
||||||
|
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.DOWN).getLocation(), Material.AIR);
|
||||||
|
else
|
||||||
|
MapUtil.QuickChangeBlockAt(block.getRelative(BlockFace.UP).getLocation(), Material.AIR);
|
||||||
|
}
|
||||||
|
else if (block.getType() == Material.DOUBLE_PLANT)
|
||||||
|
{
|
||||||
|
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.getLocation(), Material.AIR);
|
||||||
|
}
|
||||||
|
|
||||||
Parent.BlocksForDemolition.remove(this);
|
Parent.BlocksForDemolition.remove(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,11 +242,41 @@ public class RecreationData
|
||||||
{
|
{
|
||||||
for (DemolitionData demolition : BlocksForDemolition)
|
for (DemolitionData demolition : BlocksForDemolition)
|
||||||
{
|
{
|
||||||
if (demolition.Block.equals(block))
|
if (demolition.Blocks.contains(block))
|
||||||
return;
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue