diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index af1664d66..1c3a11108 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -945,7 +945,6 @@ public class ModBlocks { public static final int guiID_combine_factory = 35; public static Block machine_teleporter; - public static final int guiID_machine_teleporter = 36; public static Block teleanchor; public static Block field_disturber; diff --git a/src/main/java/com/hbm/blocks/machine/MachineTeleporter.java b/src/main/java/com/hbm/blocks/machine/MachineTeleporter.java index ac7db1bec..1df98bf12 100644 --- a/src/main/java/com/hbm/blocks/machine/MachineTeleporter.java +++ b/src/main/java/com/hbm/blocks/machine/MachineTeleporter.java @@ -1,30 +1,33 @@ package com.hbm.blocks.machine; -import java.util.Random; +import java.util.ArrayList; +import java.util.List; -import com.hbm.blocks.ModBlocks; -import com.hbm.items.ModItems; +import com.hbm.blocks.ILookOverlay; import com.hbm.lib.RefStrings; -import com.hbm.main.MainRegistry; import com.hbm.tileentity.machine.TileEntityMachineTeleporter; +import com.hbm.util.I18nUtil; -import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre; -public class MachineTeleporter extends BlockContainer { +public class MachineTeleporter extends BlockContainer implements ILookOverlay { @SideOnly(Side.CLIENT) private IIcon iconTop; @SideOnly(Side.CLIENT) private IIcon iconBottom; + public MachineTeleporter(Material mat) { + super(mat); + } + @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { @@ -39,34 +42,29 @@ public class MachineTeleporter extends BlockContainer { return side == 1 ? this.iconTop : (side == 0 ? this.iconBottom : this.blockIcon); } - @Override - public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { - return Item.getItemFromBlock(ModBlocks.machine_teleporter); - } - - public MachineTeleporter(Material p_i45386_1_) { - super(p_i45386_1_); - } - @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return new TileEntityMachineTeleporter(); } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + public void printHook(Pre event, World world, int x, int y, int z) { - if(player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.linker) { - return false; - - } else if(!player.isSneaking()) { - TileEntityMachineTeleporter entity = (TileEntityMachineTeleporter) world.getTileEntity(x, y, z); - if(entity != null && world.isRemote) { - FMLNetworkHandler.openGui(player, MainRegistry.instance, ModBlocks.guiID_machine_teleporter, world, x, y, z); - } - return true; + TileEntity tile = world.getTileEntity(x, y, z); + + if(!(tile instanceof TileEntityMachineTeleporter)) return; + + TileEntityMachineTeleporter tele = (TileEntityMachineTeleporter) tile; + + List text = new ArrayList(); + + if(tele.yCoord == -1) { + text.add(EnumChatFormatting.RED + "No destination set!"); } else { - return false; + text.add((tele.power >= tele.consumption ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + String.format("%,d", tele.power) + " / " + String.format("%,d", tele.maxPower)); + text.add("Destination: " + tele.targetX + " / " + tele.targetY + " / " + tele.targetZ); } + + ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text); } } diff --git a/src/main/java/com/hbm/items/special/ItemTeleLink.java b/src/main/java/com/hbm/items/special/ItemTeleLink.java index 98e60d432..a82b2ff0e 100644 --- a/src/main/java/com/hbm/items/special/ItemTeleLink.java +++ b/src/main/java/com/hbm/items/special/ItemTeleLink.java @@ -2,7 +2,6 @@ package com.hbm.items.special; import java.util.List; -import com.hbm.blocks.ModBlocks; import com.hbm.tileentity.machine.TileEntityMachineTeleporter; import net.minecraft.entity.player.EntityPlayer; @@ -11,58 +10,54 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; public class ItemTeleLink extends Item { @Override - public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int p_77648_7_, - float p_77648_8_, float p_77648_9_, float p_77648_10_) { - if (player.isSneaking()) { + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + + if(!player.isSneaking() && !world.isRemote) { + TileEntity te = world.getTileEntity(x, y, z); - if (te != null && te instanceof TileEntityMachineTeleporter - && world.getBlock(x, y, z) == ModBlocks.machine_teleporter) { - - if (stack.stackTagCompound == null) { + if(!(te instanceof TileEntityMachineTeleporter)) { + + if(stack.stackTagCompound == null) { stack.stackTagCompound = new NBTTagCompound(); - - stack.stackTagCompound.setInteger("x", x); - stack.stackTagCompound.setInteger("y", y); - stack.stackTagCompound.setInteger("z", z); - - if (world.isRemote) - player.addChatMessage(new ChatComponentText( - "[TeleLink] Set teleporter exit to " + x + ", " + y + ", " + z + ".")); - } else { - int x1 = stack.stackTagCompound.getInteger("x"); - int y1 = stack.stackTagCompound.getInteger("y"); - int z1 = stack.stackTagCompound.getInteger("z"); - - if (world.getBlock(x1, y1, z1) == ModBlocks.machine_teleporter - && world.getTileEntity(x1, y1, z1) != null - && world.getTileEntity(x1, y1, z1) instanceof TileEntityMachineTeleporter) { - - ((TileEntityMachineTeleporter) te).mode = true; - ((TileEntityMachineTeleporter) te).targetX = x1; - ((TileEntityMachineTeleporter) te).targetY = y1; - ((TileEntityMachineTeleporter) te).targetZ = z1; - ((TileEntityMachineTeleporter) te).linked = true; - ((TileEntityMachineTeleporter) world.getTileEntity(x1, y1, z1)).linked = true; - - if (world.isRemote) - player.addChatMessage( - new ChatComponentText("[TeleLink] Teleporters have been successfully linked.")); - - stack.stackTagCompound = null; - } else { - if (world.isRemote) - player.addChatMessage(new ChatComponentText( - "[TeleLink] Warning: Exit teleporter has been destroyed while linking. Values have been reset.")); - stack.stackTagCompound = null; - } } + + stack.stackTagCompound.setInteger("x", x); + stack.stackTagCompound.setInteger("y", y); + stack.stackTagCompound.setInteger("z", z); + world.playSoundAtEntity(player, "hbm:item.techBleep", 1.0F, 1.0F); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[TeleLink] Set teleporter exit to " + x + ", " + y + ", " + z + ".")); + player.swingItem(); + + return true; + + } else { + + if(!stack.hasTagCompound()) { + world.playSoundAtEntity(player, "hbm:item.techBoop", 1.0F, 1.0F); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[TeleLink] No destiation set!")); + return false; + } + + int x1 = stack.stackTagCompound.getInteger("x"); + int y1 = stack.stackTagCompound.getInteger("y"); + int z1 = stack.stackTagCompound.getInteger("z"); + + TileEntityMachineTeleporter tele = (TileEntityMachineTeleporter) te; + tele.targetX = x1; + tele.targetY = y1; + tele.targetZ = z1; + + tele.markDirty(); + world.playSoundAtEntity(player, "hbm:item.techBleep", 1.0F, 1.0F); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[TeleLink] Teleporters have been successfully linked.")); player.swingItem(); return true; } @@ -74,12 +69,11 @@ public class ItemTeleLink extends Item { @Override public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool) { if (itemstack.stackTagCompound != null) { - list.add("Teleporter Exit x: " + itemstack.stackTagCompound.getInteger("x")); - list.add("Teleporter Exit y: " + itemstack.stackTagCompound.getInteger("y")); - list.add("Teleporter Exit z: " + itemstack.stackTagCompound.getInteger("z")); + list.add("X: " + itemstack.stackTagCompound.getInteger("x")); + list.add("Y: " + itemstack.stackTagCompound.getInteger("y")); + list.add("Z: " + itemstack.stackTagCompound.getInteger("z")); } else { - list.add("Select teleporter exit first!"); - list.add("Right-click teleporter while sneaking."); + list.add(EnumChatFormatting.RED + "Select exit location first!"); } } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineTeleporter.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineTeleporter.java index ed2457752..2e1da9cb3 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineTeleporter.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineTeleporter.java @@ -2,29 +2,23 @@ package com.hbm.tileentity.machine; import java.util.List; -import com.hbm.lib.ModDamageSource; -import com.hbm.packet.AuxElectricityPacket; -import com.hbm.packet.PacketDispatcher; +import com.hbm.tileentity.INBTPacketReceiver; import com.hbm.tileentity.TileEntityLoadedBase; import api.hbm.energy.IEnergyUser; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -public class TileEntityMachineTeleporter extends TileEntityLoadedBase implements IEnergyUser { +public class TileEntityMachineTeleporter extends TileEntityLoadedBase implements IEnergyUser, INBTPacketReceiver { public long power = 0; - public int targetX = 0; - public int targetY = 0; - public int targetZ = 0; - public boolean linked = false; - // true: send; false: receive - public boolean mode = false; - public static final int maxPower = 100000; + public int targetX = -1; + public int targetY = -1; + public int targetZ = -1; + public static final int maxPower = 1_500_000; + public static final int consumption = 1_000_000; @Override public void readFromNBT(NBTTagCompound nbt) { @@ -34,8 +28,6 @@ public class TileEntityMachineTeleporter extends TileEntityLoadedBase implements targetX = nbt.getInteger("x1"); targetY = nbt.getInteger("y1"); targetZ = nbt.getInteger("z1"); - linked = nbt.getBoolean("linked"); - mode = nbt.getBoolean("mode"); } @Override @@ -46,8 +38,6 @@ public class TileEntityMachineTeleporter extends TileEntityLoadedBase implements nbt.setInteger("x1", targetX); nbt.setInteger("y1", targetY); nbt.setInteger("z1", targetZ); - nbt.setBoolean("linked", linked); - nbt.setBoolean("mode", mode); } @Override @@ -58,44 +48,55 @@ public class TileEntityMachineTeleporter extends TileEntityLoadedBase implements if (!this.worldObj.isRemote) { this.updateStandardConnections(worldObj, xCoord, yCoord, zCoord); - List entities = this.worldObj.getEntitiesWithinAABB(Entity.class, - AxisAlignedBB.getBoundingBox(this.xCoord - 0.25, this.yCoord, this.zCoord - 0.25, this.xCoord + 1.5, - this.yCoord + 2, this.zCoord + 1.5)); - if (!entities.isEmpty()) - for (Entity e : entities) { - if(e.ticksExisted >= 10) { - teleport(e); - b0 = true; - } + List entities = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord - 0.25, this.yCoord, this.zCoord - 0.25, this.xCoord + 1.5, this.yCoord + 2, this.zCoord + 1.5)); + + if(!entities.isEmpty()) { + for(Entity e : entities) { + teleport(e); } - - PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50)); + } + + NBTTagCompound data = new NBTTagCompound(); + data.setLong("power", power); + data.setIntArray("target", new int[] {targetX, targetY, targetZ}); + INBTPacketReceiver.networkPack(this, data, 15); + + } else { + + if(power >= consumption) { + double x = xCoord + 0.5 + worldObj.rand.nextGaussian() * 0.25D; + double y = yCoord + 1 + worldObj.rand.nextDouble() * 2D; + double z = zCoord + 0.5 + worldObj.rand.nextGaussian() * 0.25D; + worldObj.spawnParticle("reddust", x, y, z, 0.4F, 0.8F, 1F); + } } - - if(b0) - worldObj.spawnParticle("cloud", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0.0D, 0.1D, 0.0D); + } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + this.power = nbt.getLong("power"); + int[] target = nbt.getIntArray("target"); + this.targetX = target[0]; + this.targetX = target[1]; + this.targetX = target[2]; } public void teleport(Entity entity) { - - if (!this.linked || !this.mode || this.power < 50000) - return; - - TileEntity te = this.worldObj.getTileEntity(targetX, targetY, targetZ); - - if (te == null || !(te instanceof TileEntityMachineTeleporter) || ((TileEntityMachineTeleporter) te).mode) { - entity.attackEntityFrom(ModDamageSource.teleporter, 10000); + + if(this.power < consumption) return; + + worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "mob.endermen.portal", 1.0F, 1.0F); + + if((entity instanceof EntityPlayerMP)) { + ((EntityPlayerMP) entity).setPositionAndUpdate(this.targetX + 0.5D, this.targetY + 1D + entity.getYOffset(), this.targetZ + 0.5D); } else { - if ((entity instanceof EntityPlayerMP)) { - ((EntityPlayerMP) entity).setPositionAndUpdate(this.targetX + 0.5D, - this.targetY + 1.5D + entity.getYOffset(), this.targetZ + 0.5D); - } else { - entity.setPositionAndRotation(this.targetX + 0.5D, this.targetY + 1.5D + entity.getYOffset(), - this.targetZ + 0.5D, entity.rotationYaw, entity.rotationPitch); - } + entity.setPositionAndRotation(this.targetX + 0.5D, this.targetY + 1D + entity.getYOffset(), this.targetZ + 0.5D, entity.rotationYaw, entity.rotationPitch); } - this.power -= 50000; + worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); + + this.power -= consumption; + this.markDirty(); } @Override