From 15c1b565ca46cf7f77e3466e3dcad899406900ff Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 10 Mar 2014 05:20:34 +0800 Subject: [PATCH] Fixed Quantum Gate placement logic --- .../electrical/Electrical.java | 9 +- .../quantum/gate/BlockQuantumGate.java | 122 ------------- .../quantum/gate/ItemQuantumGlyph.java | 64 ++++--- .../quantum/gate/PartQuantumGlyph.java | 42 +++-- .../quantum/gate/TileQuantumGate.java | 163 ------------------ .../quantum/gate/TraitQuantumGate.java | 2 +- 6 files changed, 59 insertions(+), 343 deletions(-) delete mode 100644 electrical/src/main/java/resonantinduction/quantum/gate/BlockQuantumGate.java delete mode 100644 electrical/src/main/java/resonantinduction/quantum/gate/TileQuantumGate.java diff --git a/electrical/src/main/java/resonantinduction/electrical/Electrical.java b/electrical/src/main/java/resonantinduction/electrical/Electrical.java index 38a6e257..02cad60b 100644 --- a/electrical/src/main/java/resonantinduction/electrical/Electrical.java +++ b/electrical/src/main/java/resonantinduction/electrical/Electrical.java @@ -29,13 +29,9 @@ import resonantinduction.electrical.tesla.TileTesla; import resonantinduction.electrical.transformer.ItemTransformer; import resonantinduction.electrical.wire.EnumWireMaterial; import resonantinduction.electrical.wire.ItemWire; -import resonantinduction.quantum.gate.BlockGlyph; -import resonantinduction.quantum.gate.BlockQuantumGate; import resonantinduction.quantum.gate.ItemQuantumGlyph; -import resonantinduction.quantum.gate.TileQuantumGate; import calclavia.lib.content.ContentRegistry; import calclavia.lib.network.PacketHandler; -import calclavia.lib.prefab.item.ItemBlockMetadata; import calclavia.lib.recipe.UniversalRecipe; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; @@ -125,7 +121,6 @@ public class Electrical blockThermopile = contentRegistry.createTile(BlockThermopile.class, TileThermopile.class); // Quantum - blockQuantumGate = contentRegistry.createTile(BlockQuantumGate.class, TileQuantumGate.class); itemQuantumGlyph = contentRegistry.createItem(ItemQuantumGlyph.class); Settings.save(); @@ -190,8 +185,8 @@ public class Electrical GameRegistry.addRecipe(new ShapedOreRecipe(itemTransformer, "WWW", "WWW", "III", 'W', "wire", 'I', UniversalRecipe.PRIMARY_METAL.get())); GameRegistry.addRecipe(new ShapedOreRecipe(itemLevitator, " G ", "SDS", "SWS", 'W', "wire", 'G', Block.glass, 'D', Block.blockDiamond, 'S', UniversalRecipe.PRIMARY_METAL.get())); - /** Quantum */ - GameRegistry.addRecipe(new ShapedOreRecipe(blockQuantumGate, "TTT", "LBL", "CCC", 'B', Block.blockDiamond, 'L', itemLevitator, 'C', itemCharger, 'T', blockTesla)); + /** Quantum Gates */ + GameRegistry.addRecipe(new ShapedOreRecipe(itemQuantumGlyph, "TTT", "LBL", "CCC", 'B', Block.blockDiamond, 'L', itemLevitator, 'C', itemCharger, 'T', blockTesla)); /** Generators **/ GameRegistry.addRecipe(new ShapedOreRecipe(blockSolarPanel, "CCC", "WWW", "III", 'W', "wire", 'C', Item.coal, 'I', UniversalRecipe.PRIMARY_METAL.get())); diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/BlockQuantumGate.java b/electrical/src/main/java/resonantinduction/quantum/gate/BlockQuantumGate.java deleted file mode 100644 index edcb2564..00000000 --- a/electrical/src/main/java/resonantinduction/quantum/gate/BlockQuantumGate.java +++ /dev/null @@ -1,122 +0,0 @@ -package resonantinduction.quantum.gate; - -import java.util.Random; - -import net.minecraft.block.material.Material; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Icon; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; -import resonantinduction.electrical.Electrical; -import calclavia.lib.prefab.block.BlockTile; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class BlockQuantumGate extends BlockTile -{ - public Icon iconTop, iconSide, iconBot; - - public BlockQuantumGate(int id) - { - super(id, Material.iron); - this.setHardness(32F); - this.setResistance(1000F); - } - - /** A randomly called display update to be able to add particles or other items for display */ - @Override - @SideOnly(Side.CLIENT) - public void randomDisplayTick(World world, int x, int y, int z, Random par5Random) - { - TileEntity tile = world.getBlockTileEntity(x, y, z); - - if (tile instanceof TileQuantumGate) - { - int frequency = ((TileQuantumGate) tile).getFrequency(); - - if (frequency != -1) - { - /** - * Spawn particles all around the pillar - */ - - for (int height = 0; height < 4; height++) - { - for (int i = 2; i < 6; i++) - { - ForgeDirection dir = ForgeDirection.getOrientation(i); - double spawnX = x + 0.5f + dir.offsetX; - double spawnY = y + 0.255f + par5Random.nextFloat() * 0.25f - height; - double spawnZ = z + 0.5f + dir.offsetZ; - double xRand = par5Random.nextFloat() * 0.6F - 0.3F; - double zRand = par5Random.nextFloat() * 0.6F - 0.3F; - - world.spawnParticle("enchantmenttable", spawnX + xRand, spawnY, spawnZ + zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("enchantmenttable", spawnX - xRand, spawnY, spawnZ + zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("enchantmenttable", spawnX + xRand, spawnY, spawnZ - zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("enchantmenttable", spawnX - xRand, spawnY, spawnZ - zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - - if (((TileQuantumGate) tile).canFunction()) - { - world.spawnParticle("portal", spawnX + xRand, spawnY, spawnZ + zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("portal", spawnX - xRand, spawnY, spawnZ + zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("portal", spawnX + xRand, spawnY, spawnZ - zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - world.spawnParticle("portal", spawnX - xRand, spawnY, spawnZ - zRand, Math.random() * 0.5, 0.1, Math.random() * 0.5); - } - } - } - } - } - } - - @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float f1, float f2, float f3) - { - if (player != null && player.getHeldItem() == null) - { - TileEntity tile = world.getBlockTileEntity(x, y, z); - - if (tile instanceof TileQuantumGate) - { - int frequency = ((TileQuantumGate) tile).getFrequency(); - - if (frequency == -1) - { - if (!world.isRemote) - player.addChatMessage("Quantum Gate not set up."); - } - else - { - if (!world.isRemote) - { - player.addChatMessage("Quantum Gate frequency: " + " " + frequency); - } - } - } - return true; - } - - return false; - } - - @Override - public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity par5Entity) - { - - } - - @Override - public TileEntity createNewTileEntity(World world) - { - return new TileQuantumGate(); - } - - @Override - public boolean isOpaqueCube() - { - return false; - } - -} diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java b/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java index 47872f44..f0286cf9 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/ItemQuantumGlyph.java @@ -8,13 +8,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.core.prefab.part.IHighlight; -import resonantinduction.mechanical.energy.gear.PartGearShaft; import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.Vector3; import codechicken.microblock.CornerPlacementGrid$; import codechicken.multipart.JItemMultiPart; import codechicken.multipart.MultiPartRegistry; -import codechicken.multipart.PartMap; import codechicken.multipart.TMultiPart; import codechicken.multipart.TileMultipart; @@ -33,45 +31,45 @@ public class ItemQuantumGlyph extends JItemMultiPart implements IHighlight } @Override - public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int slot, Vector3 hit) + public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit) { PartQuantumGlyph part = (PartQuantumGlyph) MultiPartRegistry.createPart("resonant_induction_quantum_glyph", false); - slot = CornerPlacementGrid$.MODULE$.getHitSlot(hit, slot); - System.out.println(slot); - switch (slot) - { - case 7: - slot = 0; - break; - case 9: - slot = 1; - break; - case 11: - slot = 2; - break; - case 13: - slot = 3; - break; - - case 8: - slot = 4; - break; - case 10: - slot = 5; - break; - case 12: - slot = 6; - break; - case 14: - slot = 7; - break; - } + int slot = CornerPlacementGrid$.MODULE$.getHitSlot(hit, side); TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z); if (tile instanceof TileMultipart) { + TMultiPart checkPart = ((TileMultipart) tile).partMap(slot); + if (checkPart != null) + { + switch (side) + { + case 0: + slot -= 1; + break; + case 1: + slot += 1; + break; + case 2: + slot -= 2; + break; + case 3: + slot += 2; + break; + case 4: + slot -= 4; + break; + case 5: + slot += 4; + break; + } + } + else + { + pos.offset(side); + } } part.preparePlacement(slot, itemStack.getItemDamage()); diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java b/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java index a47aa766..0ca98a30 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/PartQuantumGlyph.java @@ -22,35 +22,37 @@ import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Vector3; import codechicken.multipart.JCuboidPart; import codechicken.multipart.JNormalOcclusion; +import codechicken.multipart.TSlottedPart; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, IQuantumGate +public class PartQuantumGlyph extends JCuboidPart implements TSlottedPart, JNormalOcclusion, IQuantumGate { public static final int MAX_GLYPH = 4; - static final Cuboid6[] bounds = new Cuboid6[8]; + static final Cuboid6[] bounds = new Cuboid6[15]; static { float expansion = -0.02f; - bounds[0] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5).expand(expansion); - bounds[1] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1).expand(expansion); - bounds[2] = new Cuboid6(0.5, 0, 0, 1, 0.5, 0.5).expand(expansion); - bounds[3] = new Cuboid6(0.5, 0, 0.5, 1, 0.5, 1).expand(expansion); - bounds[4] = new Cuboid6(0, 0.5, 0, 0.5, 1, 0.5).expand(expansion); - bounds[5] = new Cuboid6(0, 0.5, 0.5, 0.5, 1, 1).expand(expansion); - bounds[6] = new Cuboid6(0.5, 0.5, 0, 1, 1, 0.5).expand(expansion); - bounds[7] = new Cuboid6(0.5, 0.5, 0.5, 1, 1, 1).expand(expansion); + bounds[7] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5).expand(expansion); + bounds[9] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1).expand(expansion); + bounds[11] = new Cuboid6(0.5, 0, 0, 1, 0.5, 0.5).expand(expansion); + bounds[13] = new Cuboid6(0.5, 0, 0.5, 1, 0.5, 1).expand(expansion); + + bounds[8] = new Cuboid6(0, 0.5, 0, 0.5, 1, 0.5).expand(expansion); + bounds[10] = new Cuboid6(0, 0.5, 0.5, 0.5, 1, 1).expand(expansion); + bounds[12] = new Cuboid6(0.5, 0.5, 0, 1, 1, 0.5).expand(expansion); + bounds[14] = new Cuboid6(0.5, 0.5, 0.5, 1, 1, 1).expand(expansion); } - private byte side; + private byte slot; byte number; int ticks; public void preparePlacement(int side, int itemDamage) { - this.side = (byte) side; + this.slot = (byte) side; this.number = (byte) itemDamage; } @@ -172,9 +174,9 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I @Override public Cuboid6 getBounds() { - if (side < bounds.length) - if (bounds[side] != null) - return bounds[side]; + if (slot < bounds.length) + if (bounds[slot] != null) + return bounds[slot]; return new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5); } @@ -185,6 +187,12 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I return Arrays.asList(new Cuboid6[] { getBounds() }); } + @Override + public int getSlotMask() + { + return 1 << slot; + } + protected ItemStack getItem() { return new ItemStack(Electrical.itemQuantumGlyph, 1, number); @@ -223,14 +231,14 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I @Override public void load(NBTTagCompound nbt) { - side = nbt.getByte("side"); + slot = nbt.getByte("side"); number = nbt.getByte("number"); } @Override public void save(NBTTagCompound nbt) { - nbt.setByte("side", side); + nbt.setByte("side", slot); nbt.setByte("number", number); } diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/TileQuantumGate.java b/electrical/src/main/java/resonantinduction/quantum/gate/TileQuantumGate.java deleted file mode 100644 index 8e131004..00000000 --- a/electrical/src/main/java/resonantinduction/quantum/gate/TileQuantumGate.java +++ /dev/null @@ -1,163 +0,0 @@ -package resonantinduction.quantum.gate; - -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import resonantinduction.electrical.tesla.ITesla; -import resonantinduction.electrical.tesla.TeslaGrid; -import universalelectricity.api.energy.EnergyStorageHandler; -import universalelectricity.api.vector.Vector3; -import universalelectricity.api.vector.VectorWorld; -import calclavia.lib.prefab.tile.TileElectrical; - -/** - * @author Calclavia, Archadia - */ -public class TileQuantumGate extends TileElectrical implements ITesla -{ - private long lastFrequencyCheck = 0; - private int frequency = 0; - - public TileQuantumGate() - { - energy = new EnergyStorageHandler(100000); - ioMap = 0; - } - - @Override - public void initiate() - { - super.initiate(); - TeslaGrid.instance().register(this); - - if (!worldObj.isRemote) - { - QuantumGateManager.addAnchor(this); - } - } - - @Override - public void updateEntity() - { - super.updateEntity(); - - if (canFunction() && ticks % 60 == 0) - { - AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(xCoord - 1, yCoord - 4, zCoord - 1, xCoord + 2, yCoord + 2, zCoord + 2); - List entities = worldObj.getEntitiesWithinAABB(Entity.class, bounds); - - for (Entity entity : entities) - { - if (entity instanceof EntityPlayer) - if (entity.isSneaking()) - continue; - - doTeleport(entity); - } - } - } - - public boolean canFunction() - { - return energy.isFull(); - } - - @Override - public void validate() - { - - super.validate(); - } - - @Override - public void invalidate() - { - if (!worldObj.isRemote) - { - QuantumGateManager.remAnchor(this); - } - - TeslaGrid.instance().unregister(this); - super.invalidate(); - } - - public void doTeleport(Entity entity) - { - VectorWorld teleportSpot = null; - - if (getFrequency() != -1) - { - TileQuantumGate teleporter = QuantumGateManager.getClosestWithFrequency(new VectorWorld(this), getFrequency(), this); - - if (teleporter != null) - { - teleportSpot = new VectorWorld(teleporter).translate(0.5, 2, 0.5); - } - } - - if (teleportSpot != null) - { - QuantumGateManager.moveEntity(entity, teleportSpot); - } - } - - /** @return -1 if the teleporter is unable to teleport. */ - public int getFrequency() - { - if (System.currentTimeMillis() - this.lastFrequencyCheck > 10) - { - this.lastFrequencyCheck = System.currentTimeMillis(); - this.frequency = 0; - - for (int i = 4; i > 0; i--) - { - Vector3 position = new Vector3(xCoord, yCoord - i, this.zCoord); - - Block block = Block.blocksList[this.worldObj.getBlockId((int) position.x, (int) position.y, (int) position.z)]; - - if (block instanceof BlockGlyph) - { - int metadata = this.worldObj.getBlockMetadata((int) position.x, (int) position.y, (int) position.z); - this.frequency += Math.pow(BlockGlyph.MAX_GLYPH, i - 2) * metadata; - } - else - { - return -1; - } - } - } - - return frequency; - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - - } - - @Override - public long teslaTransfer(long transferEnergy, boolean doTransfer) - { - return energy.receiveEnergy(transferEnergy, doTransfer); - } - - @Override - public boolean canTeslaTransfer(TileEntity transferTile) - { - return true; - } -} diff --git a/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java b/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java index cc7ebd76..208ad425 100644 --- a/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java +++ b/electrical/src/main/java/resonantinduction/quantum/gate/TraitQuantumGate.java @@ -31,7 +31,7 @@ public class TraitQuantumGate extends TileMultipart implements IQuantumGate for (TMultiPart part : jPartList()) { - if (part instanceof IBlockFrequency) + if (part instanceof IQuantumGate) { frequency += Math.pow(PartQuantumGlyph.MAX_GLYPH, i) * ((IBlockFrequency) part).getFrequency(); i++;