use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.
the class LogisticsSolidBlock method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World world, int posX, int posY, int posZ, EntityLivingBase entity, ItemStack itemStack) {
super.onBlockPlacedBy(world, posX, posY, posZ, entity, itemStack);
TileEntity tile = world.getTileEntity(posX, posY, posZ);
if (tile instanceof LogisticsCraftingTableTileEntity) {
((LogisticsCraftingTableTileEntity) tile).placedBy(entity);
}
if (tile instanceof IRotationProvider) {
double x = tile.xCoord + 0.5 - entity.posX;
double z = tile.zCoord + 0.5 - entity.posZ;
double w = Math.atan2(x, z);
double halfPI = Math.PI / 2;
double halfhalfPI = halfPI / 2;
w -= halfhalfPI;
if (w < 0) {
w += 2 * Math.PI;
}
if (0 < w && w <= halfPI) {
((IRotationProvider) tile).setRotation(1);
} else if (halfPI < w && w <= 2 * halfPI) {
((IRotationProvider) tile).setRotation(2);
} else if (2 * halfPI < w && w <= 3 * halfPI) {
((IRotationProvider) tile).setRotation(0);
} else if (3 * halfPI < w && w <= 4 * halfPI) {
((IRotationProvider) tile).setRotation(3);
}
}
}
use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.
the class FindMostLikelyRecipeComponents method processPacket.
@Override
public void processPacket(EntityPlayer player) {
TileEntity tile = this.getTile(player.getEntityWorld(), TileEntity.class);
CoreRoutedPipe pipe = null;
if (tile instanceof LogisticsCraftingTableTileEntity) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity conn = CoordinateUtils.add(((LogisticsCraftingTableTileEntity) tile).getLPPosition(), dir).getTileEntity(player.getEntityWorld());
if (conn instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) conn).pipe instanceof PipeItemsCraftingLogistics) {
pipe = (CoreRoutedPipe) ((LogisticsTileGenericPipe) conn).pipe;
break;
}
}
}
} else if (tile instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) tile).pipe instanceof PipeBlockRequestTable) {
pipe = (CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe;
}
}
List<Integer> list = new ArrayList<Integer>(content.size());
while (list.size() < content.size()) {
list.add(-1);
}
if (pipe == null)
return;
LinkedList<ItemIdentifier> craftable = null;
for (int j = 0; j < content.size(); j++) {
GuiRecipeImport.Canidates canidates = content.get(j);
int maxItemPos = -1;
int max = 0;
for (int i = 0; i < canidates.order.size(); i++) {
ItemIdentifier ident = canidates.order.get(i).getItem();
int newAmount = SimpleServiceLocator.logisticsManager.getAmountFor(ident, pipe.getRouter().getIRoutersByCost());
if (newAmount > max) {
max = newAmount;
maxItemPos = i;
}
}
if (max < 64) {
if (craftable == null) {
craftable = SimpleServiceLocator.logisticsManager.getCraftableItems(pipe.getRouter().getIRoutersByCost());
}
for (ItemIdentifier craft : craftable) {
for (int i = 0; i < canidates.order.size(); i++) {
ItemIdentifier ident = canidates.order.get(i).getItem();
if (craft == ident) {
maxItemPos = i;
break;
}
}
}
}
list.set(j, maxItemPos);
}
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(MostLikelyRecipeComponentsResponse.class).setResponse(list), player);
}
use of logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity in project LogisticsPipes by RS485.
the class LogisticsCraftingTable method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
return false;
}
LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
ItemIdentifierStack result = bench.resultInv.getIDStackInSlot(0);
if (result == null) {
return false;
}
inventory.setInventorySlotContents(9, result);
// Import
for (int i = 0; i < bench.matrix.getSizeInventory(); i++) {
if (i >= inventory.getSizeInventory() - 2) {
break;
}
final ItemStack newStack = bench.matrix.getStackInSlot(i) == null ? null : bench.matrix.getStackInSlot(i).copy();
if (newStack != null && newStack.stackSize > 1) {
newStack.stackSize = 1;
}
inventory.setInventorySlotContents(i, newStack);
}
if (!bench.isFuzzy()) {
inventory.compact_first(9);
}
return true;
}
Aggregations