use of com.builtbroken.mc.api.IWorldPosition in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method destroyMultiBlockStructure.
/**
* Breaks down the multiblock stucture linked to the host
*
* @param host - host providing the layour of the structure
* @param doDrops - attempt to drop blocks?
* @param offset - offset the layout by the location of the host?
* @param killHost - destroy the host block as well?
*/
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
if (host != null) {
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
IWorldPosition center;
if (host instanceof TileEntity) {
center = new Location((TileEntity) host);
} else if (host instanceof IWorldPosition) {
center = (IWorldPosition) host;
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
return;
}
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
if (offset) {
pos = pos.add(center);
}
TileEntity tile = pos.getTileEntity(center.world());
if (tile instanceof IMultiTile) {
((IMultiTile) tile).setHost(null);
pos.setBlockToAir(center.world());
}
}
if (doDrops) {
InventoryUtility.dropBlockAsItem(center, killHost);
} else if (killHost) {
center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
}
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
}
}
}
use of com.builtbroken.mc.api.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.
the class TileLauncherScreen method onPlayerActivated.
@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
if (isServer()) {
boolean notNull = player.getHeldItem() != null;
if (notNull && player.getHeldItem().getItem() == Items.redstone) {
if (canLaunch()) {
launch();
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%1", getStatus());
player.addChatComponentMessage(new ChatComponentText(translation));
}
} else if (notNull && player.getHeldItem().getItem() instanceof ItemRemoteDetonator) {
((ItemRemoteDetonator) player.getHeldItem().getItem()).setBroadCastHz(player.getHeldItem(), getFrequency());
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%1", "" + getFrequency())));
} else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
if (location != null) {
if (location.world() == world()) {
setTarget(new Pos(location.x(), location.y(), location.z()));
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else {
player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
return true;
}
use of com.builtbroken.mc.api.IWorldPosition in project Engine by VoltzEngine-Project.
the class TestAbstractLocation method testInit.
/**
* Tests constructors
*/
public void testInit() {
List<TLocation> locations = new ArrayList();
// Test main method
locations.add(new TLocation(world, 10, 11, 12));
// Test entity method
Entity entity = new EntitySheep(world);
entity.setPosition(10, 11, 12);
locations.add(new TLocation(entity));
// Test tile
TileEntity tile = new TileEntity();
tile.setWorldObj(world);
tile.xCoord = 10;
tile.yCoord = 11;
tile.zCoord = 12;
locations.add(new TLocation(tile));
// Test NBT method
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("dimension", world.provider.dimensionId);
tag.setDouble("x", 10);
tag.setDouble("y", 11);
tag.setDouble("z", 12);
locations.add(new TLocation(tag));
// Test byte buf method
ByteBuf buf = Unpooled.buffer();
buf.writeInt(world.provider.dimensionId);
buf.writeDouble(10);
buf.writeDouble(11);
buf.writeDouble(12);
locations.add(new TLocation(buf));
// Test IWorldPosition
locations.add(new TLocation(new IWorldPosition() {
@Override
public World world() {
return world;
}
@Override
public double x() {
return 10;
}
@Override
public double y() {
return 11;
}
@Override
public double z() {
return 12;
}
}));
// Test world, IPos3D
locations.add(new TLocation(world, new IPos3D() {
@Override
public double x() {
return 10;
}
@Override
public double y() {
return 11;
}
@Override
public double z() {
return 12;
}
}));
// Test world, vec3
locations.add(new TLocation(world, Vec3.createVectorHelper(10, 11, 12)));
// Test world, moving object
locations.add(new TLocation(world, new MovingObjectPosition(10, 11, 12, 0, Vec3.createVectorHelper(10, 11, 12))));
for (int i = 0; i < locations.size(); i++) {
TLocation location = locations.get(i);
assertTrue("" + i, location.world == world);
assertTrue("" + i, location.xi() == 10);
assertTrue("" + i, location.yi() == 11);
assertTrue("" + i, location.zi() == 12);
}
}
use of com.builtbroken.mc.api.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.
the class TileCruiseLauncher method onPlayerActivated.
@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
if (isServer()) {
boolean notNull = player.getHeldItem() != null;
if (notNull && player.getHeldItem().getItem() == Items.redstone) {
if (canLaunch()) {
launch();
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%1", getStatus());
player.addChatComponentMessage(new ChatComponentText(translation));
}
} else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
if (location != null) {
if (location.world() == world()) {
setTarget(new Pos(location.x(), location.y(), location.z()));
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else {
player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
return true;
}
Aggregations