下面列出了怎么用net.minecraft.util.ChunkCoordinates的API类实例代码及写法,或者点击链接到github查看源代码。
private int updateTargetPosition(ChunkCoordinates target) {
int x = target.posX;
int y = target.posY;
int z = target.posZ;
if (!this.worldObj.getChunkFromBlockCoords(x, z).isEmpty()) {
if (this.worldObj.getBlock(x, y, z).getBlocksMovement(this.worldObj, x, y, z)) {
while (y > 0 && this.worldObj.getBlock(x, --y, z).getBlocksMovement(this.worldObj, x, y, z))
;
if (y == 0) y = target.posY;
else ++y;
} else {
while (y < 256 && !this.worldObj.getBlock(x, ++y, z).getBlocksMovement(this.worldObj, x, y, z))
;
if (y == 256) y = target.posY;
}
return y;
}
return target.posY;
}
public static WorldView createWorldView(int dimid, ChunkCoordinates spawn, int width, int height) {
if (ModConfigs.disabled) return null;
if (!DimensionManager.isDimensionRegistered(dimid)) return null;
WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimid);
if (proxyworld == null) return null;
Collection<WorldView> worldviews = worldviewsets.get(dimid);
if (worldviews == null) return null;
WorldView view = new WorldView(proxyworld, spawn, width, height);
// Initialize the view rendering system
Minecraft mc = Minecraft.getMinecraft();
EntityLivingBase backup = mc.renderViewEntity;
mc.renderViewEntity = view.camera;
view.getRenderGlobal().setWorldAndLoadRenderers(proxyworld);
mc.renderViewEntity = backup;
// Inform the server of the new view
LookingGlassPacketManager.bus.sendToServer(PacketCreateView.createPacket(view));
worldviews.add(view);
return view;
}
private void renderBlackHoleEffect(double x, double y, double z, TileEssentiaCompressor te) {
ChunkCoordinates cc = new ChunkCoordinates((int) x, (int) y, (int) z);
FXVortex v;
if (ownedVortex.containsKey(cc)) {
v = ownedVortex.get(cc);
} else {
v = new FXVortex(x, y, z, te);
ownedVortex.put(cc, v);
v.registered = true;
EffectHandler.getInstance().registerVortex(v);
}
if(!v.registered) {
EffectHandler.getInstance().registerVortex(v);
}
v.notify(System.currentTimeMillis());
}
@Override
public void updateEntity() {
if(worldObj == null) return;
ticksExisted++;
if(!worldObj.isRemote) {
ChunkCoordinates cc = getCoords();
if (!trackedEntities.containsKey(cc)) trackedEntities.put(cc, Lists.<AffectedEntity>newLinkedList());
if ((ticksExisted & 15) == 0) {
killAI();
}
if (((ticksExisted & 7) == 0)) {
handleIO();
}
if (((ticksExisted & 31) == 0)) {
drainDefaultEssentia();
}
}
}
public static void removeTrackedEntities(World world, int x, int y, int z) {
ChunkCoordinates cc = new ChunkCoordinates(x, y, z);
if(trackedEntities.containsKey(cc)) {
for (AffectedEntity ae : trackedEntities.get(cc)) {
for (Object objE : world.getLoadedEntityList()) {
if(objE != null && objE instanceof EntityLiving &&
!((EntityLiving) objE).isDead &&
((EntityLiving) objE).getUniqueID().equals(ae.eUUID)) {
((EntityLiving) objE).tasks.taskEntries = ae.tasks;
((EntityLiving) objE).targetTasks.taskEntries = ae.targetTasks;
injEntityLivingBase.setObject(objE);
injEntityLivingBase.setField("ignoreCollisions", false);
injEntityLivingBase.setObject(null);
}
}
}
trackedEntities.remove(new ChunkCoordinates(x, y, z));
}
}
@Override
public void readEntityFromNBT(NBTTagCompound com) {
super.readEntityFromNBT(com);
this.fixPosX = com.getFloat("fX");
this.fixPosY = com.getFloat("fY");
this.fixPosZ = com.getFloat("fZ");
this.masterX = com.getInteger("mX");
this.masterY = com.getInteger("mY");
this.masterZ = com.getInteger("mZ");
getDataWatcher().updateObject(ModConfig.entityNoClipItemDatawatcherMasterId, new ChunkCoordinates(masterX, masterY, masterZ));
ChunkCoordinates cc = new ChunkCoordinates(Float.floatToIntBits(fixPosX), Float.floatToIntBits(fixPosY), Float.floatToIntBits(fixPosZ));
getDataWatcher().updateObject(ModConfig.entityNoClipItemDatawatcherFixedId, cc);
}
@Override
public void readEntityFromNBT(NBTTagCompound compound) {
super.readEntityFromNBT(compound);
this.internalAuraList = new PrimalAspectList();
ticksExisted = compound.getInteger("ticksExisted");
NBTTagList list = compound.getTagList("auraList", compound.getId());
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound cmp = list.getCompoundTagAt(i);
if(cmp.hasKey("tag") && cmp.hasKey("amt")) {
internalAuraList.add(Aspect.getAspect(cmp.getString("tag")), cmp.getInteger("amt"));
}
}
if(compound.hasKey("activationVecX") && compound.hasKey("activationVecY") && compound.hasKey("activationVecZ")) {
int x = compound.getInteger("activationVecX");
int y = compound.getInteger("activationVecY");
int z = compound.getInteger("activationVecZ");
activationLocation = new ChunkCoordinates(x, y, z);
}
sendAspectData(electParliament());
initGathering();
blockCount = compound.getInteger("blockCount");
}
private static void doBlockEffects(AuraEffect effect, World worldObj, double x, double y, double z) {
int count = effect.getBlockCount(worldObj.rand);
ChunkCoordinates origin = new ChunkCoordinates((int) x, (int) y, (int) z);
List<ChunkCoordinates> foundBlocks = new ArrayList<ChunkCoordinates>();
int intRange = (int) effect.getRange();
for (int i = 0; i < count; i++) {
int xx = worldObj.rand.nextInt(intRange) - worldObj.rand.nextInt(intRange);
int yy = worldObj.rand.nextInt(intRange) - worldObj.rand.nextInt(intRange);
int zz = worldObj.rand.nextInt(intRange) - worldObj.rand.nextInt(intRange);
ChunkCoordinates blockCC = new ChunkCoordinates((int) x + xx, (int) y + yy, (int) z + zz);
if(foundBlocks.contains(blockCC)) {
count++;
} else {
foundBlocks.add(blockCC);
effect.doBlockEffect(origin, blockCC, worldObj);
}
}
}
@Override
public void doBlockEffect(ChunkCoordinates originTile, ChunkCoordinates selectedBlock, World world) {
Class animalClass = animalClasses[world.rand.nextInt(animalClasses.length)];
EntityLivingBase animal;
try {
animal = (EntityLivingBase) animalClass.getConstructor(World.class).newInstance(world);
} catch (Exception e) {
return;
}
boolean canSpawn = setAndCheckPosition(animal, selectedBlock, world, true);
if(canSpawn) {
ChunkCoordinates pos = new ChunkCoordinates((int) animal.posX, (int) animal.posY, (int) animal.posZ);
pos = iterateDown(pos, world);
animal.setPosition(pos.posX + 0.5, pos.posY, pos.posZ + 0.5);
world.spawnEntityInWorld(animal);
}
}
public void updateWorldSpawn(ChunkCoordinates cc) {
if (defaultSpawn) {
int y = updateTargetPosition(cc);
target = new ChunkCoordinates(cc.posX, y, cc.posZ);
this.setPositionAndUpdate(target.posX, target.posY, target.posZ);
if (animator != null) animator.setTarget(cc);
this.refreshAnimator();
}
}
/**
* Adds a single component to the location cache
*/
private void addComponentToLocationCache(MultiblockComponent comp) {
ChunkCoordinates pos = comp.getRelativePosition();
locationCache.put(Arrays.asList(
pos.posX,
pos.posY,
pos.posZ
), comp);
}
@Override
public void handle(ByteBuf data, EntityPlayer player) {
if (ModConfigs.disabled) return;
int dim = data.readInt();
int xPos = data.readInt();
int yPos = data.readInt();
int zPos = data.readInt();
byte renderDistance = data.readByte();
if (!DimensionManager.isDimensionRegistered(dim)) return;
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
if (world == null) return;
int x;
int y;
int z;
if (yPos < 0) {
ChunkCoordinates c = world.getSpawnPoint();
x = c.posX >> 4;
y = c.posY >> 4;
z = c.posZ >> 4;
} else {
x = xPos;
y = yPos;
z = zPos;
}
if (renderDistance > ModConfigs.renderDistance) renderDistance = ModConfigs.renderDistance;
ChunkFinderManager.instance.addFinder(new ChunkFinder(new ChunkCoordinates(x, y, z), dim, world.getChunkProvider(), player, renderDistance));
//TODO: Add to tracking list. Send time/data updates at intervals. Keep in mind to catch player disconnects when tracking clients.
//Register ChunkFinder, and support change of finder location.
//TODO: This is a repeat of the handling of PacketRequestWorldInfo
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ClientWorldInfoEvent(dim, (EntityPlayerMP) player));
LookingGlassPacketManager.bus.sendTo(PacketWorldInfo.createPacket(dim), (EntityPlayerMP) player);
}
public static FMLProxyPacket createPacket(int dimension) {
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
if (world == null) {
LoggerUtils.warn("Server-side world for dimension %i is null!", dimension);
return null;
}
ChunkCoordinates cc = world.provider.getSpawnPoint();
int posX = cc.posX;
int posY = cc.posY;
int posZ = cc.posZ;
int skylightSubtracted = world.skylightSubtracted;
float thunderingStrength = world.thunderingStrength;
float rainingStrength = world.rainingStrength;
long worldTime = world.provider.getWorldTime();
// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());
data.writeInt(dimension);
data.writeInt(posX);
data.writeInt(posY);
data.writeInt(posZ);
data.writeInt(skylightSubtracted);
data.writeFloat(thunderingStrength);
data.writeFloat(rainingStrength);
data.writeLong(worldTime);
return buildPacket(data);
}
@Override
public Object getMeta(IItemPortalActivator target, ItemStack stack) {
final ILinkInfo linkInfo = getLinkInfo(stack);
if (linkInfo == null) return null;
final String unlocalizedName = stack.getUnlocalizedName();
final boolean isLinkbook = "item.myst.linkbook".equals(unlocalizedName);
final boolean isAgebook = "item.myst.agebook".equals(unlocalizedName);
Map<String, Object> result = Maps.newHashMap();
result.put("type", isLinkbook? "link" : (isAgebook? "age" : "unknown"));
result.put("destination", linkInfo.getDisplayName());
result.put("dimension", linkInfo.getDimensionUID());
final LinkPropertyAPI linkPropertiesApi = MystcraftAccess.linkPropertiesApi;
if (linkPropertiesApi != null) {
final Collection<String> allProperties = linkPropertiesApi.getLinkProperties();
Set<String> flags = Sets.newHashSet();
for (String flag : allProperties)
if (linkInfo.getFlag(flag)) flags.add(flag);
result.put("flags", flags);
}
{
ChunkCoordinates coords = linkInfo.getSpawn();
if (coords != null) result.put("spawn", Lists.newArrayList(coords.posX, coords.posY, coords.posZ));
}
result.put("spawnYaw", linkInfo.getSpawnYaw());
return result;
}
public WorldView(WorldClient worldObj, ChunkCoordinates coords, int width, int height) {
this.width = width;
this.height = height;
this.worldObj = worldObj;
this.coords = coords;
this.camera = new EntityCamera(worldObj, coords);
this.camerawrapper = new ViewCameraImpl(camera);
this.renderGlobal = new RenderGlobal(Minecraft.getMinecraft());
this.effectRenderer = new EffectRenderer(worldObj, Minecraft.getMinecraft().getTextureManager());
// Technically speaking, this is poor practice as it leaks a reference to the view before it's done constructing.
this.fbo = FrameBufferContainer.createNewFramebuffer(this, width, height);
}
/**
* Returns the given ICommandSender as a EntityPlayer or throw an exception.
*/
public static TileEntity getCommandSenderAsTileEntity(ICommandSender sender) {
try {
World world = sender.getEntityWorld();
ChunkCoordinates coords = sender.getPlayerCoordinates();
return world.getTileEntity(coords.posX, coords.posY, coords.posZ);
} catch (Exception e) {
throw new CommandException("Could not get tile entity");
}
}
@Override
public void readFromPacketNBT(NBTTagCompound cmp) {
mana = cmp.getInteger(TAG_MANA);
int x = cmp.getInteger(TAG_POOL_X);
int y = cmp.getInteger(TAG_POOL_Y);
int z = cmp.getInteger(TAG_POOL_Z);
cachedPoolCoordinates = y < 0 ? null : new ChunkCoordinates(x, y, z);
}
@Override
public TileEntity getTileEntity(int x, int y, int z) {
TileEntity te = getBlock(x, y, z).createTileEntity(null, getBlockMetadata(x, y, z));
if(te == null) return null;
ChunkCoordinates cc = new ChunkCoordinates(x, y, z);
if(!gettedTE.containsKey(cc)) gettedTE.put(cc, te);
te.setWorldObj(this);
te.xCoord = x;
te.yCoord = y;
te.zCoord = z;
return te;
}
public static List<ChunkCoordinates> getCoordinatesAround(ChunkCoordinates center) {
List<ChunkCoordinates> coords = new ArrayList<ChunkCoordinates>();
coords.add(new ChunkCoordinates(center.posX, center.posY, center.posZ));
coords.add(new ChunkCoordinates(center.posX + 1, center.posY, center.posZ));
coords.add(new ChunkCoordinates(center.posX, center.posY, center.posZ + 1));
coords.add(new ChunkCoordinates(center.posX - 1, center.posY, center.posZ));
coords.add(new ChunkCoordinates(center.posX, center.posY, center.posZ - 1));
coords.add(new ChunkCoordinates(center.posX, center.posY - 1, center.posZ));
coords.add(new ChunkCoordinates(center.posX, center.posY + 1, center.posZ));
return coords;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int these, float are, float some, float variables) { //LUL side, hitx, hity, hitz
if(world.isRemote) return false;
TileEntity te = world.getTileEntity(x, y, z);
if(te == null || !(te instanceof TileEssentiaCompressor)) return false;
if(((TileEssentiaCompressor) te).isMultiblockFormed()) {
if(!((TileEssentiaCompressor) te).isMasterTile()) {
int yOffset = ((TileEssentiaCompressor) te).getMultiblockYIndex();
return RegisteredBlocks.blockEssentiaCompressor.onBlockActivated(world, x, y - yOffset, z, player, these, are, some, variables);
}
} else {
ItemStack heldItem = player.getHeldItem();
if(heldItem != null && heldItem.getItem() instanceof ItemWandCasting &&
ResearchManager.isResearchComplete(player.getCommandSenderName(), SimpleResearchItem.getFullName("ESSENTIA_COMPRESSOR"))) {
ChunkCoordinates lowest = findLowestCompressorBlock(world, x, y, z);
boolean canForm = lowest != null && isMuliblockPossible(world, lowest);
if(canForm && ThaumcraftApiHelper.consumeVisFromWandCrafting(player.getCurrentEquippedItem(), player, RegisteredRecipes.costsCompressorMultiblock, true)) {
int multiblockID = TileEssentiaCompressor.getAndIncrementNewMultiblockId();
TileEssentiaCompressor compressor = (TileEssentiaCompressor) world.getTileEntity(lowest.posX, lowest.posY, lowest.posZ);
compressor.setInMultiblock(true, 0, multiblockID);
PacketStartAnimation pkt = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, lowest.posX, lowest.posY, lowest.posZ);
NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, lowest.posX, lowest.posY, lowest.posZ, 32);
PacketHandler.INSTANCE.sendToAllAround(pkt, point);
compressor = (TileEssentiaCompressor) world.getTileEntity(lowest.posX, lowest.posY + 1, lowest.posZ);
compressor.setInMultiblock(false, 1, multiblockID);
pkt = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, lowest.posX, lowest.posY + 1, lowest.posZ);
point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, lowest.posX, lowest.posY + 1, lowest.posZ, 32);
PacketHandler.INSTANCE.sendToAllAround(pkt, point);
compressor = (TileEssentiaCompressor) world.getTileEntity(lowest.posX, lowest.posY + 2, lowest.posZ);
compressor.setInMultiblock(false, 2, multiblockID);
pkt = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, lowest.posX, lowest.posY + 2, lowest.posZ);
point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, lowest.posX, lowest.posY + 2, lowest.posZ, 32);
PacketHandler.INSTANCE.sendToAllAround(pkt, point);
}
}
}
return false;
}
private void consumeEldritchEyes() {
for (ChunkCoordinates cc : bufferedCCPedestals) {
try {
TilePedestal pedestal = (TilePedestal) worldObj.getTileEntity(cc.posX, cc.posY, cc.posZ);
pedestal.setInventorySlotContents(0, null);
PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_SPARKLE_SPREAD, cc.posX, cc.posY, cc.posZ);
PacketHandler.INSTANCE.sendToAllAround(packet, getTargetPoint(32));
} catch (Exception exc) {}
}
}
private Vec3 getRelPedestalLoc(int pedestalId) {
try {
ChunkCoordinates cc = bufferedCCPedestals.get(pedestalId);
return Vec3.createVectorHelper(xCoord - cc.posX, yCoord - cc.posY, zCoord - cc.posZ);
} catch (Exception exc) {}
return Vec3.createVectorHelper(0, 0, 0);
}
public static void informSessionStart(EntityPlayer player) {
if(trackedPortalActivity.containsKey(player)) {
ExtendedChunkCoordinates tileCoords = trackedPortalActivity.get(player);
trackedPortalActivity.remove(player);
if(tileCoords != null) {
ChunkCoordinates cc = tileCoords.coordinates;
WorldServer ws = MinecraftServer.getServer().worldServerForDimension(tileCoords.dimId);
ws.removeTileEntity(cc.posX, cc.posY, cc.posZ);
ws.setBlockToAir(cc.posX, cc.posY, cc.posZ);
ws.markBlockForUpdate(cc.posX, cc.posY, cc.posZ);
}
}
}
private void killAI() {
ChunkCoordinates cc = getCoords();
List objEntityList = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, BOX.copy().offset(xCoord, yCoord, zCoord));
for (Object o : objEntityList) {
if(o != null && o instanceof EntityLiving &&
!((EntityLiving) o).isDead && canAffect((EntityLiving) o)) {
EntityLiving el = (EntityLiving) o;
if(storedAmount <= 0) return;
AffectedEntity affected = removeAI(el);
trackedEntities.get(cc).add(affected);
}
}
}
public boolean canAffect(EntityLiving el) {
ChunkCoordinates cc = getCoords();
if(!trackedEntities.containsKey(cc)) return false;
UUID uu = el.getUniqueID();
for (AffectedEntity ae : trackedEntities.get(cc)) {
if(ae.eUUID.equals(uu)) return false;
}
return true;
}
private static ChunkCoordinates iterateDown(ChunkCoordinates pos, World world) {
while(world.isAirBlock(pos.posX, pos.posY, pos.posZ)) {
pos.posY -= 1;
}
pos.posY += 1;
return pos;
}
@Override
public void doEntityEffect(ChunkCoordinates originTile, Entity e) {
if (e == null || !(e instanceof EntityLivingBase)) return;
EntityLivingBase living = (EntityLivingBase) e;
addOrExtendPotionEffect(potion, living, durationCap, addedDuration, amplifier);
}
@Override
public void doEntityEffect(ChunkCoordinates originTile, Entity e) {
if(e.worldObj.rand.nextInt(4) == 0) {
EntityMob mob = (EntityMob) e;
PotionEffect effect = mob.getActivePotionEffect(RegisteredPotions.ELDRITCH);
if(effect != null && effect.getAmplifier() > 4) {
EntityUtils.makeChampion(mob, false);
mob.removePotionEffect(RegisteredPotions.ELDRITCH.getId());
} else {
mob.addPotionEffect(new PotionEffect(RegisteredPotions.ELDRITCH.getId(), MiscUtils.ticksForMinutes(1), effect == null ? 1 : effect.getAmplifier() + 1));
}
}
}
@Override
public void readSpawnData(ByteBuf buffer) {
ticksExisted = buffer.readInt();
activationLocation = new ChunkCoordinates();
activationLocation.posX = buffer.readInt();
activationLocation.posY = buffer.readInt();
activationLocation.posZ = buffer.readInt();
}
@SubscribeEvent
public void on(LivingSpawnEvent.CheckSpawn event) {
if(event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) {
double rangeSq = AuraEffects.LUX.getRange() * AuraEffects.LUX.getRange();
Vector3 entityPos = MiscUtils.getPositionVector(event.entity);
for(ChunkCoordinates luxPylons : registeredLuxPylons) {
Vector3 pylon = Vector3.fromCC(luxPylons);
if(entityPos.distanceSquared(pylon) <= rangeSq) {
event.setResult(Event.Result.DENY);
return;
}
}
}
}