use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.
the class PacketOpenGUI method handle.
@Override
public void handle(EntityPlayer player, TileEntity tile) {
if (!player.worldObj.isRemote) {
IGuiTile guiTile = null;
if (tile instanceof IGuiTile) {
guiTile = (IGuiTile) tile;
} else if (tile instanceof ITileNodeHost && ((ITileNodeHost) tile).getTileNode() instanceof IGuiTile) {
guiTile = (IGuiTile) ((ITileNodeHost) tile).getTileNode();
}
if (guiTile != null) {
ByteBuf buf = data().slice();
int guiID = buf.readInt();
if (!guiTile.openGui(player, guiID)) {
Engine.logger().error("Failed to open gui with ID(" + guiID + ") at location " + new Location(player.worldObj, x, y, z) + ", tile = " + tile);
}
} else if (Engine.runningAsDev) {
Engine.logger().error("Tile at location " + new Location(player.worldObj, x, y, z) + " is not an instance of ITileGUI, tile = " + tile);
}
} else if (Engine.runningAsDev) {
Engine.logger().error("Can not open GUI on client using PacketOpenGUI, tile = " + tile);
}
}
use of com.builtbroken.mc.imp.transform.vector.Location 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.imp.transform.vector.Location in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method updateStructure.
/**
* Runs a world update on all members of the structure
*
* @param world
* @param host
* @param offset - off set the location data by the center of the host
*/
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
//TODO junit test
if (!(host instanceof TileEntity)) {
Engine.error("Tile host is not an instance of TileEntity");
}
if (world == null) {
Engine.error("Tile host is not an instance of TileEntity");
}
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
int x = ((TileEntity) host).xCoord;
int y = ((TileEntity) host).yCoord;
int z = ((TileEntity) host).zCoord;
Pos center = new Pos(x, y, z);
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Location pos = new Location(world, entry.getKey());
if (offset) {
pos = pos.add(center);
}
pos.markForUpdate();
}
center.markForUpdate(world);
} else {
logger.error("Tile[" + host + "]'s structure map is empty");
}
}
use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class GuiMissileCoordinator method drawGuiContainerForegroundLayer.
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
this.fontRendererObj.drawString("ยง7" + tileEntity.getInventoryName(), 48, 6, 4210752);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.sim"), 50, 20, 4210752);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.from"), 13, 30, 4210752);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.to"), 134, 30, 4210752);
if (this.tileEntity.getStackInSlot(0) != null && this.tileEntity.getStackInSlot(1) != null) {
if (this.tileEntity.getStackInSlot(0).getItem() instanceof IWorldPosItem && this.tileEntity.getStackInSlot(1).getItem() instanceof IWorldPosItem) {
Location pos1 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(0).getItem()).getLocation(this.tileEntity.getStackInSlot(0)));
Location pos2 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(1).getItem()).getLocation(this.tileEntity.getStackInSlot(1)));
double displacement = pos1.distance(pos2);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.displace").replaceAll("%p", "" + UnitDisplay.roundDecimals(displacement)), 13, 65, 4210752);
double w = pos1.toVector2().distance(pos2.toVector2());
double h = 160 + (w * 3) - pos1.y();
double distance = 0.5 * Math.sqrt(16 * (h * h) + (w * w)) + (((w * w) / (8 * h)) * (Math.log(4 * h + Math.sqrt(16 * (h * h) + (w * w))) - Math.log(w)));
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.arc").replaceAll("%p", "" + UnitDisplay.roundDecimals(distance)), 13, 75, 4210752);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.time").replaceAll("%p", "" + UnitDisplay.roundDecimals(Math.max(100, 2 * displacement) / 20)), 13, 85, 4210752);
Location delta = pos1.subtract(pos2);
double rotation = MathHelper.wrapAngleTo180_double(Math.toDegrees(Math.atan2(delta.z(), delta.x()))) - 90;
int heading = MathHelper.floor_double(rotation * 4.0F / 360.0F + 0.5D) & 3;
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.direction") + " " + UnitDisplay.roundDecimals(rotation) + " (" + Direction.directions[heading] + ")", 13, 95, 4210752);
}
}
//this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.wip"), 13, 120, 4210752);
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class ItemRadarGun method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hit_x, float hit_y, float hit_z) {
if (world.isRemote) {
return true;
}
Location location = new Location(world, x, y, z);
TileEntity tile = location.getTileEntity();
if (tile instanceof IMultiTile) {
IMultiTileHost host = ((IMultiTile) tile).getHost();
if (host instanceof TileEntity) {
tile = (TileEntity) host;
}
}
if (player.isSneaking()) {
stack.setTagCompound(null);
stack.setItemDamage(0);
LanguageUtility.addChatToPlayer(player, "gps.cleared");
player.inventoryContainer.detectAndSendChanges();
return true;
} else {
Location storedLocation = getLocation(stack);
if (storedLocation == null || !storedLocation.isAboveBedrock()) {
LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid");
return true;
} else if (tile instanceof ILauncherController) {
((ILauncherController) tile).setTarget(storedLocation.toPos());
LanguageUtility.addChatToPlayer(player, "gps.data.transferred");
return true;
}
}
return false;
}
Aggregations