diff --git a/src/main/java/techreborn/blocks/BlockPlayerDetector.java b/src/main/java/techreborn/blocks/BlockPlayerDetector.java index 2bfa69f07..6b0d7149f 100644 --- a/src/main/java/techreborn/blocks/BlockPlayerDetector.java +++ b/src/main/java/techreborn/blocks/BlockPlayerDetector.java @@ -7,12 +7,18 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; +import techreborn.tiles.TilePlayerDectector; import java.util.List; import java.util.Random; @@ -70,4 +76,70 @@ public class BlockPlayerDetector extends BlockMachineBase { public void onBlockAdded(World world, int x, int y, int z) { } + + @Override + public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + return new TilePlayerDectector(); + } + + @Override + public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { + return true; + } + + @Override + public boolean canProvidePower() { + return true; + } + + @Override + public int isProvidingStrongPower(IBlockAccess blockAccess, int x, int y, int z, int side) { + TileEntity entity = blockAccess.getTileEntity(x, y, z); + if (entity instanceof TilePlayerDectector) { + return ((TilePlayerDectector) entity).isProvidingPower() ? 15 : 0; + } + return 0; + } + + @Override + public int isProvidingWeakPower(IBlockAccess blockAccess, int x, int y, int z, int side) { + TileEntity entity = blockAccess.getTileEntity(x, y, z); + if (entity instanceof TilePlayerDectector) { + return ((TilePlayerDectector) entity).isProvidingPower() ? 15 : 0; + } + return 0; + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { + super.onBlockPlacedBy(world, x, y, z, player, itemstack); + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TilePlayerDectector) { + ((TilePlayerDectector) tile).owenerUdid = player.getUniqueID().toString(); + } + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { + if (super.onBlockActivated(world, x, y, z, entityplayer, side, hitX, hitY, hitZ)) { + return true; + } + int newMeta = (world.getBlockMetadata(x, y, z) + 1) % 3; + String message = ""; + switch (newMeta) { + case 0: + message = EnumChatFormatting.GREEN + "Detects all Players"; + break; + case 1: + message = EnumChatFormatting.RED + "Detects only other Players"; + break; + case 2: + message = EnumChatFormatting.BLUE + "Detects only you"; + } + if(!world.isRemote){ + entityplayer.addChatComponentMessage(new ChatComponentText(message)); + world.setBlockMetadataWithNotify(x, y, z, newMeta, 2); + } + return true; + } } diff --git a/src/main/java/techreborn/compat/CompatManager.java b/src/main/java/techreborn/compat/CompatManager.java index f8d7b00a3..036312a6a 100644 --- a/src/main/java/techreborn/compat/CompatManager.java +++ b/src/main/java/techreborn/compat/CompatManager.java @@ -18,7 +18,7 @@ public class CompatManager { public static boolean isIC2Loaded = false; public static boolean isIC2ClassicLoaded = false; public static boolean isClassicEnet = false; - public static boolean isGrecgTechLoaded = false; + public static boolean isGregTechLoaded = false; public CompatManager() { isIC2Loaded = Loader.isModLoaded("IC2"); @@ -30,7 +30,7 @@ public class CompatManager { isClassicEnet = true; } if(Loader.isModLoaded("gregtech")){ - isGrecgTechLoaded = true; + isGregTechLoaded = true; } registerCompact(CompatModuleWaila.class, "Waila"); diff --git a/src/main/java/techreborn/init/ModBlocks.java b/src/main/java/techreborn/init/ModBlocks.java index 59fcd3831..77de0c6c5 100644 --- a/src/main/java/techreborn/init/ModBlocks.java +++ b/src/main/java/techreborn/init/ModBlocks.java @@ -125,6 +125,7 @@ public class ModBlocks { playerDetector = new BlockPlayerDetector(); GameRegistry.registerBlock(playerDetector, ItemBlockPlayerDetector.class, "playerDetector"); + GameRegistry.registerTileEntity(TilePlayerDectector.class, "TilePlayerDectectorTR"); MachineCasing = new BlockMachineCasing(Material.rock); GameRegistry.registerBlock(MachineCasing, ItemBlockMachineCasing.class, "machinecasing"); diff --git a/src/main/java/techreborn/tiles/TilePlayerDectector.java b/src/main/java/techreborn/tiles/TilePlayerDectector.java new file mode 100644 index 000000000..4f7e9c61e --- /dev/null +++ b/src/main/java/techreborn/tiles/TilePlayerDectector.java @@ -0,0 +1,93 @@ +package techreborn.tiles; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import techreborn.powerSystem.TilePowerAcceptor; + +import java.util.Iterator; + + +public class TilePlayerDectector extends TilePowerAcceptor { + + boolean redstone = false; + public String owenerUdid = ""; + + public TilePlayerDectector() { + super(1); + } + + @Override + public double getMaxPower() { + return 10000; + } + + @Override + public boolean canAcceptEnergy(ForgeDirection direction) { + return true; + } + + @Override + public boolean canProvideEnergy(ForgeDirection direction) { + return false; + } + + @Override + public double getMaxOutput() { + return 0; + } + + @Override + public double getMaxInput() { + return 32; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0){ + boolean lastRedstone = redstone; + redstone = false; + if(canUseEnergy(50)){ + Iterator tIterator = super.worldObj.playerEntities.iterator(); + while (tIterator.hasNext()) { + EntityPlayer player = (EntityPlayer) tIterator.next(); + if (player.getDistanceSq((double) super.xCoord + 0.5D, (double) super.yCoord + 0.5D, (double) super.zCoord + 0.5D) <= 256.0D) { + if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0){//ALL + redstone = true; + } else if (blockMetadata == 1){//Others + if(!owenerUdid.isEmpty() && !owenerUdid.equals(player.getUniqueID().toString())){ + redstone = true; + } + } else {//You + if(!owenerUdid.isEmpty() &&owenerUdid.equals(player.getUniqueID().toString())){ + redstone = true; + } + } + } + } + useEnergy(50); + } + if(lastRedstone != redstone){ + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); + } + } + } + + public boolean isProvidingPower(){ + return redstone; + } + + @Override + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + owenerUdid = tag.getString("ownerID"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) { + super.writeToNBT(tag); + tag.setString("ownerID", owenerUdid); + } +}