From cf517ca9f6799a1ac9fe5f9db2db8de5096b558b Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Tue, 10 Jun 2014 23:21:26 +0100 Subject: [PATCH] More portal fanciness and mana usage. --- .../common/block/tile/TileAlfPortal.java | 114 +++++++++++------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/MODSRC/vazkii/botania/common/block/tile/TileAlfPortal.java b/MODSRC/vazkii/botania/common/block/tile/TileAlfPortal.java index 15190a598..03fe8d935 100644 --- a/MODSRC/vazkii/botania/common/block/tile/TileAlfPortal.java +++ b/MODSRC/vazkii/botania/common/block/tile/TileAlfPortal.java @@ -16,9 +16,9 @@ import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -import vazkii.botania.api.BotaniaAPI; import vazkii.botania.common.Botania; import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.block.tile.mana.TilePool; import com.google.common.base.Function; @@ -27,7 +27,7 @@ public class TileAlfPortal extends TileMod { private static final int[][] LIVINGWOOD_POSITIONS = { { -1, 0, 0}, { 1, 0, 0}, { -2, 1, 0}, { 2, 1, 0}, { -2, 3, 0}, { 2, 3, 0}, { -1, 4, 0}, { 1, 4, 0} }; - + private static final int[][] GLIMMERING_LIVINGWOOD_POSITIONS = { { -2, 2, 0 }, { 2, 2, 0 }, { 0, 4, 0 } }; @@ -35,40 +35,41 @@ public class TileAlfPortal extends TileMod { private static final int[][] PYLON_POSITIONS = { { -3, 1, 3 }, { 3, 1, 3 } }; - + private static final int[][] POOL_POSITIONS = { { -3, 0, 3 }, { 3, 0, 3 } }; - + private static final int[][] AIR_POSITIONS = { { -1, 1, 0 }, { 0, 1, 0 }, { 1, 1, 0 }, { -1, 2, 0 }, { 0, 2, 0 }, { 1, 2, 0 }, { -1, 3, 0 }, { 0, 3, 0 }, { 1, 3, 0 } }; - + private static final String TAG_TICKS_OPEN = "ticksOpen"; - + public int ticksOpen = 0; - + private boolean closeNow = false; + private static final Function CONVERTER_X_Z = new Function() { @Override public int[] apply(int[] input) { return new int[] { input[2], input[1], input[0] }; } }; - + private static final Function CONVERTER_X_Z_FLOAT = new Function() { @Override public float[] apply(float[] input) { return new float[] { input[2], input[1], input[0] }; } }; - + private static final Function CONVERTER_Z_SWAP = new Function() { @Override public int[] apply(int[] input) { return new int[] { input[0], input[1], -input[2] }; } }; - + @Override public void updateEntity() { int meta = getBlockMetadata(); @@ -76,26 +77,37 @@ public class TileAlfPortal extends TileMod { ticksOpen = 0; return; } - + ticksOpen++; - if(ticksOpen > 60) { - int i = worldObj.rand.nextInt(AIR_POSITIONS.length); - float[] pos = new float[] { - AIR_POSITIONS[i][0] + 0.5F, AIR_POSITIONS[i][1] + 0.5F, AIR_POSITIONS[i][2] + 0.5F - }; - if(meta == 2) - pos = CONVERTER_X_Z_FLOAT.apply(pos); - - float motionMul = 0.2F; - Botania.proxy.wispFX(getWorldObj(), xCoord + pos[0], yCoord + pos[1], zCoord + pos[2], (float) (Math.random() * 0.25F), (float) (Math.random() * 0.5F + 0.5F), (float) (Math.random() * 0.25F), (float) (Math.random() * 0.15F + 0.1F), (float) (Math.random() - 0.5F) * motionMul, (float) (Math.random() - 0.5F) * motionMul, (float) (Math.random() - 0.5F) * motionMul); - - } - + if(ticksOpen > 60) + blockParticle(meta); + int newMeta = getValidMetadata(); - if(newMeta != meta) + if(closeNow) { + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 | 2); + for(int i = 0; i < 36; i++) + blockParticle(meta); + closeNow = false; + } else if(newMeta != meta) { + if(newMeta == 0) + for(int i = 0; i < 36; i++) + blockParticle(meta); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2); + } } - + + private void blockParticle(int meta) { + int i = worldObj.rand.nextInt(AIR_POSITIONS.length); + float[] pos = new float[] { + AIR_POSITIONS[i][0] + 0.5F, AIR_POSITIONS[i][1] + 0.5F, AIR_POSITIONS[i][2] + 0.5F + }; + if(meta == 2) + pos = CONVERTER_X_Z_FLOAT.apply(pos); + + float motionMul = 0.2F; + Botania.proxy.wispFX(getWorldObj(), xCoord + pos[0], yCoord + pos[1], zCoord + pos[2], (float) (Math.random() * 0.25F), (float) (Math.random() * 0.5F + 0.5F), (float) (Math.random() * 0.25F), (float) (Math.random() * 0.15F + 0.1F), (float) (Math.random() - 0.5F) * motionMul, (float) (Math.random() - 0.5F) * motionMul, (float) (Math.random() - 0.5F) * motionMul); + } + public boolean onWanded() { int meta = getBlockMetadata(); if(meta == 0) { @@ -106,36 +118,38 @@ public class TileAlfPortal extends TileMod { } } else { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 | 2); + for(int i = 0; i < 36; i++) + blockParticle(meta); return true; } - + return false; } - + @Override public void writeCustomNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_TICKS_OPEN, ticksOpen); } - + @Override public void readCustomNBT(NBTTagCompound cmp) { ticksOpen = cmp.getInteger(TAG_TICKS_OPEN); } - + private int getValidMetadata() { if(checkConverter(null)) return 1; if(checkConverter(CONVERTER_X_Z)) return 2; - + return 0; } - + private boolean checkConverter(Function baseConverter) { return checkMultipleConverters(baseConverter) || checkMultipleConverters(CONVERTER_Z_SWAP, baseConverter); } - + private boolean checkMultipleConverters(Function... converters) { if(!check2DArray(AIR_POSITIONS, Blocks.air, -1, converters)) return false; @@ -147,20 +161,22 @@ public class TileAlfPortal extends TileMod { return false; if(!check2DArray(POOL_POSITIONS, ModBlocks.pool, -1, converters)) return false; - + lightPylons(converters); return true; } - + private void lightPylons(Function... converters) { if(ticksOpen < 50) return; - + + int cost = ticksOpen == 50 ? 75000 : 2; + for(int[] pos : PYLON_POSITIONS) { for(Function f : converters) if(f != null) pos = f.apply(pos); - + TileEntity tile = worldObj.getTileEntity(xCoord + pos[0], yCoord + pos[1], zCoord + pos[2]); if(tile instanceof TilePylon) { TilePylon pylon = (TilePylon) tile; @@ -169,23 +185,31 @@ public class TileAlfPortal extends TileMod { pylon.centerY = yCoord; pylon.centerZ = zCoord; } - } + tile = worldObj.getTileEntity(xCoord + pos[0], yCoord + pos[1] - 1, zCoord + pos[2]); + if(tile instanceof TilePool) { + TilePool pool = (TilePool) tile; + if(pool.getCurrentMana() < cost) + closeNow = true; + else if(!worldObj.isRemote) + pool.recieveMana(-cost); + } + } } - + private boolean check2DArray(int[][] positions, Block block, int meta, Function... converters) { for(int[] pos : positions) { for(Function f : converters) if(f != null) pos = f.apply(pos); - + if(!checkPosition(pos, block, meta)) return false; } - + return true; } - + private boolean checkPosition(int[] pos, Block block, int meta) { int x = xCoord + pos[0]; int y = yCoord + pos[1]; @@ -194,14 +218,14 @@ public class TileAlfPortal extends TileMod { if(block == Blocks.air ? blockat.isAir(worldObj, x, y, z) : blockat == block) { if(meta == -1) return true; - + int metaat = worldObj.getBlockMetadata(x, y, z); return meta == metaat; } - + return false; } - + @Override public AxisAlignedBB getRenderBoundingBox() { return INFINITE_EXTENT_AABB;