Search in sources :

Example 1 with BlockEdit

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;
}
Also used : BlastEventBlockReplaced(com.builtbroken.mc.api.event.blast.BlastEventBlockReplaced) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit) BlastEventBlockRemoved(com.builtbroken.mc.api.event.blast.BlastEventBlockRemoved)

Example 2 with BlockEdit

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;
}
Also used : BlastEventBlockReplaced(com.builtbroken.mc.api.event.blast.BlastEventBlockReplaced) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit)

Example 3 with BlockEdit

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)));
}
Also used : HashMap(java.util.HashMap) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) World(net.minecraft.world.World) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld)

Example 4 with BlockEdit

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());
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Example 5 with BlockEdit

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);
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Aggregations

BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)10 Pos (com.builtbroken.mc.lib.transform.vector.Pos)5 BlastEventBlockEdit (com.builtbroken.mc.api.event.blast.BlastEventBlockEdit)4 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)4 World (net.minecraft.world.World)4 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3 Test (org.junit.Test)3 BlastEventBlockReplaced (com.builtbroken.mc.api.event.blast.BlastEventBlockReplaced)2 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Pair (com.builtbroken.jlib.type.Pair)1 BlastEventBlockRemoved (com.builtbroken.mc.api.event.blast.BlastEventBlockRemoved)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Block (net.minecraft.block.Block)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 Chunk (net.minecraft.world.chunk.Chunk)1