Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package railcraft.common.blocks.machine.alpha;
- import aaj;
- import amj;
- import anq;
- import bq;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- import java.util.Set;
- import lq;
- import net.minecraftforge.common.ForgeChunkManager;
- import net.minecraftforge.common.ForgeChunkManager.Ticket;
- import net.minecraftforge.common.ForgeChunkManager.Type;
- import qx;
- import railcraft.client.core.KeyHandler;
- import railcraft.common.api.core.WorldCoordinate;
- import railcraft.common.api.core.items.ICrowbar;
- import railcraft.common.blocks.machine.IEnumMachine;
- import railcraft.common.blocks.machine.TileMachineBase;
- import railcraft.common.blocks.machine.beta.EnumMachineBeta;
- import railcraft.common.blocks.machine.beta.TileSentinel;
- import railcraft.common.core.Railcraft;
- import railcraft.common.core.RailcraftConfig;
- import railcraft.common.lang.RailcraftLanguage;
- import railcraft.common.util.effects.EffectManager;
- import railcraft.common.util.misc.ChunkManager;
- import railcraft.common.util.misc.Game;
- import railcraft.common.util.misc.MiscTools;
- import um;
- import xo;
- import xv;
- public class TileWorldAnchor extends TileMachineBase
- {
- public static final Map pairingMap = Collections.synchronizedMap(new HashMap());
- private static final int SENTINEL_CHECK = 128;
- private static final byte MAX_SENTINEL_CHUNKS = 9;
- private static final byte ANCHOR_RADIUS = 1;
- private int xSentinel = -1;
- private int ySentinel = -1;
- private int zSentinel = -1;
- private ForgeChunkManager.Ticket ticket;
- private int update = MiscTools.getRand().nextInt();
- private Set chunks;
- public IEnumMachine getMachineType()
- {
- return EnumMachineAlpha.WORLD_ANCHOR;
- }
- public int getBlockTexture(int side)
- {
- return getMachineType().getTexture(side);
- }
- public boolean blockActivated(qx player, int side)
- {
- um current = player.bT();
- if ((current != null) && ((current.b() instanceof ICrowbar))) {
- WorldCoordinate sentinel = (WorldCoordinate)pairingMap.get(player);
- if (sentinel != null) {
- if (this.k.v.h == sentinel.dimension) {
- setSentinel(player, sentinel.x, sentinel.y, sentinel.z);
- }
- return true;
- }
- }
- return super.blockActivated(player, side);
- }
- public int getMaxSentinelChunks() {
- if (this.ticket == null) {
- return 9;
- }
- return Math.min(this.ticket.getMaxChunkListDepth(), 9);
- }
- public void setSentinel(qx player, int x, int y, int z) {
- anq tile = this.k.q(x, y, z);
- if ((tile instanceof TileSentinel)) {
- int xChunk = this.l >> 4;
- int zChunk = this.n >> 4;
- int xSentinelChunk = tile.l >> 4;
- int zSentinelChunk = tile.n >> 4;
- if ((xChunk != xSentinelChunk) && (zChunk != zSentinelChunk)) {
- if (Game.isNotHost(this.k)) {
- player.b(b() + " " + RailcraftLanguage.translate("gui.anchor.pair.fail.alignment") + " " + RailcraftLanguage.translate(EnumMachineBeta.SENTINEL.getTag()));
- }
- return;
- }
- int max = getMaxSentinelChunks();
- if ((Math.abs(xChunk - xSentinelChunk) > max) || (Math.abs(zChunk - zSentinelChunk) > max)) {
- if (Game.isNotHost(this.k)) {
- player.b(b() + " " + RailcraftLanguage.translate("gui.anchor.pair.fail.distance") + " " + RailcraftLanguage.translate(EnumMachineBeta.SENTINEL.getTag()));
- }
- return;
- }
- this.xSentinel = tile.l;
- this.ySentinel = tile.m;
- this.zSentinel = tile.n;
- if (Game.isHost(this.k)) {
- releaseTicket();
- requestTicket();
- markBlockForUpdate();
- } else {
- player.b(b() + " " + RailcraftLanguage.translate("gui.anchor.pair.success"));
- }
- }
- }
- public void clearSentinel() {
- if (!hasSentinel()) {
- return;
- }
- this.xSentinel = -1;
- this.ySentinel = -1;
- this.zSentinel = -1;
- releaseTicket();
- requestTicket();
- markBlockForUpdate();
- }
- public boolean hasSentinel() {
- return this.ySentinel != -1;
- }
- public void g()
- {
- super.g();
- if (Game.isNotHost(this.k)) {
- if ((this.chunks != null) && (KeyHandler.isChunkAuraEnabled())) {
- EffectManager.chunkLoaderEffect(this.k, this, this.chunks);
- }
- return;
- }
- if (RailcraftConfig.deleteAnchors()) {
- releaseTicket();
- this.k.e(this.l, this.m, this.n, amj.as.cm);
- return;
- }
- this.update += 1;
- if ((this.update % 128 == 0) && (hasSentinel())) {
- anq tile = this.k.q(this.xSentinel, this.ySentinel, this.zSentinel);
- if (!(tile instanceof TileSentinel)) {
- clearSentinel();
- }
- }
- if ((this.ticket == null) && (ForgeChunkManager.ticketCountAvailableFor(Railcraft.getMod(), this.k) > 0))
- requestTicket();
- }
- public void onBlockAdded()
- {
- requestTicket();
- }
- public void onBlockRemoval()
- {
- releaseTicket();
- }
- private void releaseTicket() {
- ForgeChunkManager.releaseTicket(this.ticket);
- }
- private void requestTicket() {
- ForgeChunkManager.Ticket chunkTicket = ForgeChunkManager.requestTicket(Railcraft.getMod(), this.k, ForgeChunkManager.Type.NORMAL);
- if (chunkTicket != null) {
- chunkTicket.getModData().a("xCoord", this.l);
- chunkTicket.getModData().a("yCoord", this.m);
- chunkTicket.getModData().a("zCoord", this.n);
- forceChunkLoading(chunkTicket);
- }
- }
- public void forceChunkLoading(ForgeChunkManager.Ticket ticket) {
- if (this.ticket == null) {
- this.ticket = ticket;
- }
- setupChunks();
- for (xo chunk : this.chunks)
- ForgeChunkManager.forceChunk(ticket, chunk);
- }
- public void setupChunks()
- {
- if (hasSentinel())
- this.chunks = ChunkManager.getInstance().getChunksBetween(this.l >> 4, this.n >> 4, this.xSentinel >> 4, this.zSentinel >> 4, getMaxSentinelChunks());
- else
- this.chunks = ChunkManager.getInstance().getChunksAround(this.l >> 4, this.n >> 4, 1);
- }
- public void writePacketData(DataOutputStream data)
- throws IOException
- {
- super.writePacketData(data);
- data.writeInt(this.xSentinel);
- data.writeInt(this.ySentinel);
- data.writeInt(this.zSentinel);
- }
- public void readPacketData(DataInputStream data) throws IOException
- {
- super.readPacketData(data);
- this.xSentinel = data.readInt();
- this.ySentinel = data.readInt();
- this.zSentinel = data.readInt();
- setupChunks();
- }
- public void b(bq data)
- {
- super.b(data);
- data.a("xSentinel", this.xSentinel);
- data.a("ySentinel", this.ySentinel);
- data.a("zSentinel", this.zSentinel);
- }
- public void a(bq data)
- {
- super.a(data);
- this.xSentinel = data.e("xSentinel");
- this.ySentinel = data.e("ySentinel");
- this.zSentinel = data.e("zSentinel");
- }
- public float getResistance(lq exploder)
- {
- return 60.0F;
- }
- public float getHardness()
- {
- return 20.0F;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement