use of me.desht.pneumaticcraft.common.entity.living.EntityDrone in project pnc-repressurized by TeamPneumatic.
the class AmadronOfferManager method tryRestockCustomOffers.
public void tryRestockCustomOffers() {
for (AmadronOffer offer : allOffers) {
if (offer instanceof AmadronOfferCustom) {
AmadronOfferCustom custom = (AmadronOfferCustom) offer;
TileEntity input = custom.getProvidingTileEntity();
TileEntity output = custom.getReturningTileEntity();
int possiblePickups = ContainerAmadron.capShoppingAmount(custom.invert(), 50, getItemHandler(input), getItemHandler(output), getFluidHandler(input), getFluidHandler(output), null);
if (possiblePickups > 0) {
BlockPos pos = new BlockPos(input.getPos().getX(), input.getPos().getY(), input.getPos().getZ());
EntityDrone drone = ContainerAmadron.retrieveOrderItems(custom, possiblePickups, input.getWorld(), pos, input.getWorld(), pos);
if (drone != null) {
drone.setHandlingOffer(custom.copy(), possiblePickups, null, "Restock");
}
}
custom.invert();
custom.payout();
}
}
}
use of me.desht.pneumaticcraft.common.entity.living.EntityDrone in project pnc-repressurized by TeamPneumatic.
the class ProgWidgetDroneConditionEntity method getCount.
@Override
protected int getCount(IDroneBase d, IProgWidget widget) {
EntityDrone drone = (EntityDrone) d;
int count = 0;
for (Entity e : drone.getPassengers()) {
if (((IEntityProvider) widget).isEntityValid(e))
count++;
}
return count;
// return drone.getPassengers().isEmpty() || !((IEntityProvider) widget).isEntityValid(drone.riddenByEntity) ? 0 : 1;
}
use of me.desht.pneumaticcraft.common.entity.living.EntityDrone in project pnc-repressurized by TeamPneumatic.
the class EventHandlerPneumaticCraft method onAmadronSuccess.
@SubscribeEvent
public void onAmadronSuccess(AmadronRetrievalEvent event) {
EntityDrone drone = (EntityDrone) event.drone;
AmadronOffer offer = drone.getHandlingOffer();
boolean shouldDeliver = false;
if (offer instanceof AmadronOfferCustom) {
AmadronOffer realOffer = AmadronOfferManager.getInstance().get(offer);
if (realOffer != null) {
// If we find the non-inverted offer, that means the Drone just has completed trading with a different player.
((AmadronOfferCustom) realOffer).addPayment(drone.getOfferTimes());
((AmadronOfferCustom) realOffer).addStock(-drone.getOfferTimes());
realOffer.onTrade(drone.getOfferTimes(), drone.getBuyingPlayer());
shouldDeliver = true;
}
realOffer = AmadronOfferManager.getInstance().get(((AmadronOfferCustom) offer).copy().invert());
if (realOffer != null) {
// If we find the inverted offer, that means the Drone has just restocked.
((AmadronOfferCustom) realOffer).addStock(drone.getOfferTimes());
}
} else {
shouldDeliver = true;
}
if (shouldDeliver) {
ItemStack usedTablet = drone.getUsedTablet();
if (offer.getOutput() instanceof ItemStack) {
ItemStack offeringItems = (ItemStack) offer.getOutput();
int producedItems = offeringItems.getCount() * drone.getOfferTimes();
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (producedItems > 0) {
ItemStack stack = offeringItems.copy();
stack.setCount(Math.min(producedItems, stack.getMaxStackSize()));
stacks.add(stack);
producedItems -= stack.getCount();
}
BlockPos pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
if (pos != null) {
World world = DimensionManager.getWorld(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
DroneRegistry.getInstance().deliverItemsAmazonStyle(world, pos, stacks.toArray(new ItemStack[stacks.size()]));
}
} else {
FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
offeringFluid.amount *= drone.getOfferTimes();
BlockPos pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
if (pos != null) {
World world = DimensionManager.getWorld(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
DroneRegistry.getInstance().deliverFluidAmazonStyle(world, pos, offeringFluid);
}
}
}
}
use of me.desht.pneumaticcraft.common.entity.living.EntityDrone in project pnc-repressurized by TeamPneumatic.
the class DroneAIPlace method isValidPosition.
@Override
protected boolean isValidPosition(BlockPos pos) {
if (drone.world().isAirBlock(pos)) {
boolean failedOnPlacement = false;
for (int i = 0; i < drone.getInv().getSlots(); i++) {
ItemStack droneStack = drone.getInv().getStackInSlot(i);
if (droneStack.getItem() instanceof ItemBlock) {
if (widget.isItemValidForFilters(droneStack)) {
Block placingBlock = ((ItemBlock) droneStack.getItem()).getBlock();
EnumFacing side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
if (drone.world().mayPlace(placingBlock, pos, false, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) {
return true;
} else {
if (drone.world().mayPlace(placingBlock, pos, true, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) {
drone.addDebugEntry("gui.progWidget.place.debug.cantPlaceBlock", pos);
} else {
drone.addDebugEntry("gui.progWidget.place.debug.entityInWay", pos);
}
failedOnPlacement = true;
}
}
}
}
if (!failedOnPlacement)
abort();
}
return false;
}
use of me.desht.pneumaticcraft.common.entity.living.EntityDrone in project pnc-repressurized by TeamPneumatic.
the class PacketUpdateDebuggingDrone method handleServerSide.
@Override
public void handleServerSide(PacketUpdateDebuggingDrone message, EntityPlayer player) {
ItemStack stack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!stack.isEmpty()) {
NBTUtil.setInteger(stack, NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE, message.entityId);
Entity entity = player.world.getEntityByID(message.entityId);
if (entity instanceof EntityDrone) {
((EntityDrone) entity).trackAsDebugged((EntityPlayerMP) player);
}
}
}
Aggregations