use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class PacketBlast method decodeInto.
@Override
@SideOnly(Side.CLIENT)
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
type = BlastPacketType.values()[buffer.readInt()];
x = buffer.readDouble();
y = buffer.readDouble();
z = buffer.readDouble();
size = buffer.readDouble();
String id = ByteBufUtils.readUTF8String(buffer);
handler = ExplosiveRegistry.get(id);
if (handler == null) {
Engine.logger().error("Failed to load handler[" + id + "] from packet data");
}
NBTTagCompound save = ByteBufUtils.readTag(buffer);
blast = (Blast) handler.createBlastForTrigger(Minecraft.getMinecraft().theWorld, x, y, z, TriggerCauseRegistry.rebuild(save.getCompoundTag("trigger"), Minecraft.getMinecraft().theWorld), size, save.getCompoundTag("explosiveData"));
if (type == BlastPacketType.EDIT_DISPLAY) {
edit = new BlockEdit(save.getCompoundTag("edit"));
}
blast.readBytes(buffer);
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class SchematicMap method getBlocksToPlace.
/**
* Gets all blocks needed to build the schematic at the given location
*
* @param spot - center point of the schematic
* @param blockMap - map of blocks from the schematic file
* @param checkWorld - check if blocks are already placed
* @param checkIfWorldIsLoaded - check if the area is loaded, make sure this is true if
* checkWorld boolean is true as it effects the results if the chunk is unloaded. Setting this
* true will not load the area and is designed to prevent wasting blocks when generating
* buildings using actual blocks
*/
public void getBlocksToPlace(Location spot, List<IWorldEdit> blockMap, boolean checkWorld, boolean checkIfWorldIsLoaded) {
if (this.block_map != null) {
for (Entry<Pos, Pair<Block, Integer>> entry : this.block_map.entrySet()) {
Block block = entry.getValue().left();
int meta = entry.getValue().right();
if (block == null || block != Blocks.sponge) {
if (meta > 15) {
meta = 15;
} else if (meta < 0) {
meta = 0;
}
Pos setPos = spot.toPos().subtract(this.schematicCenter).add(entry.getKey());
if (checkWorld) {
if (checkIfWorldIsLoaded) {
Chunk chunk = spot.world.getChunkFromBlockCoords(setPos.xi(), setPos.zi());
if (!chunk.isChunkLoaded) {
continue;
}
}
Block checkID = setPos.getBlock(spot.world);
int checkMeta = setPos.getBlockMetadata(spot.world);
if (checkID == block && checkMeta == meta) {
continue;
}
}
blockMap.add(new BlockEdit(spot.world, setPos).set(block, meta));
}
}
}
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class BlastBasic method expand.
/**
* Called to map another iteration to expand outwards from the center of the explosion
*
* @param map - hash map to store data for block placement to energy used
* @param vec - next block to expand from, and to log to map
* @param energy - current energy at block
* @param side - side not to expand in, and direction we came from
* @param iteration - current iteration count from center, use this to stop the iteration if they get too far from center
*/
protected void expand(HashMap<BlockEdit, Float> map, BlockEdit vec, float energy, EnumFacing side, int iteration) {
long timeStart = System.nanoTime();
if (iteration < size * 2) {
float e = getEnergyCostOfTile(vec, energy);
profile.tilesPathed++;
if (e >= 0) {
// Add block to effect list
vec.energy = energy;
onBlockMapped(vec, e, energy - e);
map.put(vec, energy - e);
// Only iterate threw sides if we have more energy
if (e > 1) {
// Get valid sides to iterate threw
List<BlockEdit> sides = new ArrayList();
for (EnumFacing dir : EnumFacing.values()) {
if (dir != side) {
BlockEdit v = new BlockEdit(world, vec.x(), vec.y(), vec.z());
v.doDrops();
v = v.add(dir);
v.face = dir;
v.logPrevBlock();
sides.add(v);
}
}
Collections.sort(sides, new Vector3DistanceComparator(new Pos(x(), y(), z())));
profile.blockIterationTimes.add(System.nanoTime() - timeStart);
// Iterate threw sides expending energy outwards
for (BlockEdit f : sides) {
float eToSpend = (e / sides.size()) + (e % sides.size());
e -= eToSpend;
EnumFacing face = side == null ? getOpposite(f.face) : side;
if (!map.containsKey(f) || map.get(f) < eToSpend) {
f.face = face;
expand(map, f, eToSpend, face, iteration + 1);
}
}
}
}
}
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class TestBlockEdit method testList.
@Test
public void testList() {
List<BlockEdit> list = new ArrayList();
list.add(new BlockEdit(null, 0, 0, 0));
// Test basic contains
Assert.assertTrue("Should contain location", list.contains(new BlockEdit(null, 0, 0, 0)));
Assert.assertTrue("Should not contain location", !list.contains(new BlockEdit(null, 0, 1, 0)));
// Test removes
list.remove(new BlockEdit(null, 0, 0, 0));
Assert.assertTrue("Should not contain location", !list.contains(new BlockEdit(null, 0, 0, 0)));
// Repeat with world not null
World world = FakeWorld.newWorld("BlockEditTest");
World world2 = FakeWorld.newWorld("BlockEditTest");
list.add(new BlockEdit(world, 0, 0, 0));
// Test basic contains
Assert.assertTrue("Should contain location", list.contains(new BlockEdit(world, 0, 0, 0)));
Assert.assertTrue("Should not contain location", !list.contains(new BlockEdit(world2, 0, 0, 0)));
list.add(new BlockEdit(world, 0, 1.00, 0));
// Test basic contains
Assert.assertTrue("Should contain location", list.contains(new BlockEdit(world, 0, 1.00, 0)));
Assert.assertTrue("Should not contain location", !list.contains(new BlockEdit(world2, 0, 1.00, 0)));
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class BlastBasic method getEffectedBlocks.
@Override
public void getEffectedBlocks(List<IWorldEdit> list) {
// TODO disable profiler if not in debug mode
HashMap<BlockEdit, Float> map = new HashMap();
profile.startSection("getEffectedBlocks");
// Start path finder
profile.startSection("Pathfinder");
list.add(new BlockEdit(this, Blocks.air, 0));
triggerPathFinder(map, new BlockEdit(this.world, this.x, this.y, this.z), energy);
profile.endSection("Pathfinder");
// Add map keys to block list
list.addAll(map.keySet());
// Sort results so blocks are placed in the center first
profile.startSection("Sorter");
Collections.sort(list, new Vector3DistanceComparator(new Pos(x(), y(), z())));
profile.endSection("Sorter");
profile.endSection("getEffectedBlocks");
// Generate debug info
if (Engine.runningAsDev) {
Engine.instance.logger().info(profile.getOutputSimple());
}
}
Aggregations