use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class RenderDroneAI method update.
public void update() {
entityItem.age += 4;
ChunkPosition lastPos = pos;
pos = drone.getTargetedBlock();
if (pos != null) {
if (lastPos == null) {
oldPos = pos;
} else if (!pos.equals(lastPos)) {
progress = 0;
oldPos = lastPos;
}
} else {
oldPos = null;
}
progress = Math.min((float) Math.PI, progress + 0.1F);
Iterator<Pair<RenderCoordWireframe, Integer>> iterator = blackListWireframes.iterator();
while (iterator.hasNext()) {
Pair<RenderCoordWireframe, Integer> wireframe = iterator.next();
wireframe.getKey().ticksExisted++;
wireframe.setValue(wireframe.getValue() - 1);
if (wireframe.getValue() <= 0) {
iterator.remove();
}
}
}
use of net.minecraft.world.ChunkPosition 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 net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class DroneGoToChargingStation method shouldExecute.
/**
* Returns whether the EntityAIBase should begin execution.
*/
@Override
public boolean shouldExecute() {
List<TileEntityChargingStation> validChargingStations = new ArrayList<TileEntityChargingStation>();
if (drone.getPressure(null) < PneumaticValues.DRONE_LOW_PRESSURE) {
for (TileEntity te : (List<TileEntity>) drone.worldObj.loadedTileEntityList) {
if (te instanceof TileEntityChargingStation) {
TileEntityChargingStation station = (TileEntityChargingStation) te;
ChunkPosition pos = new ChunkPosition(station.xCoord, station.yCoord, station.zCoord);
if (DroneClaimManager.getInstance(drone.worldObj).isClaimed(pos)) {
drone.addDebugEntry("gui.progWidget.chargingStation.debug.claimed", pos);
} else if (station.getPressure(ForgeDirection.UNKNOWN) <= PneumaticValues.DRONE_LOW_PRESSURE) {
drone.addDebugEntry("gui.progWidget.chargingStation.debug.notEnoughPressure", pos);
} else if (station.getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) == 0) {
drone.addDebugEntry("gui.progWidget.chargingStation.debug.noDispenserUpgrades", pos);
} else {
validChargingStations.add(station);
}
}
}
}
Collections.sort(validChargingStations, new Comparator() {
@Override
public int compare(Object arg1, Object arg2) {
TileEntity te1 = (TileEntity) arg1;
TileEntity te2 = (TileEntity) arg2;
return Double.compare(PneumaticCraftUtils.distBetween(te1.xCoord, te1.yCoord, te1.zCoord, drone.posX, drone.posY, drone.posZ), PneumaticCraftUtils.distBetween(te2.xCoord, te2.yCoord, te2.zCoord, drone.posX, drone.posY, drone.posZ));
}
});
for (TileEntityChargingStation station : validChargingStations) {
boolean protect = PneumaticCraftUtils.getProtectingSecurityStations(drone.worldObj, station.xCoord, station.yCoord, station.zCoord, drone.getFakePlayer(), false, false) > 0;
ChunkPosition pos = new ChunkPosition(station.xCoord, station.yCoord, station.zCoord);
if (protect) {
drone.addDebugEntry("gui.progWidget.chargingStation.debug.protected", pos);
} else if (drone.getPathNavigator().moveToXYZ(station.xCoord, station.yCoord + 1.5, station.zCoord) || drone.getPathNavigator().isGoingToTeleport()) {
isExecuting = true;
curCharger = station;
DroneClaimManager.getInstance(drone.worldObj).claim(pos);
return true;
} else {
drone.addDebugEntry("gui.progWidget.chargingStation.debug.cantNavigate", pos);
}
}
isExecuting = false;
return false;
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class DroneAIBlockInteraction method continueExecuting.
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
@Override
public boolean continueExecuting() {
if (aborted)
return false;
if (searching) {
//Wait until the area is sorted from closest to furtherest.
if (!sorter.isDone())
return true;
boolean firstRun = true;
//keeps track of the looked up blocks, and stops searching when we reach our quota.
int searchedBlocks = 0;
while (curPos == null && curY != lastSuccessfulY && order != ProgWidgetDigAndPlace.EnumOrder.CLOSEST || firstRun) {
firstRun = false;
while (!shouldAbort() && searchIndex < area.size()) {
ChunkPosition pos = area.get(searchIndex);
if (isYValid(pos.chunkPosY) && !blacklist.contains(pos) && (!respectClaims() || !DroneClaimManager.getInstance(drone.getWorld()).isClaimed(pos))) {
indicateToListeningPlayers(pos);
if (isValidPosition(pos)) {
curPos = pos;
if (moveToPositions()) {
if (moveIntoBlock()) {
if (drone.getPathNavigator().moveToXYZ(curPos.chunkPosX, curPos.chunkPosY + 0.5, curPos.chunkPosZ)) {
searching = false;
totalActions++;
if (respectClaims())
DroneClaimManager.getInstance(drone.getWorld()).claim(pos);
//clear the list for next time (maybe the blocks/rights have changed by the time there will be dug again).
blacklist.clear();
return true;
}
} else {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (drone.getPathNavigator().moveToXYZ(curPos.chunkPosX + dir.offsetX, curPos.chunkPosY + dir.offsetY + 0.5, curPos.chunkPosZ + dir.offsetZ)) {
searching = false;
totalActions++;
if (respectClaims())
DroneClaimManager.getInstance(drone.getWorld()).claim(pos);
//clear the list for next time (maybe the blocks/rights have changed by the time there will be dug again).
blacklist.clear();
return true;
}
}
}
if (drone.getPathNavigator().isGoingToTeleport()) {
searching = false;
totalActions++;
if (respectClaims())
DroneClaimManager.getInstance(drone.getWorld()).claim(pos);
//clear the list for next time (maybe the blocks/rights have changed by the time there will be dug again).
blacklist.clear();
return true;
} else {
drone.addDebugEntry("gui.progWidget.general.debug.cantNavigate", pos);
}
} else {
searching = false;
totalActions++;
return true;
}
}
searchedBlocks++;
}
searchIndex++;
if (searchedBlocks >= lookupsPerSearch())
return true;
}
if (curPos == null)
updateY();
}
if (!shouldAbort())
addEndingDebugEntry();
return false;
} else {
Vec3 dronePos = drone.getPosition();
double dist = curPos != null ? PneumaticCraftUtils.distBetween(curPos.chunkPosX + 0.5, curPos.chunkPosY + 0.5, curPos.chunkPosZ + 0.5, dronePos.xCoord, dronePos.yCoord, dronePos.zCoord) : 0;
if (curPos != null) {
if (!moveToPositions())
return doBlockInteraction(curPos, dist);
if (respectClaims())
DroneClaimManager.getInstance(drone.getWorld()).claim(curPos);
if (dist < (moveIntoBlock() ? 1 : 2)) {
return doBlockInteraction(curPos, dist);
}
}
return !drone.getPathNavigator().hasNoPath();
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class DroneAIManager method writeToNBT.
public void writeToNBT(NBTTagCompound tag) {
NBTTagList tagList = new NBTTagList();
for (Map.Entry<String, ChunkPosition> entry : coordinateVariables.entrySet()) {
NBTTagCompound t = new NBTTagCompound();
t.setString("key", entry.getKey());
t.setInteger("x", entry.getValue().chunkPosX);
t.setInteger("y", entry.getValue().chunkPosY);
t.setInteger("z", entry.getValue().chunkPosZ);
tagList.appendTag(t);
}
tag.setTag("coords", tagList);
GlobalVariableManager.getInstance().writeItemVars(tag, itemVariables);
}
Aggregations