use of pneumaticCraft.common.progwidgets.ISidedWidget in project PneumaticCraft by MineMaarten.
the class DroneEntityAIInventoryExport method export.
private boolean export(ChunkPosition pos, boolean simulate) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack droneStack = drone.getInventory().getStackInSlot(i);
if (droneStack != null) {
if (widget.isItemValidForFilters(droneStack)) {
for (int side = 0; side < 6; side++) {
droneStack = drone.getInventory().getStackInSlot(i);
if (((ISidedWidget) widget).getSides()[side] && droneStack != null) {
droneStack = droneStack.copy();
int oldCount = droneStack.stackSize;
if (((ICountWidget) widget).useCount())
droneStack.stackSize = Math.min(droneStack.stackSize, getRemainingCount());
ItemStack remainder = IOHelper.insert(inv, droneStack.copy(), side, simulate);
int stackSize = drone.getInventory().getStackInSlot(i).stackSize - (remainder == null ? droneStack.stackSize : droneStack.stackSize - remainder.stackSize);
droneStack.stackSize = stackSize;
int exportedItems = oldCount - stackSize;
if (!simulate) {
drone.getInventory().setInventorySlotContents(i, stackSize > 0 ? droneStack : null);
decreaseCount(exportedItems);
}
if (simulate && exportedItems > 0)
return true;
// doing it for every side for no side sensitive inventories would be a waste.
if (!(inv instanceof ISidedInventory))
break;
}
}
if (droneStack == null && !simulate)
drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
else
drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
} else {
drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
}
}
}
} else {
drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
}
return false;
}
use of pneumaticCraft.common.progwidgets.ISidedWidget in project PneumaticCraft by MineMaarten.
the class DroneEntityAIInventoryImport method importItems.
private boolean importItems(ChunkPosition pos, boolean simulate) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
for (Integer i : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && IOHelper.canExtractItemFromInventory(inv, stack, i, ((ISidedWidget) widget).getSides())) {
if (widget.isItemValidForFilters(stack)) {
ItemStack importedStack = stack.copy();
if (((ICountWidget) widget).useCount())
importedStack.stackSize = Math.min(importedStack.stackSize, getRemainingCount());
ItemStack remainder = IOHelper.insert(drone.getInventory(), importedStack.copy(), 0, simulate);
int removedItems = importedStack.stackSize - (remainder != null ? remainder.stackSize : 0);
if (!simulate) {
ItemStack newStack = stack.copy();
newStack.stackSize = stack.stackSize - removedItems;
inv.setInventorySlotContents(i, newStack.stackSize > 0 ? newStack : null);
decreaseCount(removedItems);
drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
if (((ICountWidget) widget).useCount() && getRemainingCount() <= 0)
return false;
} else if (removedItems > 0) {
return true;
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.filledToMax", pos);
}
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.stackdoesntPassFilter", pos);
}
}
}
} else {
drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
}
return false;
}
use of pneumaticCraft.common.progwidgets.ISidedWidget in project PneumaticCraft by MineMaarten.
the class GuiProgWidgetCondition method initGui.
@Override
public void initGui() {
super.initGui();
if (isSidedWidget()) {
for (int i = 0; i < 6; i++) {
String sideName = PneumaticCraftUtils.getOrientationName(ForgeDirection.getOrientation(i));
GuiCheckBox checkBox = new GuiCheckBox(i, guiLeft + 4, guiTop + 30 + i * 12, 0xFF000000, sideName);
checkBox.checked = ((ISidedWidget) widget).getSides()[i];
addWidget(checkBox);
}
}
int baseX = isSidedWidget() ? 90 : 4;
int baseY = isUsingAndOr() ? 60 : 30;
List<GuiRadioButton> radioButtons;
GuiRadioButton radioButton;
if (isUsingAndOr()) {
radioButtons = new ArrayList<GuiRadioButton>();
radioButton = new GuiRadioButton(6, guiLeft + baseX, guiTop + 30, 0xFF000000, "Any block");
radioButton.checked = !((ICondition) widget).isAndFunction();
addWidget(radioButton);
radioButtons.add(radioButton);
radioButton.otherChoices = radioButtons;
radioButton = new GuiRadioButton(7, guiLeft + baseX, guiTop + 42, 0xFF000000, "All blocks");
radioButton.checked = ((ICondition) widget).isAndFunction();
addWidget(radioButton);
radioButtons.add(radioButton);
radioButton.otherChoices = radioButtons;
}
if (requiresNumber()) {
radioButtons = new ArrayList<GuiRadioButton>();
for (int i = 0; i < ICondition.Operator.values().length; i++) {
radioButton = new GuiRadioButton(8 + i, guiLeft + baseX, guiTop + baseY + i * 12, 0xFF000000, ICondition.Operator.values()[i].toString());
radioButton.checked = ((ICondition) widget).getOperator().ordinal() == i;
addWidget(radioButton);
radioButtons.add(radioButton);
radioButton.otherChoices = radioButtons;
}
textField = new WidgetTextField(Minecraft.getMinecraft().fontRenderer, guiLeft + baseX, guiTop + baseY + 30, 50, 11);
textField.setText(((ICondition) widget).getRequiredCount() + "");
addWidget(textField);
}
}
use of pneumaticCraft.common.progwidgets.ISidedWidget in project PneumaticCraft by MineMaarten.
the class DroneAIPlace method doBlockInteraction.
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
if (drone.getPathNavigator().hasNoPath()) {
ForgeDirection side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
ItemStack droneStack = drone.getInventory().getStackInSlot(i);
if (droneStack != null && droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).field_150939_a.canPlaceBlockOnSide(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()).ordinal())) {
if (widget.isItemValidForFilters(droneStack)) {
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
// Teleport the drone to make sure it isn't in the way of placing a block.
entity.setPosition(entity.posX, entity.posY + 200, entity.posZ);
}
if (drone.getWorld().canPlaceEntityOnSide(((ItemBlock) droneStack.getItem()).field_150939_a, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, false, 0, null, droneStack)) {
Block block = Block.getBlockFromItem(droneStack.getItem());
int meta = droneStack.getItem().getMetadata(droneStack.getItemDamage());
int newMeta = block.onBlockPlaced(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), side.offsetX, side.offsetY, side.offsetZ, meta);
setFakePlayerAccordingToDir();
if (placeBlockAt(droneStack, drone.getFakePlayer(), drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, side.ordinal(), 0, 0, 0, newMeta)) {
drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
drone.getWorld().playSoundEffect(pos.chunkPosX + 0.5F, pos.chunkPosY + 0.5F, pos.chunkPosZ + 0.5F, block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
if (--droneStack.stackSize <= 0) {
drone.getInventory().setInventorySlotContents(i, null);
}
}
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
}
return false;
}
if (drone instanceof EntityDrone) {
EntityDrone entity = (EntityDrone) drone;
entity.setPosition(entity.posX, entity.posY - 200, entity.posZ);
}
}
}
}
return false;
} else {
return true;
}
}
Aggregations