aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-02-27 21:52:02 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-02-27 21:52:02 +1000
commit47ff638d276f5f926640b224e443bdccfd7b8506 (patch)
tree2b39067caab27d5bf93e6b8bbb84e6e3eb342d98 /src/Java/miscutil/core
parent7711c80664fdfa703b5e60e62af437655da783ae (diff)
downloadGT5-Unofficial-47ff638d276f5f926640b224e443bdccfd7b8506.tar.gz
GT5-Unofficial-47ff638d276f5f926640b224e443bdccfd7b8506.tar.bz2
GT5-Unofficial-47ff638d276f5f926640b224e443bdccfd7b8506.zip
Pushing more things to Git which weren't there.
ToroiseGit doesn't auto add new files to be pushed/committed unless you manually add them to a commit. :(
Diffstat (limited to 'src/Java/miscutil/core')
-rw-r--r--src/Java/miscutil/core/block/antigrief/TowerDevice.java265
-rw-r--r--src/Java/miscutil/core/tileentities/TileEntityReverter.java309
-rw-r--r--src/Java/miscutil/core/util/Log.java29
-rw-r--r--src/Java/miscutil/core/waila/IWailaInfoProvider.java19
-rw-r--r--src/Java/miscutil/core/waila/IWailaNBTProvider.java8
-rw-r--r--src/Java/miscutil/core/waila/WailaCompat.java323
6 files changed, 953 insertions, 0 deletions
diff --git a/src/Java/miscutil/core/block/antigrief/TowerDevice.java b/src/Java/miscutil/core/block/antigrief/TowerDevice.java
new file mode 100644
index 0000000000..aea1d40921
--- /dev/null
+++ b/src/Java/miscutil/core/block/antigrief/TowerDevice.java
@@ -0,0 +1,265 @@
+package miscutil.core.block.antigrief;
+
+import static miscutil.core.block.ModBlocks.blockGriefSaver;
+
+import java.util.List;
+import java.util.Random;
+
+import miscutil.core.creativetabs.AddToCreativeTab;
+import miscutil.core.lib.Strings;
+import miscutil.core.tileentities.TileEntityReverter;
+import miscutil.core.util.Utils;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+public class TowerDevice extends Block {
+ private static IIcon TEX_ANTIBUILDER;
+ public static final int META_ANTIBUILDER = 9;
+ public TowerDevice()
+ {
+ super(Material.wood);
+ setHardness(10.0F);
+ setResistance(35.0F);
+ setStepSound(Block.soundTypeWood);
+ setCreativeTab(AddToCreativeTab.tabMachines);
+ }
+
+ public int tickRate()
+ {
+ return 15;
+ }
+
+ public IIcon getIcon(int side, int meta)
+ {
+ return TEX_ANTIBUILDER;
+ }
+
+ @SideOnly(Side.CLIENT)
+ public void registerBlockIcons(IIconRegister par1IconRegister)
+ {
+ TEX_ANTIBUILDER = par1IconRegister.registerIcon(Strings.MODID + ":" + "blockAntiGrief");
+ }
+
+ public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
+ {
+ par3List.add(new ItemStack(par1, 1, 9));
+ }
+
+ public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
+ {
+ int meta = par1World.getBlockMetadata(x, y, z);
+ return false;
+ }
+
+ public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ)
+ {
+ int meta = world.getBlockMetadata(x, y, z);
+ return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ);
+ }
+
+ public float getBlockHardness(World world, int x, int y, int z)
+ {
+ int meta = world.getBlockMetadata(x, y, z);
+ return super.getBlockHardness(world, x, y, z);
+ }
+
+ public static boolean areNearbyLockBlocks(World world, int x, int y, int z)
+ {
+ boolean locked = false;
+ for (int dx = x - 2; dx <= x + 2; dx++) {
+ for (int dy = y - 2; dy <= y + 2; dy++) {
+ for (int dz = z - 2; dz <= z + 2; dz++) {
+ if ((world.getBlock(dx, dy, dz) == blockGriefSaver) && (world.getBlockMetadata(dx, dy, dz) == 4)) {
+ locked = true;
+ }
+ }
+ }
+ }
+ return locked;
+ }
+
+ public static void unlockBlock(World par1World, int x, int y, int z)
+ {
+ Block thereBlockID = par1World.getBlock(x, y, z);
+ int thereBlockMeta = par1World.getBlockMetadata(x, y, z);
+ if ((thereBlockID == blockGriefSaver) || (thereBlockMeta == 4))
+ {
+ changeToBlockMeta(par1World, x, y, z, 5);
+ par1World.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "random.click", 0.3F, 0.6F);
+ }
+ }
+
+ private static void changeToBlockMeta(World par1World, int x, int y, int z, int meta)
+ {
+ Block thereBlockID = par1World.getBlock(x, y, z);
+ if ((thereBlockID == blockGriefSaver))
+ {
+ par1World.setBlock(x, y, z, thereBlockID, meta, 3);
+ par1World.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
+ par1World.notifyBlocksOfNeighborChange(x, y, z, thereBlockID);
+ }
+ }
+
+ public void onBlockAdded(World par1World, int x, int y, int z)
+ {
+ int meta = par1World.getBlockMetadata(x, y, z);
+ if (!par1World.isRemote) {
+
+ }
+ }
+
+ public void onNeighborBlockChange(World par1World, int x, int y, int z, Block myBlockID)
+ {
+ int meta = par1World.getBlockMetadata(x, y, z);
+ if (!par1World.isRemote)
+ {
+
+ }
+ }
+
+ public void updateTick(World par1World, int x, int y, int z, Random par5Random)
+ {
+ if (!par1World.isRemote)
+ {
+ int meta = par1World.getBlockMetadata(x, y, z);
+ }
+ }
+
+ private void letsBuild(World par1World, int x, int y, int z)
+ {
+
+ }
+
+ private boolean isInactiveTrapCharged(World par1World, int x, int y, int z)
+ {
+ return false;
+ }
+
+ private boolean isReactorReady(World world, int x, int y, int z)
+ {
+ if ((world.getBlock(x, y + 1, z) != Blocks.redstone_block) ||
+ (world.getBlock(x, y - 1, z) != Blocks.redstone_block) ||
+ (world.getBlock(x + 1, y, z) != Blocks.redstone_block) ||
+ (world.getBlock(x - 1, y, z) != Blocks.redstone_block) ||
+ (world.getBlock(x, y, z + 1) != Blocks.redstone_block) ||
+ (world.getBlock(x, y, z - 1) != Blocks.redstone_block)) {
+ return false;
+ }
+ return true;
+ }
+
+ @SideOnly(Side.CLIENT)
+ public void randomDisplayTick(World par1World, int x, int y, int z, Random par5Random)
+ {
+ int meta = par1World.getBlockMetadata(x, y, z);
+ if ((meta == 3) || (meta == 1) || (meta == 9)) {
+ for (int i = 0; i < 1; i++) {
+ sparkle(par1World, x, y, z, par5Random);
+ }
+ }
+ }
+
+ public void sparkle(World world, int x, int y, int z, Random rand)
+ {
+ double offset = 0.0625D;
+ for (int side = 0; side < 6; side++)
+ {
+ double rx = x + rand.nextFloat();
+ double ry = y + rand.nextFloat();
+ double rz = z + rand.nextFloat();
+ if ((side == 0) && (!world.getBlock(x, y + 1, z).isOpaqueCube())) {
+ ry = y + 1 + offset;
+ }
+ if ((side == 1) && (!world.getBlock(x, y - 1, z).isOpaqueCube())) {
+ ry = y + 0 - offset;
+ }
+ if ((side == 2) && (!world.getBlock(x, y, z + 1).isOpaqueCube())) {
+ rz = z + 1 + offset;
+ }
+ if ((side == 3) && (!world.getBlock(x, y, z - 1).isOpaqueCube())) {
+ rz = z + 0 - offset;
+ }
+ if ((side == 4) && (!world.getBlock(x + 1, y, z).isOpaqueCube())) {
+ rx = x + 1 + offset;
+ }
+ if ((side == 5) && (!world.getBlock(x - 1, y, z).isOpaqueCube())) {
+ rx = x + 0 - offset;
+ }
+ if ((rx < x) || (rx > x + 1) || (ry < 0.0D) || (ry > y + 1) || (rz < z) || (rz > z + 1)) {
+ world.spawnParticle("reddust", rx, ry, rz, 0.0D, 0.0D, 0.0D);
+ }
+ }
+ }
+
+ public static void checkAndActivateVanishBlock(World world, int x, int y, int z)
+ {
+ Block thereID = world.getBlock(x, y, z);
+ int thereMeta = world.getBlockMetadata(x, y, z);
+ }
+
+ public static void changeToActiveVanishBlock(World par1World, int x, int y, int z, int meta)
+ {
+ changeToBlockMeta(par1World, x, y, z, meta);
+ par1World.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "random.pop", 0.3F, 0.6F);
+
+ Block thereBlockID = par1World.getBlock(x, y, z);
+ par1World.scheduleBlockUpdate(x, y, z, thereBlockID, getTickRateFor(thereBlockID, meta, par1World.rand));
+ }
+
+ private static int getTickRateFor(Block thereBlockID, int meta, Random rand)
+ {
+ return 15;
+ }
+
+ public int getLightValue(IBlockAccess world, int x, int y, int z)
+ {
+ Block blockID = world.getBlock(x, y, z);
+ int meta = world.getBlockMetadata(x, y, z);
+ if (blockID != this) {
+ return 0;
+ }
+ return 10;
+ }
+
+ public boolean hasTileEntity(int metadata)
+ {
+ return (metadata == 0);
+ }
+
+ public TileEntity createTileEntity(World world, int metadata)
+ {
+ if (metadata == 0) {
+ Utils.LOG_INFO("I have been created. [Antigriefer]"+this.getLocalizedName());
+ return new TileEntityReverter();
+ }
+ return null;
+ }
+
+ public Item getItemDropped(int meta, Random par2Random, int par3)
+ {
+ switch (meta)
+ {
+ case 0:
+ return null;
+ }
+ return Item.getItemFromBlock(this);
+ }
+
+ public int damageDropped(int meta)
+ {
+ return meta;
+ }
+}
diff --git a/src/Java/miscutil/core/tileentities/TileEntityReverter.java b/src/Java/miscutil/core/tileentities/TileEntityReverter.java
new file mode 100644
index 0000000000..4ee8eeed4b
--- /dev/null
+++ b/src/Java/miscutil/core/tileentities/TileEntityReverter.java
@@ -0,0 +1,309 @@
+package miscutil.core.tileentities;
+
+import java.util.Random;
+
+import miscutil.core.block.ModBlocks;
+import net.minecraft.block.Block;
+import net.minecraft.init.Blocks;
+import net.minecraft.tileentity.TileEntity;
+
+
+
+public class TileEntityReverter extends TileEntity
+{
+ private static final int REVERT_CHANCE = 10;
+ public int radius = 16;
+ public int diameter = 8 * this.radius + 4;
+ public double requiredPlayerRange = 64.0D;
+ public Random rand = new Random();
+ private int tickCount;
+ private boolean slowScan;
+ private int ticksSinceChange;
+ private Block[] blockData;
+ private byte[] metaData;
+
+ public boolean canUpdate(){
+ return true;
+ }
+
+ public void updateEntity()
+ {
+ if (anyPlayerInRange())
+ {
+ this.tickCount += 1;
+ if (this.worldObj.isRemote)
+ {
+ double var1 = this.xCoord + this.worldObj.rand.nextFloat();
+ double var3 = this.yCoord + this.worldObj.rand.nextFloat();
+ double var5 = this.zCoord + this.worldObj.rand.nextFloat();
+
+ this.worldObj.spawnParticle("enchantmenttable", var1, var3, var5, 0.0D, 0.0D, 0.0D);
+ if (this.rand.nextInt(5) == 0)
+ {
+ makeRandomOutline();
+ makeRandomOutline();
+ makeRandomOutline();
+ }
+ }
+ else
+ {
+ if ((this.blockData == null) || (this.metaData == null))
+ {
+ captureBlockData();
+ this.slowScan = true;
+ }
+ if ((!this.slowScan) || (this.tickCount % 20 == 0)) {
+ if (scanAndRevertChanges())
+ {
+ this.slowScan = false;
+ this.ticksSinceChange = 0;
+ }
+ else
+ {
+ this.ticksSinceChange += 1;
+ if (this.ticksSinceChange > 20) {
+ this.slowScan = true;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ this.blockData = null;
+ this.metaData = null;
+
+ this.tickCount = 0;
+ }
+ }
+
+ private void makeRandomOutline()
+ {
+ makeOutline(this.rand.nextInt(12));
+ }
+
+ private void makeOutline(int outline)
+ {
+ double sx = this.xCoord;
+ double sy = this.yCoord;
+ double sz = this.zCoord;
+
+ double dx = this.xCoord;
+ double dy = this.yCoord;
+ double dz = this.zCoord;
+ switch (outline)
+ {
+ case 0:
+ sx -= this.radius;
+ dx -= this.radius;
+ sz -= this.radius;
+ dz += this.radius + 1;
+ case 8:
+ sx -= this.radius;
+ dx += this.radius + 1;
+ sz -= this.radius;
+ dz -= this.radius;
+ break;
+ case 1:
+ case 9:
+ sx -= this.radius;
+ dx -= this.radius;
+ sz -= this.radius;
+ dz += this.radius + 1;
+ break;
+ case 2:
+ case 10:
+ sx -= this.radius;
+ dx += this.radius + 1;
+ sz += this.radius + 1;
+ dz += this.radius + 1;
+ break;
+ case 3:
+ case 11:
+ sx += this.radius + 1;
+ dx += this.radius + 1;
+ sz -= this.radius;
+ dz += this.radius + 1;
+ break;
+ case 4:
+ sx -= this.radius;
+ dx -= this.radius;
+ sz -= this.radius;
+ dz -= this.radius;
+ break;
+ case 5:
+ sx += this.radius + 1;
+ dx += this.radius + 1;
+ sz -= this.radius;
+ dz -= this.radius;
+ break;
+ case 6:
+ sx += this.radius + 1;
+ dx += this.radius + 1;
+ sz += this.radius + 1;
+ dz += this.radius + 1;
+ break;
+ case 7:
+ sx -= this.radius;
+ dx -= this.radius;
+ sz += this.radius + 1;
+ dz += this.radius + 1;
+ }
+ switch (outline)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ sy += this.radius + 1;
+ dy += this.radius + 1;
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ sy -= this.radius;
+ dy += this.radius + 1;
+ break;
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ sy -= this.radius;
+ dy -= this.radius;
+ }
+ if (this.rand.nextBoolean()) {
+ drawParticleLine(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, dx, dy, dz);
+ } else {
+ drawParticleLine(sx, sy, sz, this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D);
+ }
+ drawParticleLine(sx, sy, sz, dx, dy, dz);
+ }
+
+ protected void drawParticleLine(double srcX, double srcY, double srcZ, double destX, double destY, double destZ)
+ {
+ int particles = 16;
+ for (int i = 0; i < particles; i++)
+ {
+ double trailFactor = i / (particles - 1.0D);
+
+ double tx = srcX + (destX - srcX) * trailFactor + this.rand.nextFloat() * 0.005D;
+ double ty = srcY + (destY - srcY) * trailFactor + this.rand.nextFloat() * 0.005D;
+ double tz = srcZ + (destZ - srcZ) * trailFactor + this.rand.nextFloat() * 0.005D;
+ this.worldObj.spawnParticle("portal", tx, ty, tz, 0.0D, 0.0D, 0.0D);
+ }
+ }
+
+ private boolean scanAndRevertChanges()
+ {
+ int index = 0;
+ boolean reverted = false;
+ for (int x = -this.radius; x <= this.radius; x++) {
+ for (int y = -this.radius; y <= this.radius; y++) {
+ for (int z = -this.radius; z <= this.radius; z++)
+ {
+ Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z);
+ byte meta = (byte)this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, this.zCoord + z);
+ if (this.blockData[index] != blockID) {
+ if (revertBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z, blockID, meta, this.blockData[index], this.metaData[index]))
+ {
+ reverted = true;
+ }
+ else
+ {
+ this.blockData[index] = blockID;
+ this.metaData[index] = meta;
+ }
+ }
+ index++;
+ }
+ }
+ }
+ return reverted;
+ }
+
+ private boolean revertBlock(int x, int y, int z, Block thereBlockID, byte thereMeta, Block replaceBlockID, byte replaceMeta)
+ {
+ /*if ((thereBlockID == Blocks.air) && (!replaceBlockID.getMaterial().blocksMovement()))
+ {
+ System.out.println("Not replacing block " + replaceBlockID + " because it doesn't block movement");
+
+ return false;
+ }*/
+ if (isUnrevertable(thereBlockID, thereMeta, replaceBlockID, replaceMeta)) {
+ return false;
+ }
+ if (this.rand.nextInt(5) == 0)
+ {
+ if (replaceBlockID != Blocks.air)
+ {
+ //replaceBlockID = null;
+ replaceMeta = 4;
+ }
+ this.worldObj.setBlock(x, y, z, replaceBlockID, replaceMeta, 2);
+ if (thereBlockID == Blocks.air)
+ {
+ this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(replaceBlockID) + (replaceMeta << 12));
+ }
+ else if (replaceBlockID == Blocks.air)
+ {
+ this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(thereBlockID) + (thereMeta << 12));
+ thereBlockID.dropBlockAsItem(this.worldObj, x, y, z, thereMeta, 0);
+ }
+ }
+ return true;
+ }
+
+ private boolean isUnrevertable(Block thereBlockID, byte thereMeta, Block replaceBlockID, byte replaceMeta)
+ {
+ if ((thereBlockID == ModBlocks.blockGriefSaver) || (replaceBlockID == ModBlocks.blockGriefSaver)) {
+ return true;
+ }
+ /*if (((thereBlockID == towerTranslucent) && (thereMeta != 4)) || ((replaceBlockID == towerTranslucent) && (replaceMeta != 4))) {
+ return true;
+ }*/
+ if ((thereBlockID == Blocks.redstone_lamp) && (replaceBlockID == Blocks.lit_redstone_lamp)) {
+ return true;
+ }
+ if ((thereBlockID == Blocks.lit_redstone_lamp) && (replaceBlockID == Blocks.redstone_lamp)) {
+ return true;
+ }
+ /*if ((thereBlockID == Blocks.water) || (replaceBlockID == Blocks.flowing_water)) {
+ return true;
+ }
+ if ((thereBlockID == Blocks.flowing_water) || (replaceBlockID == Blocks.water)) {
+ return true;
+ }*/
+ if (replaceBlockID == Blocks.tnt) {
+ return true;
+ }
+ return false;
+ }
+
+ private void captureBlockData()
+ {
+ this.blockData = new Block[this.diameter * this.diameter * this.diameter];
+ this.metaData = new byte[this.diameter * this.diameter * this.diameter];
+
+ int index = 0;
+ for (int x = -this.radius; x <= this.radius; x++) {
+ for (int y = -this.radius; y <= this.radius; y++) {
+ for (int z = -this.radius; z <= this.radius; z++)
+ {
+ Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z);
+ int meta = this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, this.zCoord + z);
+
+ this.blockData[index] = blockID;
+ this.metaData[index] = ((byte)meta);
+
+ index++;
+ }
+ }
+ }
+ }
+
+ public boolean anyPlayerInRange()
+ {
+ return this.worldObj.getClosestPlayer(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, this.requiredPlayerRange) != null;
+ }
+}
diff --git a/src/Java/miscutil/core/util/Log.java b/src/Java/miscutil/core/util/Log.java
new file mode 100644
index 0000000000..ea69618ec7
--- /dev/null
+++ b/src/Java/miscutil/core/util/Log.java
@@ -0,0 +1,29 @@
+package crazypants.enderio;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public final class Log
+{
+ public static final Logger LOGGER = LogManager.getLogger("EnderIO");
+
+ public static void warn(String msg)
+ {
+ LOGGER.warn(msg);
+ }
+
+ public static void error(String msg)
+ {
+ LOGGER.error(msg);
+ }
+
+ public static void info(String msg)
+ {
+ LOGGER.info(msg);
+ }
+
+ public static void debug(String msg)
+ {
+ LOGGER.debug(msg);
+ }
+}
diff --git a/src/Java/miscutil/core/waila/IWailaInfoProvider.java b/src/Java/miscutil/core/waila/IWailaInfoProvider.java
new file mode 100644
index 0000000000..90b96d4bc0
--- /dev/null
+++ b/src/Java/miscutil/core/waila/IWailaInfoProvider.java
@@ -0,0 +1,19 @@
+package crazypants.enderio.waila;
+
+import java.text.NumberFormat;
+import java.util.List;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.world.World;
+
+public abstract interface IWailaInfoProvider
+{
+ public static final int BIT_BASIC = 1;
+ public static final int BIT_COMMON = 2;
+ public static final int BIT_DETAILED = 4;
+ public static final int ALL_BITS = 7;
+ public static final NumberFormat fmt = ;
+
+ public abstract void getWailaInfo(List<String> paramList, EntityPlayer paramEntityPlayer, World paramWorld, int paramInt1, int paramInt2, int paramInt3);
+
+ public abstract int getDefaultDisplayMask(World paramWorld, int paramInt1, int paramInt2, int paramInt3);
+}
diff --git a/src/Java/miscutil/core/waila/IWailaNBTProvider.java b/src/Java/miscutil/core/waila/IWailaNBTProvider.java
new file mode 100644
index 0000000000..5b4f7dbe2b
--- /dev/null
+++ b/src/Java/miscutil/core/waila/IWailaNBTProvider.java
@@ -0,0 +1,8 @@
+package crazypants.enderio.waila;
+
+import net.minecraft.nbt.NBTTagCompound;
+
+public abstract interface IWailaNBTProvider
+{
+ public abstract void getData(NBTTagCompound paramNBTTagCompound);
+}
diff --git a/src/Java/miscutil/core/waila/WailaCompat.java b/src/Java/miscutil/core/waila/WailaCompat.java
new file mode 100644
index 0000000000..1f494f89bd
--- /dev/null
+++ b/src/Java/miscutil/core/waila/WailaCompat.java
@@ -0,0 +1,323 @@
+package crazypants.enderio.waila;
+
+import crazypants.enderio.EnderIO;
+import crazypants.enderio.TileEntityEio;
+import crazypants.enderio.block.BlockDarkSteelAnvil;
+import crazypants.enderio.conduit.ConduitUtil;
+import crazypants.enderio.conduit.IConduit;
+import crazypants.enderio.conduit.IConduitBundle;
+import crazypants.enderio.conduit.liquid.AbstractTankConduit;
+import crazypants.enderio.conduit.liquid.ConduitTank;
+import crazypants.enderio.conduit.power.IPowerConduit;
+import crazypants.enderio.fluid.Fluids;
+import crazypants.enderio.gui.IAdvancedTooltipProvider;
+import crazypants.enderio.gui.IResourceTooltipProvider;
+import crazypants.enderio.gui.TooltipAddera;
+import crazypants.enderio.machine.IIoConfigurable;
+import crazypants.enderio.machine.IoMode;
+import crazypants.enderio.machine.capbank.TileCapBank;
+import crazypants.enderio.machine.power.TileCapacitorBank;
+import crazypants.enderio.power.IInternalPoweredTile;
+import crazypants.util.IFacade;
+import crazypants.util.Lang;
+import java.text.NumberFormat;
+import java.util.List;
+import mcp.mobius.waila.api.ITaggedList;
+import mcp.mobius.waila.api.IWailaConfigHandler;
+import mcp.mobius.waila.api.IWailaDataAccessor;
+import mcp.mobius.waila.api.IWailaDataProvider;
+import mcp.mobius.waila.api.IWailaRegistrar;
+import mcp.mobius.waila.api.impl.ConfigHandler;
+import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.MovingObjectPosition;
+import net.minecraft.world.World;
+import net.minecraft.world.WorldSettings;
+import net.minecraft.world.chunk.IChunkProvider;
+import net.minecraft.world.storage.WorldInfo;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.FluidStack;
+
+public class WailaCompat
+ implements IWailaDataProvider
+{
+ private class WailaWorldWrapper
+ extends World
+ {
+ private World wrapped;
+
+ private WailaWorldWrapper(World wrapped)
+ {
+ super(wrapped.getWorldInfo().getWorldName(), wrapped.provider, new WorldSettings(wrapped.getWorldInfo()), wrapped.theProfiler);
+ this.wrapped = wrapped;
+ this.isRemote = wrapped.isRemote;
+ }
+
+ public Block getBlock(int x, int y, int z)
+ {
+ Block block = this.wrapped.getBlock(x, y, z);
+ if ((block instanceof IFacade)) {
+ return ((IFacade)block).getFacade(this.wrapped, x, y, z, -1);
+ }
+ return block;
+ }
+
+ public int getBlockMetadata(int x, int y, int z)
+ {
+ Block block = this.wrapped.getBlock(x, y, z);
+ if ((block instanceof IFacade)) {
+ return ((IFacade)block).getFacadeMetadata(this.wrapped, x, y, z, -1);
+ }
+ return this.wrapped.getBlockMetadata(x, y, z);
+ }
+
+ public TileEntity getTileEntity(int x, int y, int z)
+ {
+ int meta = getBlockMetadata(x, y, z);
+ Block block = getBlock(x, y, z);
+ if ((block == null) || (!block.hasTileEntity(meta))) {
+ return null;
+ }
+ TileEntity te = block.createTileEntity(this, meta);
+ if (te == null) {
+ return null;
+ }
+ te.setWorldObj(this);
+ te.xCoord = x;
+ te.yCoord = y;
+ te.zCoord = z;
+
+ return te;
+ }
+
+ protected IChunkProvider createChunkProvider()
+ {
+ return null;
+ }
+
+ protected int func_152379_p()
+ {
+ return 0;
+ }
+
+ public Entity getEntityByID(int p_73045_1_)
+ {
+ return null;
+ }
+ }
+
+ public static final WailaCompat INSTANCE = new WailaCompat();
+ private static IWailaDataAccessor _accessor = null;
+
+ public static void load(IWailaRegistrar registrar)
+ {
+ registrar.registerStackProvider(INSTANCE, IFacade.class);
+ registrar.registerStackProvider(INSTANCE, BlockDarkSteelAnvil.class);
+
+ registrar.registerHeadProvider(INSTANCE, Block.class);
+ registrar.registerBodyProvider(INSTANCE, Block.class);
+ registrar.registerTailProvider(INSTANCE, Block.class);
+
+ registrar.registerNBTProvider(INSTANCE, TileEntityEio.class);
+
+ registrar.registerSyncedNBTKey("controllerStoredEnergyRF", TileCapacitorBank.class);
+
+
+
+
+ ConfigHandler.instance().addConfig("Ender IO", "facades.hidden", Lang.localize("waila.config.hiddenfacades"));
+ IWailaInfoProvider.fmt.setMaximumFractionDigits(1);
+ }
+
+ public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config)
+ {
+ MovingObjectPosition pos = accessor.getPosition();
+ if (config.getConfig("facades.hidden"))
+ {
+ if ((accessor.getBlock() instanceof IFacade))
+ {
+ if (((accessor.getTileEntity() instanceof IConduitBundle)) && (ConduitUtil.isFacadeHidden((IConduitBundle)accessor.getTileEntity(), accessor.getPlayer()))) {
+ return null;
+ }
+ IFacade bundle = (IFacade)accessor.getBlock();
+ Block facade = bundle.getFacade(accessor.getWorld(), pos.blockX, pos.blockY, pos.blockZ, accessor.getSide().ordinal());
+ if (facade != null)
+ {
+ ItemStack ret = facade.getPickBlock(pos, new WailaWorldWrapper(accessor.getWorld(), null), pos.blockX, pos.blockY, pos.blockZ);
+ return ret;
+ }
+ }
+ }
+ else if ((accessor.getBlock() instanceof BlockDarkSteelAnvil)) {
+ return accessor.getBlock().getPickBlock(accessor.getPosition(), accessor.getWorld(), accessor.getPosition().blockX, accessor.getPosition().blockY, accessor.getPosition().blockZ);
+ }
+ return null;
+ }
+
+ public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
+ {
+ return currenttip;
+ }
+
+ public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
+ {
+ _accessor = accessor;
+
+ EntityPlayer player = accessor.getPlayer();
+ MovingObjectPosition pos = accessor.getPosition();
+ int x = pos.blockX;int y = pos.blockY;int z = pos.blockZ;
+ World world = accessor.getWorld();
+ Block block = world.getBlock(x, y, z);
+ TileEntity te = world.getTileEntity(x, y, z);
+ Item item = Item.getItemFromBlock(block);
+ if (((te instanceof IIoConfigurable)) && (block == accessor.getBlock()))
+ {
+ IIoConfigurable machine = (IIoConfigurable)te;
+ ForgeDirection side = accessor.getSide();
+ IoMode mode = machine.getIoMode(side);
+ currenttip.add(EnumChatFormatting.YELLOW + String.format(Lang.localize("gui.machine.side"), new Object[] { EnumChatFormatting.WHITE + Lang.localize(new StringBuilder().append("gui.machine.side.").append(side.name().toLowerCase()).toString()) }));
+
+ currenttip.add(EnumChatFormatting.YELLOW + String.format(Lang.localize("gui.machine.ioMode"), new Object[] { mode.colorLocalisedName() }));
+ }
+ if ((block instanceof IWailaInfoProvider))
+ {
+ IWailaInfoProvider info = (IWailaInfoProvider)block;
+ if ((block instanceof IAdvancedTooltipProvider))
+ {
+ int mask = info.getDefaultDisplayMask(world, pos.blockX, pos.blockY, pos.blockZ);
+ boolean basic = (mask & 0x1) == 1;
+ boolean common = (mask & 0x2) == 2;
+ boolean detailed = (mask & 0x4) == 4;
+
+ IAdvancedTooltipProvider adv = (IAdvancedTooltipProvider)block;
+ if (common) {
+ adv.addCommonEntries(itemStack, player, currenttip, false);
+ }
+ if ((TooltipAddera.showAdvancedTooltips()) && (detailed)) {
+ adv.addDetailedEntries(itemStack, player, currenttip, false);
+ } else if (detailed) {
+ TooltipAddera.addShowDetailsTooltip(currenttip);
+ }
+ if ((!TooltipAddera.showAdvancedTooltips()) && (basic)) {
+ adv.addBasicEntries(itemStack, player, currenttip, false);
+ }
+ }
+ else if ((block instanceof IResourceTooltipProvider))
+ {
+ TooltipAddera.addInformation((IResourceTooltipProvider)block, itemStack, player, currenttip);
+ }
+ if (currenttip.size() > 0) {
+ currenttip.add("");
+ }
+ info.getWailaInfo(currenttip, player, world, pos.blockX, pos.blockY, pos.blockZ);
+ }
+ else if ((block instanceof IAdvancedTooltipProvider))
+ {
+ TooltipAddera.addInformation((IAdvancedTooltipProvider)block, itemStack, player, currenttip, false);
+ }
+ else if ((item instanceof IAdvancedTooltipProvider))
+ {
+ TooltipAddera.addInformation((IAdvancedTooltipProvider)item, itemStack, player, currenttip, false);
+ }
+ else if ((block instanceof IResourceTooltipProvider))
+ {
+ TooltipAddera.addInformation((IResourceTooltipProvider)block, itemStack, player, currenttip);
+ }
+ boolean removeRF = false;
+ if (((te instanceof IInternalPoweredTile)) && (block == accessor.getBlock()) && (accessor.getNBTData().hasKey("storedEnergyRF")) && (!(te instanceof TileCapBank)))
+ {
+ removeRF = true;
+ IInternalPoweredTile power = (IInternalPoweredTile)te;
+ if (power.displayPower())
+ {
+ if (currenttip.size() > 4) {
+ currenttip.add("");
+ }
+ int stored = (accessor.getTileEntity() instanceof TileCapacitorBank) ? power.getEnergyStored() : accessor.getNBTData().getInteger("storedEnergyRF");
+ int max = power.getMaxEnergyStored();
+
+ currenttip.add(String.format("%s%s%s / %s%s%s RF", new Object[] { EnumChatFormatting.WHITE, IWailaInfoProvider.fmt.format(stored), EnumChatFormatting.RESET, EnumChatFormatting.WHITE, IWailaInfoProvider.fmt.format(max), EnumChatFormatting.RESET }));
+ }
+ }
+ else if (((te instanceof IConduitBundle)) && (itemStack != null) && (itemStack.getItem() == EnderIO.itemPowerConduit))
+ {
+ removeRF = true;
+ NBTTagCompound nbtRoot = accessor.getNBTData();
+ short nbtVersion = nbtRoot.getShort("nbtVersion");
+ NBTTagList conduitTags = (NBTTagList)nbtRoot.getTag("conduits");
+ if (conduitTags != null) {
+ for (int i = 0; i < conduitTags.tagCount(); i++)
+ {
+ NBTTagCompound conduitTag = conduitTags.getCompoundTagAt(i);
+ IConduit conduit = ConduitUtil.readConduitFromNBT(conduitTag, nbtVersion);
+ if ((conduit instanceof IPowerConduit)) {
+ currenttip.add(String.format("%s%s%s / %s%s%s RF", new Object[] { EnumChatFormatting.WHITE, IWailaInfoProvider.fmt.format(((IPowerConduit)conduit).getEnergyStored()), EnumChatFormatting.RESET, EnumChatFormatting.WHITE, IWailaInfoProvider.fmt.format(((IConduitBundle)te).getMaxEnergyStored()), EnumChatFormatting.RESET }));
+ }
+ }
+ }
+ }
+ else if (((te instanceof IConduitBundle)) && (itemStack != null) && (itemStack.getItem() == EnderIO.itemLiquidConduit))
+ {
+ NBTTagCompound nbtRoot = accessor.getNBTData();
+ short nbtVersion = nbtRoot.getShort("nbtVersion");
+ NBTTagList conduitTags = (NBTTagList)nbtRoot.getTag("conduits");
+ if (conduitTags != null) {
+ for (int i = 0; i < conduitTags.tagCount(); i++)
+ {
+ NBTTagCompound conduitTag = conduitTags.getCompoundTagAt(i);
+ IConduit conduit = ConduitUtil.readConduitFromNBT(conduitTag, nbtVersion);
+ if ((conduit instanceof AbstractTankConduit))
+ {
+ AbstractTankConduit tankConduit = (AbstractTankConduit)conduit;
+ ConduitTank tank = tankConduit.getTank();
+ if (tank.getFluid() == null) {
+ break;
+ }
+ String lockedStr = tankConduit.isFluidTypeLocked() ? Lang.localize("itemLiquidConduit.lockedWaila") : "";
+ String fluidName = tank.getFluid().getLocalizedName();
+ int fluidAmount = tank.getFluidAmount();
+ if (fluidAmount > 0) {
+ currenttip.add(String.format("%s%s%s%s %s%s%s %s", new Object[] { lockedStr, EnumChatFormatting.WHITE, fluidName, EnumChatFormatting.RESET, EnumChatFormatting.WHITE, IWailaInfoProvider.fmt.format(fluidAmount), EnumChatFormatting.RESET, Fluids.MB() }));
+ } else if (tankConduit.isFluidTypeLocked()) {
+ currenttip.add(String.format("%s%s%s%s", new Object[] { lockedStr, EnumChatFormatting.WHITE, fluidName, EnumChatFormatting.RESET }));
+ }
+ break;
+ }
+ }
+ }
+ }
+ if (removeRF) {
+ ((ITaggedList)currenttip).removeEntries("RFEnergyStorage");
+ }
+ return currenttip;
+ }
+
+ public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
+ {
+ return currenttip;
+ }
+
+ public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z)
+ {
+ if ((te instanceof IWailaNBTProvider)) {
+ ((IWailaNBTProvider)te).getData(tag);
+ }
+ tag.setInteger("x", x);
+ tag.setInteger("y", y);
+ tag.setInteger("z", z);
+ return tag;
+ }
+
+ public static NBTTagCompound getNBTData()
+ {
+ return _accessor.getNBTData();
+ }
+}