Created
May 17, 2014 19:41
-
-
Save Corosauce/88145bea0c48c32cadee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package combat.block; | |
import combat.location.StructureObject; | |
import combat.location.town.building.BuildingCommand; | |
import combat.registry.StructureMapping; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.ChunkCoordinates; | |
public class TileEntityRTSBuilding extends TileEntity | |
{ | |
//this class is now just a tile entity that makes a town | |
public StructureObject building; | |
public NBTTagCompound nbtBuilding; | |
public boolean firstTimeSync = true; | |
public boolean hasLoadedNBT = false; | |
public boolean waitingOnExternalInit = true; //this is to let mc do its thing to auto setup the tile entity, so then my outside code can initialize the building info for it, and then mark this false | |
//important nbt | |
public String buildingNameType = "command"; | |
public TileEntityRTSBuilding(String parName) { | |
buildingNameType = parName; | |
} | |
public TileEntityRTSBuilding() { | |
} | |
public void updateEntity() | |
{ | |
if (!worldObj.isRemote) { | |
if (hasLoadedNBT) { | |
if (firstTimeSync && !waitingOnExternalInit) { | |
firstTimeSync = false; | |
initReady(); | |
} | |
//if (building != null) building.tickUpdate(); | |
} | |
} | |
} | |
@Override | |
public void validate() | |
{ | |
super.validate(); | |
hasLoadedNBT = true; | |
} | |
@Override | |
public void invalidate() | |
{ | |
cleanup(); | |
super.invalidate(); | |
} | |
public void onBlockBroken() | |
{ | |
cleanup(); | |
} | |
public void cleanup() { | |
} | |
public void setBuildingAndMarkInitReady(String parName, int parTeam) { | |
setBuildingAndMarkInitReady(parName); | |
nbtBuilding = new NBTTagCompound(); | |
nbtBuilding.setInteger("teamID", parTeam); | |
nbtBuilding.setInteger("posX", xCoord); | |
nbtBuilding.setInteger("posY", yCoord); | |
nbtBuilding.setInteger("posZ", zCoord); | |
} | |
public void setBuildingAndMarkInitReady(String parName) { | |
buildingNameType = parName; | |
waitingOnExternalInit = false; | |
} | |
public void initReady() { | |
building = StructureMapping.newTown(this.worldObj.provider.dimensionId, buildingNameType, new ChunkCoordinates(xCoord, yCoord, zCoord)); | |
if (building != null) { | |
//if (building instanceof BuildingCommand) ((BuildingCommand)building).dimID = this.worldObj.provider.dimensionId; | |
if (nbtBuilding != null) building.readFromNBT(nbtBuilding); | |
building.init(); | |
building.location.initFirstTime(); | |
} else { | |
System.out.println("building null, weird command building tile entity left over"); | |
} | |
} | |
public void writeToNBT(NBTTagCompound var1) | |
{ | |
super.writeToNBT(var1); | |
/*var1.setString("buildingNameType", buildingNameType); | |
NBTTagCompound tag = new NBTTagCompound(); | |
if (building != null) { | |
building.writeToNBT(tag); | |
} | |
var1.setCompoundTag("buildingData", tag);*/ | |
} | |
public void readFromNBT(NBTTagCompound var1) | |
{ | |
super.readFromNBT(var1); | |
buildingNameType = var1.getString("buildingNameType"); | |
nbtBuilding = var1.getCompoundTag("buildingData"); | |
waitingOnExternalInit = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment