use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.
the class RenderProgrammableController method renderTileEntityAt.
/*
* TileEntitySpecialRenderer part
*/
@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
if (renderDrone == null) {
renderDrone = new RenderDrone(false);
renderDrone.setRenderManager(RenderManager.instance);
drone = new EntityDrone(tileentity.getWorldObj());
}
TileEntityProgrammableController te = (TileEntityProgrammableController) tileentity;
double droneX = te.oldCurX + (te.getPosition().xCoord - te.oldCurX) * f - te.xCoord + 0.5 + d0;
double droneY = te.oldCurY + (te.getPosition().yCoord - te.oldCurY) * f - te.yCoord - 0.2 + d1;
double droneZ = te.oldCurZ + (te.getPosition().zCoord - te.oldCurZ) * f - te.zCoord + 0.5 + d2;
renderDrone.doRender((Entity) drone, droneX, droneY, droneZ, 0, f);
}
use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.
the class EventHandlerPneumaticCraft method onDroneSuicide.
@SubscribeEvent
public void onDroneSuicide(DroneSuicideEvent event) {
if (event.drone instanceof EntityDrone) {
EntityDrone drone = (EntityDrone) event.drone;
AmadronOffer offer = drone.getHandlingOffer();
if (offer != null) {
int times = drone.getOfferTimes();
if (offer.getInput() instanceof ItemStack) {
int requiredCount = ((ItemStack) offer.getInput()).stackSize * times;
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
if (drone.getInventory().getStackInSlot(i) != null) {
requiredCount -= drone.getInventory().getStackInSlot(i).stackSize;
}
}
if (requiredCount <= 0) {
for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
drone.getInventory().setInventorySlotContents(i, null);
}
MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
}
} else {
int requiredCount = ((FluidStack) offer.getInput()).amount * times;
if (drone.getTank().getFluidAmount() >= requiredCount) {
MinecraftForge.EVENT_BUS.post(new AmadronRetrievalEvent(event.drone));
}
}
}
}
}
use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.
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.stackSize * drone.getOfferTimes();
List<ItemStack> stacks = new ArrayList<ItemStack>();
while (producedItems > 0) {
ItemStack stack = offeringItems.copy();
stack.stackSize = Math.min(producedItems, stack.getMaxStackSize());
stacks.add(stack);
producedItems -= stack.stackSize;
}
ChunkPosition pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
if (pos != null) {
World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
PneumaticRegistry.getInstance().deliverItemsAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()]));
}
} else {
FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
offeringFluid.amount *= drone.getOfferTimes();
ChunkPosition pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
if (pos != null) {
World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
PneumaticRegistry.getInstance().deliverFluidAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, offeringFluid);
}
}
}
}
use of pneumaticCraft.common.entity.living.EntityDrone 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;
}
}
use of pneumaticCraft.common.entity.living.EntityDrone in project PneumaticCraft by MineMaarten.
the class BlockDroneRedstoneEmitter method isProvidingWeakPower.
/**
* Returns true if the block is emitting indirect/weak redstone power on the
* specified side. If isBlockNormalCube returns true, standard redstone
* propagation rules will apply instead and this will not be called. Args:
* World, X, Y, Z, side. Note that the side is reversed - eg it is 1 (up)
* when checking the bottom of the block.
*/
@Override
public int isProvidingWeakPower(IBlockAccess blockAccess, int x, int y, int z, int side) {
if (blockAccess instanceof World) {
World world = (World) blockAccess;
List<EntityDrone> drones = world.getEntitiesWithinAABB(EntityDrone.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
int signal = 0;
for (EntityDrone drone : drones) {
signal = Math.max(signal, drone.getEmittingRedstone(ForgeDirection.getOrientation(side).getOpposite()));
}
return signal;
} else {
return 0;
}
}
Aggregations