use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class Blast method prePlace.
/**
* Called before block placement to check that
* the placement is not canceled by an event
*
* @param vec - edit data, null and has changed checked
* @return true if should continue
*/
protected boolean prePlace(final IWorldEdit vec) {
BlastEventBlockEdit event;
if (vec.getNewBlock() == Blocks.air) {
event = new BlastEventBlockRemoved.Pre(this, world, vec.getBlock(), vec.getBlockMetadata(), (int) vec.x(), (int) vec.y(), (int) vec.z());
} else {
event = new BlastEventBlockReplaced.Pre(this, world, vec.getBlock(), vec.getBlockMetadata(), vec.getNewBlock(), vec.getNewMeta(), (int) vec.x(), (int) vec.y(), (int) vec.z());
}
boolean result = MinecraftForge.EVENT_BUS.post(event);
if (vec instanceof BlockEdit && event instanceof BlastEventBlockReplaced.Pre) {
((BlockEdit) vec).set(((BlastEventBlockReplaced.Pre) event).newBlock, ((BlastEventBlockReplaced.Pre) event).newMeta);
}
return !result;
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class BlastBasic method prePlace.
@Override
protected boolean prePlace(final IWorldEdit vec) {
BlastEventBlockEdit event = new BlastEventDestroyBlock.Pre(this, BlastEventDestroyBlock.DestructionType.FORCE, world, vec.getBlock(), vec.getBlockMetadata(), (int) vec.x(), (int) vec.y(), (int) vec.z());
boolean result = MinecraftForge.EVENT_BUS.post(event);
if (vec instanceof BlockEdit && event instanceof BlastEventBlockReplaced.Pre) {
((BlockEdit) vec).set(((BlastEventBlockReplaced.Pre) event).newBlock, ((BlastEventBlockReplaced.Pre) event).newMeta);
}
return !result;
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class TestBlockEdit method testMap.
public void testMap() {
HashMap<BlockEdit, Object> map = new HashMap();
map.put(new BlockEdit(null, 0, 0, 0), "yo");
// Test basic contains
Assert.assertTrue("Should contain location", map.containsKey(new BlockEdit(null, 0, 0, 0)));
Assert.assertTrue("Should not contain location", !map.containsKey(new BlockEdit(null, 0, 1, 0)));
// Test removes
map.remove(new BlockEdit(null, 0, 0, 0));
Assert.assertTrue("Should not contain location", !map.containsKey(new BlockEdit(null, 0, 0, 0)));
// Repeat with world not null
World world = FakeWorld.newWorld("BlockEditTest");
World world2 = FakeWorld.newWorld("BlockEditTest");
map.put(new BlockEdit(world, 0, 0, 0), "mama");
// Test basic contains
Assert.assertTrue("Should contain location", map.containsKey(new BlockEdit(world, 0, 0, 0)));
Assert.assertTrue("Should not contain location", !map.containsKey(new BlockEdit(world2, 0, 0, 0)));
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class TestBlockEdit method testHashCode.
@Test
public void testHashCode() {
World world = FakeWorld.newWorld("BlockEditTest");
World world2 = FakeWorld.newWorld("BlockEditTest2");
BlockEdit location = new BlockEdit(world, 0, 0, 0);
BlockEdit location2 = new BlockEdit(world, 0, 0, 0);
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
location2 = new BlockEdit(world2, 0, 0, 0);
// Test world not equal
Assert.assertNotSame("BlockEdit one & two should not equal each other", location.hashCode(), location2.hashCode());
location = new BlockEdit(world, 0, 1, 0);
// Test pos not equal
Assert.assertNotSame("BlockEdit one & two should not equal each other", location.hashCode(), location2.hashCode());
// Test decimal point
for (Pos pos : new Pos[] { new Pos(1, 2.0, 3.0f), new Pos(1, 2.2, 3.1f), new Pos(1.5125412, 2.2223, 3.0f), new Pos(1.231, 2.45454, 3.23213f) }) {
location = new BlockEdit(world, pos.x(), pos.y(), pos.z());
location2 = new BlockEdit(world, pos.x(), pos.y(), pos.z());
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
}
location = new BlockEdit(world, 1, 2, 3);
location2 = new BlockEdit(world, 1.3, 2.2, 3.4);
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
}
use of com.builtbroken.mc.lib.world.edit.BlockEdit in project Engine by VoltzEngine-Project.
the class TestBlockEdit method testEquals.
@Test
public void testEquals() {
World world = FakeWorld.newWorld("BlockEditTest");
World world2 = FakeWorld.newWorld("BlockEditTest2");
BlockEdit location = new BlockEdit(world, 0, 0, 0);
BlockEdit location2 = new BlockEdit(world, 0, 0, 0);
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location, location);
Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
location2 = new BlockEdit(world2, 0, 0, 0);
// Test world not equal
Assert.assertNotSame("BlockEdit one & two should not equal each other", location, location2);
location = new BlockEdit(world, 0, 1, 0);
// Test pos not equal
Assert.assertNotSame("BlockEdit one & two should not equal each other", location, location2);
// Test decimal point
for (Pos pos : new Pos[] { new Pos(1, 2.0, 3.0f), new Pos(1, 2.2, 3.1f), new Pos(1.5125412, 2.2223, 3.0f), new Pos(1.231, 2.45454, 3.23213f) }) {
location = new BlockEdit(world, pos.x(), pos.y(), pos.z());
location2 = new BlockEdit(world, pos.x(), pos.y(), pos.z());
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location, location);
Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
}
location = new BlockEdit(world, 1, 2, 3);
location2 = new BlockEdit(world, 1.3, 2.2, 3.4);
// Test would equals
Assert.assertEquals("BlockEdit one should equal itself", location, location);
Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
}
Aggregations