package micdoodle8.mods.galacticraft.core.tile; import java.util.LinkedList; import java.util.List; import micdoodle8.mods.galacticraft.core.GCBlocks; import micdoodle8.mods.galacticraft.core.blocks.BlockMulti; import micdoodle8.mods.galacticraft.core.blocks.BlockMulti.EnumBlockMultiType; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class TileEntitySpaceStationBase extends TileEntityMulti implements IMultiBlock { public TileEntitySpaceStationBase() { super(null); } public String ownerUsername = "bobby"; private boolean initialised; @Override public void update() { if (!this.initialised) { this.initialised = this.initialiseMultiTiles(this.getPos(), this.worldObj); } } @Override public void readFromNBT(NBTTagCompound par1NBTTagCompound) { super.readFromNBT(par1NBTTagCompound); this.ownerUsername = par1NBTTagCompound.getString("ownerUsername"); } @Override public void writeToNBT(NBTTagCompound par1NBTTagCompound) { super.writeToNBT(par1NBTTagCompound); par1NBTTagCompound.setString("ownerUsername", this.ownerUsername); } public void setOwner(String username) { this.ownerUsername = username; } public String getOwner() { return this.ownerUsername; } @Override public boolean onActivated(EntityPlayer entityPlayer) { return false; } @Override public void onCreate(World world, BlockPos placedPosition) { this.mainBlockPosition = placedPosition; this.markDirty(); List<BlockPos> positions = new LinkedList(); this.getPositions(placedPosition, positions); ((BlockMulti) GCBlocks.fakeBlock).makeFakeBlock(world, positions, placedPosition, this.getMultiType()); } @Override public BlockMulti.EnumBlockMultiType getMultiType() { return EnumBlockMultiType.SPACE_STATION_BASE; } @Override public void getPositions(BlockPos placedPosition, List<BlockPos> positions) { int buildHeight = this.worldObj.getHeight() - 1; for (int y = 1; y < 3; y++) { if (placedPosition.getY() + y > buildHeight) { return; } positions.add(new BlockPos(placedPosition.getX(), placedPosition.getY() + y, placedPosition.getZ())); } } @Override public void onDestroy(TileEntity callingBlock) { final BlockPos thisBlock = getPos(); List<BlockPos> positions = new LinkedList(); this.getPositions(thisBlock, positions); for (BlockPos pos : positions) { IBlockState stateAt = this.worldObj.getBlockState(pos); if (stateAt.getBlock() == GCBlocks.fakeBlock && (EnumBlockMultiType) stateAt.getValue(BlockMulti.MULTI_TYPE) == EnumBlockMultiType.SPACE_STATION_BASE) { this.worldObj.setBlockToAir(pos); } } this.worldObj.destroyBlock(this.getPos(), false); } }