use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateNullCell method onActivated.
// In-world customization
@Override
public boolean onActivated(EntityPlayer player, QMovingObjectPosition mop, ItemStack item) {
Vec3d hit = new Vec3d(mop.hitVec).sub(mop.blockX, mop.blockY, mop.blockZ).rotateUndo(getFace(), Vec3d.center);
if (item != null) {
if (item.getItem() instanceof ItemPart) {
IPart part = ((ItemPart) item.getItem()).createPart(item, player, null, null);
if (part != null && part instanceof PartRedwireFaceUninsulated) {
PartRedwireFace wire = (PartRedwireFace) part;
if (hit.getY() > 2 / 16D) {
if (typeB == null) {
if (getWorld().isRemote)
return true;
typeB = wire.getRedwireType(ForgeDirection.UNKNOWN);
bundledB = false;
inWorldB = true;
getRedstoneConnectionCache().recalculateConnections();
sendUpdatePacket();
if (!player.capabilities.isCreativeMode)
item.stackSize--;
return true;
}
} else {
if (typeA == null) {
if (getWorld().isRemote)
return true;
typeA = wire.getRedwireType(ForgeDirection.UNKNOWN);
bundledA = false;
inWorldA = true;
getRedstoneConnectionCache().recalculateConnections();
sendUpdatePacket();
if (!player.capabilities.isCreativeMode)
item.stackSize--;
return true;
}
}
}
} else if (item.getItem() instanceof IScrewdriver && player.isSneaking()) {
if (hit.getY() > 2 / 16D && ((hit.getY() <= 4 / 16D && hit.getX() > 0.5 - 1 / 16D && hit.getX() > 0.5 + 1 / 16D) || hit.getY() > 4 / 16D)) {
if (typeB != null) {
if (getWorld().isRemote)
return true;
IOHelper.spawnItemInWorld(getWorld(), typeB.getPartInfo(MinecraftColor.NONE, bundledB).getStack(), getX() + 0.5, getY() + 0.5, getZ() + 0.5);
typeB = null;
bundledB = false;
inWorldB = false;
((IScrewdriver) item.getItem()).damage(item, 1, player, false);
getRedstoneConnectionCache().recalculateConnections();
sendUpdatePacket();
return true;
}
} else if (hit.getY() > 2 / 16D) {
if (typeA != null) {
if (getWorld().isRemote)
return true;
IOHelper.spawnItemInWorld(getWorld(), typeA.getPartInfo(MinecraftColor.NONE, bundledA).getStack(), getX() + 0.5, getY() + 0.5, getZ() + 0.5);
typeA = null;
bundledA = false;
inWorldA = false;
((IScrewdriver) item.getItem()).damage(item, 1, player, false);
getRedstoneConnectionCache().recalculateConnections();
sendUpdatePacket();
return true;
}
}
}
}
return super.onActivated(player, mop, item);
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class RecipeNullCell method getCraftingResult.
private ItemStack getCraftingResult(IInventory inv, EntityPlayer player, boolean isCrafting) {
if (inv.getSizeInventory() < 9)
return null;
int centerX = 0;
int centerY = 0;
GateNullCell gnc = null;
// Find the null cell
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
ItemStack item = getItemAt(inv, x, y);
if (item == null)
continue;
if (!(item.getItem() instanceof ItemPart))
continue;
IPart p = ((ItemPart) item.getItem()).createPart(item, BluePower.proxy.getPlayer(), null, null);
if (p != null && p instanceof GateNullCell) {
gnc = (GateNullCell) p;
centerX = x;
centerY = y;
break;
}
}
if (gnc != null)
break;
}
// If there's no null cell, return null
if (gnc == null)
return null;
// Make this recipe invalid if there's items where there shouldn't be
{
// To the right
if (centerX < 2)
for (int x = centerX + 1; x < 3; x++) for (int y = 0; y < 3; y++) if (getItemAt(inv, x, y) != null)
return null;
// To the left - 1
for (int x = 0; x < centerX - 1; x++) for (int y = 0; y < 3; y++) if (getItemAt(inv, x, y) != null)
return null;
// To the left
if (centerX > 0) {
if (getItemAt(inv, centerX - 1, 0) != null)
return null;
if (getItemAt(inv, centerX - 1, 2) != null)
return null;
}
}
// Determine what kind of crafting operation this is
// Removing > adding
{
// Removing
{
// Screwdriver on top
if (centerY > 0) {
ItemStack sd = getItemAt(inv, centerX, centerY - 1);
if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
RedwireType t = gnc.getTypeB();
boolean bundled = gnc.isBundledB();
if (t != null) {
boolean can = true;
if (centerY < 2)
if (getItemAt(inv, centerX, centerY + 1) != null)
can = false;
if (centerX > 0)
if (getItemAt(inv, centerX - 1, centerY) != null)
can = false;
if (!((IScrewdriver) sd.getItem()).damage(sd, getItemAt(inv, centerX, centerY).stackSize, null, true))
can = false;
if (can) {
ItemStack wire = PartManager.getPartInfo("wire." + t.getName() + (bundled ? ".bundled" : "")).getStack(getItemAt(inv, centerX, centerY).stackSize);
if (isCrafting) {
gnc = new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), null, false);
ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
setItemAt(inv, centerX, centerY, nullCellStack);
sd.stackSize++;
((IScrewdriver) sd.getItem()).damage(sd, nullCellStack.stackSize - 1, null, false);
}
return wire;
}
}
}
}
// Screwdriver below
if (centerY < 2) {
ItemStack sd = getItemAt(inv, centerX, centerY + 1);
if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
RedwireType t = gnc.getTypeA();
boolean bundled = gnc.isBundledA();
if (t != null) {
boolean can = true;
if (centerY > 0)
if (getItemAt(inv, centerX, centerY - 1) != null)
can = false;
if (centerX > 0)
if (getItemAt(inv, centerX - 1, centerY) != null)
can = false;
if (!((IScrewdriver) sd.getItem()).damage(sd, getItemAt(inv, centerX, centerY).stackSize, null, true))
can = false;
if (can) {
ItemStack wire = PartManager.getPartInfo("wire." + t.getName() + (bundled ? ".bundled" : "")).getStack(getItemAt(inv, centerX, centerY).stackSize);
if (isCrafting) {
gnc = new GateNullCell(null, false, gnc.getTypeB(), gnc.isBundledB());
ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
setItemAt(inv, centerX, centerY, nullCellStack);
sd.stackSize++;
((IScrewdriver) sd.getItem()).damage(sd, nullCellStack.stackSize - 1, null, false);
}
return wire;
}
}
}
}
// Screwdriver on the left
if (centerX > 0) {
ItemStack sd = getItemAt(inv, centerX - 1, centerY);
if (sd != null && sd.getItem() instanceof ItemScrewdriver) {
RedwireType tA = gnc.getTypeA();
boolean bundledA = gnc.isBundledA();
RedwireType tB = gnc.getTypeB();
boolean bundledB = gnc.isBundledB();
if (tA != null || tB != null) {
boolean can = true;
if (centerY > 0)
if (getItemAt(inv, centerX, centerY - 1) != null)
can = false;
if (centerY < 2)
if (getItemAt(inv, centerX, centerY + 1) != null)
can = false;
int amt = 0;
if (tA != null && (tB == null || tB == tA))
amt += getItemAt(inv, centerX, centerY).stackSize;
if (tB != null)
amt += getItemAt(inv, centerX, centerY).stackSize;
if (amt > 64)
can = false;
if (!((IScrewdriver) sd.getItem()).damage(sd, amt, null, true))
can = false;
if (can) {
ItemStack wire = null;
if (tB != null) {
wire = PartManager.getPartInfo("wire." + tB.getName() + (bundledB ? ".bundled" : "")).getStack(amt);
} else {
wire = PartManager.getPartInfo("wire." + tA.getName() + (bundledA ? ".bundled" : "")).getStack(amt);
}
if (isCrafting) {
if (tA != null && tB != null && tA == tB) {
gnc = new GateNullCell(null, false, null, false);
} else if (tB != null) {
gnc = new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), null, false);
} else if (tA != null) {
gnc = new GateNullCell(null, false, gnc.getTypeB(), gnc.isBundledB());
}
ItemStack nullCellStack = GateNullCell.getStackWithData(gnc);
nullCellStack.stackSize = getItemAt(inv, centerX, centerY).stackSize + 1;
setItemAt(inv, centerX, centerY, nullCellStack);
sd.stackSize++;
System.out.println(((IScrewdriver) sd.getItem()).damage(sd, amt, null, false) + " " + player);
}
return wire;
}
}
}
}
}
// Adding
{
// Wire on top
if (centerY > 0 && gnc.getTypeB() == null) {
ItemStack wire = getItemAt(inv, centerX, centerY - 1);
if (wire != null && wire.getItem() instanceof ItemPart) {
IPart p = ((ItemPart) wire.getItem()).createPart(wire, BluePower.proxy.getPlayer(), null, null);
if (p != null && p instanceof PartRedwireFaceUninsulated) {
RedwireType t = ((PartRedwireFace) p).getRedwireType(ForgeDirection.UNKNOWN);
boolean bundled = false;
boolean can = true;
if (centerY < 2)
if (getItemAt(inv, centerX, centerY + 1) != null)
can = false;
if (centerX > 0)
if (getItemAt(inv, centerX - 1, centerY) != null)
can = false;
if (can)
return GateNullCell.getStackWithData(new GateNullCell(gnc.getTypeA(), gnc.isBundledA(), t, bundled));
}
}
}
// Wire below
if (centerY < 2 && gnc.getTypeA() == null) {
ItemStack wire = getItemAt(inv, centerX, centerY + 1);
if (wire != null && wire.getItem() instanceof ItemPart) {
IPart p = ((ItemPart) wire.getItem()).createPart(wire, BluePower.proxy.getPlayer(), null, null);
if (p != null && p instanceof PartRedwireFaceUninsulated) {
RedwireType t = ((PartRedwireFace) p).getRedwireType(ForgeDirection.UNKNOWN);
boolean bundled = false;
boolean can = true;
if (centerY > 0)
if (getItemAt(inv, centerX, centerY - 1) != null)
can = false;
if (centerX > 0)
if (getItemAt(inv, centerX - 1, centerY) != null)
can = false;
if (can)
return GateNullCell.getStackWithData(new GateNullCell(t, bundled, gnc.getTypeB(), gnc.isBundledB()));
}
}
}
// Wire below
if (centerY == 1 && gnc.getTypeA() == null && gnc.getTypeB() == null) {
ItemStack wireA = getItemAt(inv, centerX, centerY + 1);
ItemStack wireB = getItemAt(inv, centerX, centerY - 1);
if (wireA != null && wireA.getItem() instanceof ItemPart && wireB != null && wireB.getItem() instanceof ItemPart) {
IPart pA = ((ItemPart) wireA.getItem()).createPart(wireA, BluePower.proxy.getPlayer(), null, null);
IPart pB = ((ItemPart) wireB.getItem()).createPart(wireB, BluePower.proxy.getPlayer(), null, null);
if (pA != null && pA instanceof PartRedwireFaceUninsulated && pB != null && pB instanceof PartRedwireFaceUninsulated) {
RedwireType tA = ((PartRedwireFace) pA).getRedwireType(ForgeDirection.UNKNOWN);
boolean bundledA = false;
RedwireType tB = ((PartRedwireFace) pB).getRedwireType(ForgeDirection.UNKNOWN);
boolean bundledB = false;
boolean can = true;
if (centerX > 0)
if (getItemAt(inv, centerX - 1, centerY) != null)
can = false;
if (can)
return GateNullCell.getStackWithData(new GateNullCell(tA, bundledA, tB, bundledB));
}
}
}
}
}
return null;
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class BundledPropagator method propagate.
@Override
public void propagate() {
if ((device instanceof IPart && ((IPart) device).getParent() == null) || device.getWorld() == null)
return;
for (MinecraftColor c : MinecraftColor.VALID_COLORS) {
IRedstoneDevice dev;
if (device instanceof IInsulatedRedwire) {
dev = (IRedstoneDevice) device;
} else {
dev = BundledDeviceWrapper.wrap(device, c);
}
if (dev == null)
continue;
RedstoneApi.getInstance().getRedstonePropagator(dev, side).propagate();
}
}
Aggregations