Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package astreaInfinitum.tileEntities.eco;
- import astreaInfinitum.api.IEcoAltarBlock;
- import astreaInfinitum.api.utils.TileEntityClientServer;
- import astreaInfinitum.blocks.AIBlocks;
- import astreaInfinitum.network.MessageAltarSync;
- import astreaInfinitum.network.PacketHandler;
- import astreaInfinitum.utils.BlockPos;
- import cpw.mods.fml.client.FMLClientHandler;
- import cpw.mods.fml.common.network.NetworkRegistry;
- import net.minecraft.block.Block;
- import net.minecraft.init.Blocks;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.world.World;
- import net.minecraftforge.common.util.Constants;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by Jared on 8/26/2015.
- */
- public class TileEntityEcoAltar extends TileEntityClientServer {
- public boolean activated;
- public boolean shouldConvert;
- public int convertTime;
- public boolean converted = false;
- public boolean shouldSendParticle;
- public List<BlockPos> blocksToConvert = new ArrayList<BlockPos>();
- public boolean converting = false;
- public TileEntityEcoAltar() {
- }
- @Override
- public void updateEntity() {
- super.updateEntity();
- }
- public void updateClient() {
- if (converting && !blocksToConvert.isEmpty()) {
- convert(worldObj, xCoord, yCoord, zCoord, true);
- }
- }
- public void updateServer() {
- if (!activated) {
- activated = canActivate(worldObj, xCoord, yCoord, zCoord);
- if (activated) {
- System.out.println("activated");
- markDirty();
- }
- }
- if (converting && !blocksToConvert.isEmpty()) {
- convert(worldObj, xCoord, yCoord, zCoord, false);
- }
- convertTime -= 1;
- if (convertTime <= 0) {
- converted = false;
- convertTime = 5;
- }
- }
- public boolean canActivate(World world, int x, int y, int z) {
- for (int X = x - 3; X <= x + 3; X++) {
- for (int Z = z - 3; Z <= z + 3; Z++) {
- if (X != x && Z != z) {
- if (world.getBlock(X, y, Z) == null || !(world.getBlock(X, y, Z) == Blocks.nether_brick || (world.getBlock(X, y, Z) == Blocks.quartz_block || world.getBlock(X, y, Z) instanceof IEcoAltarBlock))) {
- return false;
- }
- }
- }
- }
- return true;
- }
- public void getBlocksToConvert(World world, int x, int y, int z) {
- for (int X = x - 3; X <= x + 3; X++) {
- for (int Z = z - 3; Z <= z + 3; Z++) {
- Block block = world.getBlock(X, y, Z);
- if (block != null) {
- if (block == Blocks.nether_brick || block == Blocks.quartz_block) {
- blocksToConvert.add(new BlockPos(X, y, Z));
- }
- }
- }
- }
- }
- public void convert(World world, int x, int y, int z, boolean particle) {
- for (int j = 0; j < blocksToConvert.size(); j++) {
- BlockPos pos = blocksToConvert.get(j);
- int X = pos.x;
- int Z = pos.z;
- if (!converted) {
- if (worldObj.getBlock(X, yCoord, Z) == Blocks.nether_brick) {
- if (particle) {
- System.out.println("part");
- for (int i = 0; i < 16; i++) {
- world.spawnParticle("blockdust_" + Block.getIdFromBlock(worldObj.getBlock(X, yCoord, Z)) + "_0", X, yCoord, Z, 0, 0.8, 0);
- }
- }
- worldObj.setBlock(X, yCoord, Z, AIBlocks.ecoAltarBlock);
- converted = true;
- }
- if (worldObj.getBlock(X, yCoord, Z) == Blocks.quartz_block) {
- for (int i = 0; i < 16; i++) {
- FMLClientHandler.instance().getClient().theWorld.spawnParticle("blockdust_" + Block.getIdFromBlock(worldObj.getBlock(X, yCoord, Z)) + "_0", X, yCoord, Z, 0, 0.8, 0);
- }
- worldObj.setBlock(X, yCoord, Z, AIBlocks.ecoRitualBlock);
- converted = true;
- }
- if (converted) {
- blocksToConvert.remove(pos);
- markDirty();
- }
- }
- }
- }
- public boolean shouldActivate(World world, int x, int y, int z) {
- for (int X = x - 3; X <= x + 3; X++) {
- for (int Z = z - 3; Z <= z + 3; Z++) {
- if (world.getBlock(X, y, Z) == Blocks.nether_brick) {
- return true;
- }
- if (world.getBlock(X, y, Z) == Blocks.quartz_block) {
- return true;
- }
- }
- }
- return false;
- }
- @Override
- public void markDirty() {
- super.markDirty();
- PacketHandler.INSTANCE.sendToAllAround(new MessageAltarSync(this), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 128D));
- }
- public boolean isAltarActivated(World world, int x, int y, int z) {
- for (int X = x - 3; X <= x + 3; X++) {
- for (int Z = z - 3; Z <= z + 3; Z++) {
- if (X != x && Z != z) {
- if (!(world.getBlock(X, y, Z) instanceof IEcoAltarBlock)) {
- return false;
- }
- }
- }
- }
- return true;
- }
- @Override
- public void writeToNBT(NBTTagCompound tag) {
- super.writeToNBT(tag);
- tag.setBoolean("activated", activated);
- tag.setBoolean("shouldConvert", shouldConvert);
- tag.setInteger("convertTime", convertTime);
- writeBlocksToNbt(tag);
- }
- public void writeBlocksToNbt(NBTTagCompound tags) {
- NBTTagList nbttaglist = new NBTTagList();
- for (int iter = 0; iter < blocksToConvert.size(); iter++) {
- if (blocksToConvert.get(iter) != null) {
- NBTTagCompound tagList = new NBTTagCompound();
- tagList.setInteger("position", iter);
- blocksToConvert.get(iter).writeToNbt(tagList);
- nbttaglist.appendTag(tagList);
- }
- }
- tags.setTag("Blocks", nbttaglist);
- }
- @Override
- public void readFromNBT(NBTTagCompound tag) {
- super.readFromNBT(tag);
- activated = tag.getBoolean("activated");
- shouldConvert = tag.getBoolean("shouldConvert");
- convertTime = tag.getInteger("convertTime");
- readBlocksFromNbt(tag);
- }
- public void readBlocksFromNbt(NBTTagCompound tags) {
- NBTTagList nbttaglist = tags.getTagList("Blocks", Constants.NBT.TAG_COMPOUND);
- for (int iter = 0; iter < nbttaglist.tagCount(); iter++) {
- NBTTagCompound tagList = nbttaglist.getCompoundTagAt(iter);
- int position = tagList.getInteger("position");
- if (position >= 0 && position < blocksToConvert.size()) {
- blocksToConvert.set(position, BlockPos.getBlockFromNbt(tagList));
- }
- }
- }
- public boolean isActivated() {
- return activated;
- }
- public boolean isShouldConvert() {
- return shouldConvert;
- }
- public int getConvertTime() {
- return convertTime;
- }
- public boolean isConverted() {
- return converted;
- }
- public boolean isShouldSendParticle() {
- return shouldSendParticle;
- }
- public List<BlockPos> getBlocksToConvert() {
- return blocksToConvert;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement