use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ProgWidgetArea method getAreaPoints.
private ChunkPosition[] getAreaPoints() {
ChunkPosition c1;
if (coord1Variable.equals("")) {
c1 = x1 != 0 || y1 != 0 || z1 != 0 ? new ChunkPosition(x1, y1, z1) : null;
} else {
c1 = aiManager != null ? aiManager.getCoordinate(coord1Variable) : null;
}
ChunkPosition c2;
if (coord2Variable.equals("")) {
c2 = x2 != 0 || y2 != 0 || z2 != 0 ? new ChunkPosition(x2, y2, z2) : null;
} else {
c2 = aiManager != null ? aiManager.getCoordinate(coord2Variable) : null;
}
if (c1 == null && c2 == null) {
return new ChunkPosition[] { null, null };
} else if (c1 == null) {
return new ChunkPosition[] { c2, null };
} else if (c2 == null) {
return new ChunkPosition[] { c1, null };
} else {
return new ChunkPosition[] { c1, c2 };
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onChunkSave.
@SubscribeEvent
public void onChunkSave(ChunkDataEvent.Save event) {
Map<ChunkPosition, ISemiBlock> map = semiBlocks.get(event.getChunk());
if (map != null && map.size() > 0) {
NBTTagList tagList = new NBTTagList();
for (Map.Entry<ChunkPosition, ISemiBlock> entry : map.entrySet()) {
NBTTagCompound t = new NBTTagCompound();
entry.getValue().writeToNBT(t);
t.setInteger("x", entry.getKey().chunkPosX);
t.setInteger("y", entry.getKey().chunkPosY);
t.setInteger("z", entry.getKey().chunkPosZ);
t.setString("type", getKeyForSemiBlock(entry.getValue()));
tagList.appendTag(t);
}
event.getData().setTag("SemiBlocks", tagList);
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onClientTick.
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if (this == getServerInstance())
getClientOldInstance().onClientTick(event);
else {
EntityPlayer player = PneumaticCraft.proxy.getPlayer();
if (player != null) {
for (ISemiBlock semiBlock : addingBlocks) {
Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
}
addingBlocks.clear();
Iterator<Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>>> iterator = semiBlocks.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>> entry = iterator.next();
if (PneumaticCraftUtils.distBetween(player.posX, 0, player.posZ, entry.getKey().xPosition * 16 - 8, 0, entry.getKey().zPosition * 16 - 8) > SYNC_DISTANCE + 10) {
iterator.remove();
} else {
for (ISemiBlock semiBlock : entry.getValue().values()) {
if (!semiBlock.isInvalid())
semiBlock.update();
}
Iterator<ISemiBlock> it = entry.getValue().values().iterator();
while (it.hasNext()) {
if (it.next().isInvalid()) {
it.remove();
}
}
}
}
} else {
semiBlocks.clear();
}
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onInteraction.
@SubscribeEvent
public void onInteraction(PlayerInteractEvent event) {
if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
ItemStack curItem = event.entityPlayer.getCurrentEquippedItem();
if (curItem != null && curItem.getItem() instanceof ISemiBlockItem) {
if (getSemiBlock(event.world, event.x, event.y, event.z) != null) {
if (event.entityPlayer.capabilities.isCreativeMode) {
setSemiBlock(event.world, event.x, event.y, event.z, null);
} else {
breakSemiBlock(event.world, event.x, event.y, event.z, event.entityPlayer);
}
event.setCanceled(true);
} else {
ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.world, event.x, event.y, event.z, curItem);
newBlock.initialize(event.world, new ChunkPosition(event.x, event.y, event.z));
if (newBlock.canPlace()) {
setSemiBlock(event.world, event.x, event.y, event.z, newBlock);
newBlock.onPlaced(event.entityPlayer, curItem);
event.world.playSoundEffect(event.x + 0.5, event.y + 0.5, event.z + 0.5, Block.soundTypeGlass.func_150496_b(), (Block.soundTypeGlass.getVolume() + 1.0F) / 2.0F, Block.soundTypeGlass.getPitch() * 0.8F);
if (!event.entityPlayer.capabilities.isCreativeMode) {
curItem.stackSize--;
if (curItem.stackSize <= 0)
event.entityPlayer.setCurrentItemOrArmor(0, null);
}
event.setCanceled(true);
}
}
}
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ProgWidgetItemInventoryCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv != null) {
int count = 0;
Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
for (Integer i : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && widget.isItemValidForFilters(stack)) {
count += stack.stackSize;
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
}
return false;
}
};
}
Aggregations