Oregen sync fix
This commit is contained in:
parent
5509d94044
commit
457fb3a4ad
2 changed files with 63 additions and 161 deletions
|
@ -1,119 +0,0 @@
|
|||
package gregtech.common.blocks;
|
||||
|
||||
import gregtech.api.enums.GT_Values;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GT_TickHandler_Ores {
|
||||
|
||||
public static HashMap<Integer, HashMap<ChunkCoordIntPair, ArrayList<GT_TileEntity_Ores>>> data = new HashMap<>();
|
||||
|
||||
public GT_TickHandler_Ores() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public static void loadChunkOre(GT_TileEntity_Ores gt_tileEntity_ores) {
|
||||
getChunkData(
|
||||
gt_tileEntity_ores.getWorld().provider.getDimension(),
|
||||
new ChunkCoordIntPair(gt_tileEntity_ores.getPos()))
|
||||
.add(gt_tileEntity_ores);
|
||||
}
|
||||
|
||||
public static void unloadChunkOre(GT_TileEntity_Ores gt_tileEntity_ores) {
|
||||
getChunkData(
|
||||
gt_tileEntity_ores.getWorld().provider.getDimension(),
|
||||
new ChunkCoordIntPair(gt_tileEntity_ores.getPos()))
|
||||
.remove(gt_tileEntity_ores);
|
||||
}
|
||||
|
||||
public static ArrayList<GT_TileEntity_Ores> getChunkData(int dimension, ChunkCoordIntPair chunk) {
|
||||
HashMap<ChunkCoordIntPair, ArrayList<GT_TileEntity_Ores>> dimensionData = data.get(dimension);
|
||||
if(dimensionData == null) {
|
||||
dimensionData = new HashMap<>();
|
||||
data.put(dimension, dimensionData);
|
||||
}
|
||||
ArrayList<GT_TileEntity_Ores> oresData = dimensionData.get(chunk);
|
||||
if(oresData == null) {
|
||||
oresData = new ArrayList<>();
|
||||
dimensionData.put(chunk, oresData);
|
||||
}
|
||||
return oresData;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(TickEvent.PlayerTickEvent player) {
|
||||
/*if(player.side.isServer()) {
|
||||
EntityPlayer entityPlayer = player.player;
|
||||
World world = entityPlayer.worldObj;
|
||||
if (world.getWorldTime() % 10 == 0) {
|
||||
GT_Packet_Ores packet_ores = new GT_Packet_Ores();
|
||||
ChunkCoordIntPair chunk = new ChunkCoordIntPair(new BlockPos(entityPlayer));
|
||||
for (int x = -1; x < 1; x++) {
|
||||
for (int z = -1; z < 1; z++) {
|
||||
ChunkCoordIntPair offset = chunk.offset(x, z);
|
||||
ArrayList<GT_TileEntity_Ores> ores = getChunkData(world.provider.getDimension(), offset);
|
||||
ores.removeIf(TileEntity::isInvalid);
|
||||
for (GT_TileEntity_Ores oresTile : ores) {
|
||||
packet_ores.addPos(oresTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!packet_ores.isEmpty()) {
|
||||
GT_Values.NW.sendTo(packet_ores, (EntityPlayerMP) entityPlayer);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
public static class ChunkCoordIntPair {
|
||||
|
||||
public final int coordX;
|
||||
public final int coordZ;
|
||||
|
||||
public ChunkCoordIntPair(BlockPos pos) {
|
||||
this(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair(int coordX, int coordZ) {
|
||||
this.coordX = coordX;
|
||||
this.coordZ = coordZ;
|
||||
}
|
||||
|
||||
public ChunkCoordIntPair offset(int x, int z) {
|
||||
if(x == 0 && z == 0) return this;
|
||||
return new ChunkCoordIntPair(coordX + x, coordZ + z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ChunkCoordIntPair)) return false;
|
||||
|
||||
ChunkCoordIntPair that = (ChunkCoordIntPair) o;
|
||||
|
||||
if (coordX != that.coordX) return false;
|
||||
if (coordZ != that.coordZ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = coordX;
|
||||
result = 31 * result + coordZ;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,16 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -30,6 +34,63 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
public short mMetaData = 0;
|
||||
public boolean mNatural = false;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket() {
|
||||
return new SPacketUpdateTileEntity(this.pos, -1, this.getUpdateTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
return writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
readFromNBT(pkt.getNbtCompound());
|
||||
causeChunkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(NBTTagCompound tag) {
|
||||
readNBTInternal(tag);
|
||||
causeChunkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound aNBT) {
|
||||
super.readFromNBT(aNBT);
|
||||
readNBTInternal(aNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound aNBT) {
|
||||
super.writeToNBT(aNBT);
|
||||
writeNBTInternal(aNBT);
|
||||
return aNBT;
|
||||
}
|
||||
|
||||
public void writeNBTInternal(NBTTagCompound tagCompound) {
|
||||
tagCompound.setShort("m", this.mMetaData);
|
||||
tagCompound.setBoolean("n", this.mNatural);
|
||||
}
|
||||
|
||||
public void readNBTInternal(NBTTagCompound tagCompound) {
|
||||
this.mMetaData = tagCompound.getShort("m");
|
||||
this.mNatural = tagCompound.getBoolean("n");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void causeChunkUpdate() {
|
||||
int minX = pos.getX() - 5;
|
||||
int minY = pos.getY() - 5;
|
||||
int minZ = pos.getZ() - 5;
|
||||
int maxX = pos.getX() + 5;
|
||||
int maxY = pos.getY() + 5;
|
||||
int maxZ = pos.getZ() + 5;
|
||||
Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public static byte getHarvestData(short aMetaData) {
|
||||
Materials aMaterial = GregTech_API.sGeneratedMaterials[(aMetaData % 1000)];
|
||||
byte tByte = aMaterial == null ? 0 : (byte) Math.max((aMetaData % 16000 / 1000 == 3) || (aMetaData % 16000 / 1000 == 4) ? 3 : 0, Math.min(7, aMaterial.mToolQuality - (aMetaData < 16000 ? 0 : 1)));
|
||||
|
@ -96,32 +157,6 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound aNBT) {
|
||||
super.readFromNBT(aNBT);
|
||||
this.mMetaData = aNBT.getShort("m");
|
||||
this.mNatural = aNBT.getBoolean("n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound aNBT) {
|
||||
super.writeToNBT(aNBT);
|
||||
aNBT.setShort("m", this.mMetaData);
|
||||
aNBT.setBoolean("n", this.mNatural);
|
||||
return aNBT;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void causeChunkUpdate() {
|
||||
int minX = pos.getX() - 5;
|
||||
int minY = pos.getY() - 5;
|
||||
int minZ = pos.getZ() - 5;
|
||||
int maxX = pos.getX() + 5;
|
||||
int maxY = pos.getY() + 5;
|
||||
int maxZ = pos.getZ() + 5;
|
||||
Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public void overrideOreBlockMaterial(Block aOverridingStoneBlock, byte aOverridingStoneMeta) {
|
||||
this.mMetaData = ((short) (int) (this.mMetaData % 1000L + this.mMetaData / 16000L * 16000L));
|
||||
if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), state -> state.getBlock() == Blocks.NETHERRACK)) {
|
||||
|
@ -152,18 +187,6 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
this.worldObj.setBlockState(getPos(), getBlockType().getStateFromMeta(getHarvestData(this.mMetaData)), 0);
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void invalidate() {
|
||||
//super.invalidate();
|
||||
//GT_TickHandler_Ores.unloadChunkOre(this);
|
||||
//}
|
||||
|
||||
//@Override
|
||||
//public void validate() {
|
||||
//super.validate();
|
||||
//GT_TickHandler_Ores.loadChunkOre(this);
|
||||
//}
|
||||
|
||||
public void convertOreBlock(World aWorld, int aX, int aY, int aZ) {
|
||||
short aMeta = ((short) (int) (this.mMetaData % 1000 + (this.mMetaData / 16000 * 16000)));
|
||||
aWorld.setBlockState(new BlockPos(aX, aY, aZ), GregTech_API.sBlockOres1.getStateFromMeta(getHarvestData(aMeta)));
|
||||
|
@ -173,10 +196,6 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
}
|
||||
}
|
||||
|
||||
public short getMetaData() {
|
||||
return this.mMetaData;
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> getDrops(Block aDroppedOre, int aFortune) {
|
||||
ArrayList<ItemStack> rList = new ArrayList<>();
|
||||
if (this.mMetaData <= 0) {
|
||||
|
@ -252,6 +271,7 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
return rList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITexture[] getTexture(Block aBlock, byte aSide) {
|
||||
Materials aMaterial = GregTech_API.sGeneratedMaterials[(this.mMetaData % 1000)];
|
||||
if ((aMaterial != null) && (this.mMetaData < 32000)) {
|
||||
|
@ -264,4 +284,5 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
|
|||
new GT_RenderedTexture("minecraft:blocks/stone", null),
|
||||
new GT_RenderedTexture(gregtech.api.enums.TextureSet.SET_NONE.mTextures[OrePrefixes.ore.mTextureIndex])};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue