use of net.minecraft.world.ChunkCache in project PneumaticCraft by MineMaarten.
the class BlockTrackUpgradeHandler method update.
@Override
public void update(EntityPlayer player, int rangeUpgrades) {
ticksExisted++;
SearchUpgradeHandler searchHandler = HUDHandler.instance().getSpecificRenderer(SearchUpgradeHandler.class);
if (ticksExisted % updateInterval == 0) {
int timeTaken = (int) accTime / updateInterval;
updateInterval = updateInterval * timeTaken / MAX_TIME;
if (updateInterval <= 1)
updateInterval = 2;
accTime = 0;
ticksExisted = 0;
}
accTime -= System.currentTimeMillis();
int blockTrackRange = BLOCK_TRACKING_RANGE + Math.min(rangeUpgrades, 5) * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
int baseX = (int) Math.floor(player.posX) - blockTrackRange;
int baseY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval) / (updateInterval / 2);
int maxY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval + 1) / (updateInterval / 2);
baseY = MathHelper.clamp_int(baseY, 0, 255);
maxY = MathHelper.clamp_int(maxY, 0, 255);
int baseZ = (int) Math.floor(player.posZ) - blockTrackRange;
IBlockAccess chunkCache = new ChunkCache(player.worldObj, baseX, baseY, baseZ, baseX + 2 * blockTrackRange, maxY, baseZ + 2 * blockTrackRange, 0);
for (int i = baseX; i <= baseX + 2 * blockTrackRange; i++) {
for (int j = baseY; j < maxY; j++) {
for (int k = baseZ; k <= baseZ + 2 * blockTrackRange; k++) {
if (player.getDistance(i, j, k) > blockTrackRange)
continue;
TileEntity te = chunkCache.getTileEntity(i, j, k);
if (MinecraftForge.EVENT_BUS.post(new BlockTrackEvent(player.worldObj, i, j, k, te)))
continue;
if (searchHandler != null && te instanceof IInventory) {
searchHandler.checkInventoryForItems(te);
}
List<IBlockTrackEntry> entries = BlockTrackEntryList.instance.getEntriesForCoordinate(chunkCache, i, j, k, te);
if (entries.isEmpty())
continue;
boolean inList = false;
for (int l = 0; l < blockTargets.size(); l++) {
if (blockTargets.get(l).isSameTarget(player.worldObj, i, j, k)) {
inList = true;
// cancel lost targets
blockTargets.get(l).ticksExisted = Math.abs(blockTargets.get(l).ticksExisted);
blockTargets.get(l).setTileEntity(te);
break;
}
}
if (!inList) {
boolean sentUpdate = false;
for (IBlockTrackEntry entry : entries) {
if (entry.shouldBeUpdatedFromServer(te)) {
if (!sentUpdate) {
NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(i, j, k));
sentUpdate = true;
}
}
}
addBlockTarget(new RenderBlockTarget(player.worldObj, player, i, j, k, te, this));
for (IBlockTrackEntry entry : entries) {
if (countBlockTrackersOfType(entry) == entry.spamThreshold() + 1) {
HUDHandler.instance().addMessage(new ArmorMessage(I18n.format("blockTracker.message.stopSpam", I18n.format(entry.getEntryName())), new ArrayList<String>(), 60, 0x7700AA00));
}
}
}
}
}
}
accTime += System.currentTimeMillis();
for (int i = 0; i < blockTargets.size(); i++) {
RenderBlockTarget blockTarget = blockTargets.get(i);
boolean wasNegative = blockTarget.ticksExisted < 0;
blockTarget.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
if (blockTarget.ticksExisted >= 0 && wasNegative)
blockTarget.ticksExisted = -1;
blockTarget.update();
if (blockTarget.getDistanceToEntity(player) > blockTrackRange + 5 || !blockTarget.isTargetStillValid()) {
if (blockTarget.ticksExisted > 0) {
blockTarget.ticksExisted = -60;
} else if (blockTarget.ticksExisted == -1) {
removeBlockTarget(i);
i--;
}
}
}
List<String> textList = new ArrayList<String>();
RenderBlockTarget focusedTarget = null;
for (RenderBlockTarget blockTarget : blockTargets) {
if (blockTarget.isInitialized() && blockTarget.isPlayerLooking()) {
focusedTarget = blockTarget;
break;
}
}
if (focusedTarget != null) {
blockTrackInfo.setTitle(focusedTarget.stat.getTitle());
textList.addAll(focusedTarget.textList);
} else {
blockTrackInfo.setTitle("Current tracked blocks:");
if (blockTypeCount == null || ticksExisted % 40 == 0) {
blockTypeCount = new int[BlockTrackEntryList.instance.trackList.size()];
for (RenderBlockTarget target : blockTargets) {
for (IBlockTrackEntry validEntry : target.getApplicableEntries()) {
blockTypeCount[BlockTrackEntryList.instance.trackList.indexOf(validEntry)]++;
}
}
}
for (int i = 0; i < blockTypeCount.length; i++) {
if (blockTypeCount[i] > 0) {
textList.add(blockTypeCount[i] + " " + I18n.format(BlockTrackEntryList.instance.trackList.get(i).getEntryName()));
}
}
if (textList.size() == 0)
textList.add("Tracking no blocks currently.");
}
blockTrackInfo.setText(textList);
}
use of net.minecraft.world.ChunkCache in project PneumaticCraft by MineMaarten.
the class EntityPathNavigateDrone method getEntityPathToXYZ.
public PathEntity getEntityPathToXYZ(EntityDrone par1Entity, int par2, int par3, int par4, float par5, boolean par6, boolean par7, boolean par8, boolean par9) {
if (!par1Entity.isBlockValidPathfindBlock(par2, par3, par4))
return null;
PathEntity pathentity = null;
int l = MathHelper.floor_double(par1Entity.posX);
int i1 = MathHelper.floor_double(par1Entity.posY);
int j1 = MathHelper.floor_double(par1Entity.posZ);
if (!forceTeleport || l == par2 && i1 == par3 && j1 == par4) {
int k1 = (int) (par5 + 8.0F);
int l1 = l - k1;
int i2 = i1 - k1;
int j2 = j1 - k1;
int k2 = l + k1;
int l2 = i1 + k1;
int i3 = j1 + k1;
ChunkCache chunkcache = new ChunkCache(par1Entity.worldObj, l1, i2, j2, k2, l2, i3, 0);
pathentity = new PathFinderDrone(par1Entity, chunkcache, par6, par7, pathThroughLiquid, par9).createEntityPathTo(par1Entity, par2, par3, par4, par5);
if (pathentity != null) {
PathPoint finalPoint = pathentity.getFinalPathPoint();
if (finalPoint == null || finalPoint.xCoord != par2 || finalPoint.yCoord != par3 || finalPoint.zCoord != par4)
pathentity = null;
}
}
teleportCounter = pathentity != null ? -1 : 0;
telX = par2;
telY = par3;
telZ = par4;
par1Entity.setStandby(false);
return pathentity;
}
use of net.minecraft.world.ChunkCache in project ImmersiveEngineering by BluSunrize.
the class SmartLightingQuad method pipe.
@Override
public void pipe(IVertexConsumer consumer) {
IBlockAccess world = null;
BlockInfo info = null;
if (consumer instanceof VertexLighterFlat) {
try {
info = (BlockInfo) blockInfo.get(consumer);
world = info.getWorld();
if (world instanceof ChunkCache)
world = ((ChunkCache) world).world;
consumer = (IVertexConsumer) parent.get(consumer);
} catch (Throwable e) {
e.printStackTrace();
}
}
consumer.setQuadOrientation(this.getFace());
if (this.hasTintIndex())
consumer.setQuadTint(this.getTintIndex());
float[] data = new float[4];
VertexFormat format = consumer.getVertexFormat();
int count = format.getElementCount();
int[] eMap = LightUtil.mapFormats(format, DefaultVertexFormats.ITEM);
int itemCount = DefaultVertexFormats.ITEM.getElementCount();
eMap[eMap.length - 1] = 2;
for (int v = 0; v < 4; v++) for (int e = 0; e < count; e++) if (eMap[e] != itemCount) {
if (// lightmap is UV with 2 shorts
format.getElement(e).getUsage() == EnumUsage.UV && format.getElement(e).getType() == EnumType.SHORT) {
int brightness;
if (!ignoreLight && world != null && !(world instanceof ChunkCache)) {
BlockPos here = blockPos.add(relativePos[v][0], relativePos[v][1], relativePos[v][2]);
brightness = world.getCombinedLight(here, 0);
} else
brightness = staticBrightness;
data[0] = ((float) ((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
data[1] = ((float) ((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
} else
LightUtil.unpack(this.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
consumer.put(e, data);
} else
consumer.put(e, 0);
}
use of net.minecraft.world.ChunkCache in project pnc-repressurized by TeamPneumatic.
the class BlockTrackUpgradeHandler method update.
@Override
public void update(EntityPlayer player, int rangeUpgrades) {
ticksExisted++;
SearchUpgradeHandler searchHandler = HUDHandler.instance().getSpecificRenderer(SearchUpgradeHandler.class);
if (ticksExisted % updateInterval == 0) {
int timeTaken = (int) accTime / updateInterval;
updateInterval = updateInterval * timeTaken / MAX_TIME;
if (updateInterval <= 1)
updateInterval = 2;
accTime = 0;
ticksExisted = 0;
}
accTime -= System.currentTimeMillis();
int blockTrackRange = BLOCK_TRACKING_RANGE + Math.min(rangeUpgrades, 5) * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
int baseX = (int) Math.floor(player.posX) - blockTrackRange;
int baseY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval) / (updateInterval / 2);
int maxY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval + 1) / (updateInterval / 2);
baseY = MathHelper.clamp(baseY, 0, 255);
maxY = MathHelper.clamp(maxY, 0, 255);
int baseZ = (int) Math.floor(player.posZ) - blockTrackRange;
IBlockAccess chunkCache = new ChunkCache(player.world, new BlockPos(baseX, baseY, baseZ), new BlockPos(baseX + 2 * blockTrackRange, maxY, baseZ + 2 * blockTrackRange), 0);
for (int i = baseX; i <= baseX + 2 * blockTrackRange; i++) {
for (int j = baseY; j < maxY; j++) {
for (int k = baseZ; k <= baseZ + 2 * blockTrackRange; k++) {
if (player.getDistance(i, j, k) > blockTrackRange)
continue;
BlockPos pos = new BlockPos(i, j, k);
TileEntity te = chunkCache.getTileEntity(pos);
if (MinecraftForge.EVENT_BUS.post(new BlockTrackEvent(player.world, pos, te)))
continue;
if (searchHandler != null && te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
searchHandler.checkInventoryForItems(te);
}
List<IBlockTrackEntry> entries = BlockTrackEntryList.instance.getEntriesForCoordinate(chunkCache, pos, te);
if (entries.isEmpty())
continue;
boolean inList = false;
for (int l = 0; l < blockTargets.size(); l++) {
if (blockTargets.get(l).isSameTarget(player.world, pos)) {
inList = true;
// cancel lost targets
blockTargets.get(l).ticksExisted = Math.abs(blockTargets.get(l).ticksExisted);
blockTargets.get(l).setTileEntity(te);
break;
}
}
if (!inList) {
boolean sentUpdate = false;
for (IBlockTrackEntry entry : entries) {
if (entry.shouldBeUpdatedFromServer(te)) {
if (!sentUpdate) {
NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(pos));
sentUpdate = true;
}
}
}
addBlockTarget(new RenderBlockTarget(player.world, player, pos, te, this));
for (IBlockTrackEntry entry : entries) {
if (countBlockTrackersOfType(entry) == entry.spamThreshold() + 1) {
HUDHandler.instance().addMessage(new ArmorMessage(I18n.format("blockTracker.message.stopSpam", I18n.format(entry.getEntryName())), new ArrayList<String>(), 60, 0x7700AA00));
}
}
}
}
}
}
accTime += System.currentTimeMillis();
for (int i = 0; i < blockTargets.size(); i++) {
RenderBlockTarget blockTarget = blockTargets.get(i);
boolean wasNegative = blockTarget.ticksExisted < 0;
blockTarget.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
if (blockTarget.ticksExisted >= 0 && wasNegative)
blockTarget.ticksExisted = -1;
blockTarget.update();
if (blockTarget.getDistanceToEntity(player) > blockTrackRange + 5 || !blockTarget.isTargetStillValid()) {
if (blockTarget.ticksExisted > 0) {
blockTarget.ticksExisted = -60;
} else if (blockTarget.ticksExisted == -1) {
removeBlockTarget(i);
i--;
}
}
}
List<String> textList = new ArrayList<String>();
RenderBlockTarget focusedTarget = null;
for (RenderBlockTarget blockTarget : blockTargets) {
if (blockTarget.isInitialized() && blockTarget.isPlayerLooking()) {
focusedTarget = blockTarget;
break;
}
}
if (focusedTarget != null) {
blockTrackInfo.setTitle(focusedTarget.stat.getTitle());
textList.addAll(focusedTarget.textList);
} else {
blockTrackInfo.setTitle("Current tracked blocks:");
if (blockTypeCount == null || ticksExisted % 40 == 0) {
blockTypeCount = new int[BlockTrackEntryList.instance.trackList.size()];
for (RenderBlockTarget target : blockTargets) {
for (IBlockTrackEntry validEntry : target.getApplicableEntries()) {
blockTypeCount[BlockTrackEntryList.instance.trackList.indexOf(validEntry)]++;
}
}
}
for (int i = 0; i < blockTypeCount.length; i++) {
if (blockTypeCount[i] > 0) {
textList.add(blockTypeCount[i] + " " + I18n.format(BlockTrackEntryList.instance.trackList.get(i).getEntryName()));
}
}
if (textList.size() == 0)
textList.add("Tracking no blocks currently.");
}
blockTrackInfo.setText(textList);
}
use of net.minecraft.world.ChunkCache in project pnc-repressurized by TeamPneumatic.
the class ProgWidgetAreaItemBase method getCache.
public static IBlockAccess getCache(Collection<BlockPos> area, World world) {
if (area.size() == 0)
return world;
int minX, minY, minZ, maxX, maxY, maxZ;
Iterator<BlockPos> iterator = area.iterator();
BlockPos p = iterator.next();
minX = maxX = p.getX();
minY = maxY = p.getY();
minZ = maxZ = p.getZ();
while (iterator.hasNext()) {
p = iterator.next();
minX = Math.min(minX, p.getX());
minY = Math.min(minY, p.getY());
minZ = Math.min(minZ, p.getZ());
maxX = Math.max(maxX, p.getX());
maxY = Math.max(maxY, p.getY());
maxZ = Math.max(maxZ, p.getZ());
}
return new ChunkCache(world, new BlockPos(minX, minY, minZ), new BlockPos(maxX, maxY, maxZ), 0);
}
Aggregations