aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/tileentities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities')
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java1
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java468
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityAdvPooCollector.java12
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java12
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java15
5 files changed, 489 insertions, 19 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
index bb7004350d..c3670ef959 100644
--- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
+++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
@@ -7,6 +7,7 @@ import gtPlusPlus.core.block.general.BlockSuperLight.TileEntitySuperLight;
import gtPlusPlus.core.block.machine.Machine_SuperJukebox.TileEntitySuperJukebox;
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.tileentities.general.*;
+import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler;
import gtPlusPlus.core.tileentities.machines.*;
import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner;
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java
new file mode 100644
index 0000000000..eda0c65e46
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java
@@ -0,0 +1,468 @@
+package gtPlusPlus.core.tileentities.general.redstone;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+import gtPlusPlus.api.interfaces.IToolable;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.minecraft.EntityUtils;
+import net.minecraft.block.Block;
+import net.minecraft.init.Blocks;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.EnumSkyBlock;
+import net.minecraft.world.IBlockAccess;
+
+public abstract class TileEntityRedstoneHandler extends TileEntity implements IToolable {
+
+ private final int mTileType;
+ private BlockPos mTilePos;
+ private boolean mRequiresUpdate = false;
+ private Long mStartTime;
+ private Byte mRedstoneLevel;
+
+ public boolean mLightMode = false;
+ public float mLightValue = 0;
+
+ /**
+ * Sets the Redstone Handler Type.
+ * @param aTileType - A type of the handler designated by an int. 0 = receiver, 1 = emitter, 2 = both, anything else = nothing.
+ */
+ public TileEntityRedstoneHandler(int aTileType) {
+ mTileType = aTileType;
+ registerTileEntity();
+ }
+
+ private void registerTileEntity() {
+ if (!EntityUtils.isTileEntityRegistered(getTileEntityClass(), getTileEntityNameForRegistration())) {
+ GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration());
+ }
+ }
+
+ protected abstract Class<? extends TileEntity> getTileEntityClass();
+
+ protected abstract String getTileEntityNameForRegistration();
+
+ public Block getBlock() {
+ return mTilePos != null ? mTilePos.getBlockAtPos() : Blocks.redstone_block;
+ }
+
+ public final boolean isLight() {
+ return mLightMode;
+ }
+
+ public final float getLightBrightness() {
+ if (!isLight()) {
+ return 0;
+ }
+ else {
+ return mLightValue;
+ }
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound aNBT) {
+ mStartTime = aNBT.getLong("mStartTime");
+ mInvName = aNBT.getString("mInvName");
+ mLightValue = aNBT.getFloat("mLightValue");
+ mLightMode = aNBT.getBoolean("mLightMode");
+ mRedstoneLevel = aNBT.getByte("mRedstoneLevel");
+ super.readFromNBT(aNBT);
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound aNBT) {
+ aNBT.setInteger("mTileType", mTileType);
+ aNBT.setLong("mStartTime", mStartTime);
+ aNBT.setString("mInvName", mInvName);
+ aNBT.setFloat("mLightValue", getLightBrightness());
+ aNBT.setBoolean("mLightMode", isLight());
+ aNBT.setByte("mRedstoneLevel", mRedstoneLevel);
+ super.writeToNBT(aNBT);
+ }
+
+
+ private boolean mHasUpdatedRecently = false;
+
+ private final boolean init() {
+ if (mTilePos == null) {
+ try {
+ mTilePos = new BlockPos(this);
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+ if (mStartTime == null) {
+ try {
+ mStartTime = System.currentTimeMillis();
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+ return true;
+ }
+ private Long mLastUpdate;
+ private String mInvName = "";
+
+ @Override
+ public void updateEntity() {
+ //Handle init
+ if (!init()) {
+ return;
+ }
+ if (mRequiresUpdate || mLastUpdate == null) {
+ mRequiresUpdate = false;
+ mHasUpdatedRecently = true;
+ mLastUpdate = System.currentTimeMillis();
+ if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()/0.0625f) {
+ mTilePos.getBlockAtPos().setLightLevel(getLightBrightness()/0.0625f);
+ mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.0625f));
+ mTilePos.world.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord);
+ Logger.INFO("Updating Light");
+ }
+ mTilePos.world.scheduleBlockUpdate(xCoord, yCoord, zCoord, mTilePos.getBlockAtPos(), 1);
+ markDirty();
+ }
+ if (Utils.getMillisSince(mLastUpdate, System.currentTimeMillis()) >= 5000) {
+ if (mHasUpdatedRecently) {
+ mHasUpdatedRecently = false;
+ this.markForUpdate();
+ }
+ }
+
+ if (Utils.getMillisSince(mStartTime, System.currentTimeMillis()) % 50 == 0) {
+
+ }
+
+
+
+ super.updateEntity();
+ }
+
+ public final void markForUpdate() {
+ mRequiresUpdate = true;
+ }
+
+ public final boolean hasUpdatedRecently() {
+ return mHasUpdatedRecently;
+ }
+
+ @Override
+ public int getBlockMetadata() {
+ return super.getBlockMetadata();
+ }
+
+ @Override
+ public void markDirty() {
+ super.markDirty();
+ }
+
+ @Override
+ public boolean canUpdate() {
+ return true;
+ }
+
+ public void setRedstoneState(boolean aRedstoneActive) {
+
+ }
+
+ public void setCurrentTextureArray(IIcon[] aTextures) {
+
+ }
+
+ /**
+ * Used to see if one of the blocks next to you or your block is getting power from a neighboring block. Used by
+ * items like TNT or Doors so they don't have redstone going straight into them. Args: x, y, z
+ */
+ public boolean isGettingIndirectlyPowered() {
+ if (mTilePos == null) {
+ return false;
+ }
+ return mTilePos.world.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
+ }
+
+ public int getStrongestIndirectPower() {
+ if (mTilePos == null) {
+ return 0;
+ }
+ return mTilePos.world.getStrongestIndirectPower(xCoord, yCoord, zCoord);
+ }
+
+ /**
+ * Gets the power level from a certain block face. Args: x, y, z, direction
+ */
+ public int getIndirectPowerForSide(int aSide) {
+ if (mTilePos == null || aSide <0 || aSide > 5) {
+ return 0;
+ }
+ return mTilePos.world.getIndirectPowerLevelTo(xCoord, yCoord, zCoord, aSide);
+ }
+
+ /**
+ * Returns the highest redstone signal strength powering the given block. Args: X, Y, Z.
+ */
+ public int getBlockPowerInput() {
+ if (mTilePos == null) {
+ return 0;
+ }
+ return mTilePos.world.getBlockPowerInput(xCoord, yCoord, zCoord);
+ }
+
+ /**
+ * Determine if this block can make a redstone connection on the side provided,
+ * Useful to control which sides are inputs and outputs for redstone wires.
+ *
+ * Side:
+ * -1: UP
+ * 0: NORTH
+ * 1: EAST
+ * 2: SOUTH
+ * 3: WEST
+ *
+ * @param world The current world
+ * @param x X Position
+ * @param y Y Position
+ * @param z Z Position
+ * @param side The side that is trying to make the connection
+ * @return True to make the connection
+ */
+ public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
+ if (mTilePos == null) {
+ return false;
+ }
+ return canAcceptRedstoneSignal() || canSupplyRedstoneSignal();
+ }
+
+ /**
+ * Called to determine whether to allow the a block to handle its own indirect power rather than using the default rules.
+ * @param world The world
+ * @param x The x position of this block instance
+ * @param y The y position of this block instance
+ * @param z The z position of this block instance
+ * @param side The INPUT side of the block to be powered - ie the opposite of this block's output side
+ * @return Whether Block#isProvidingWeakPower should be called when determining indirect power
+ */
+ public boolean shouldCheckWeakPower(IBlockAccess world, int x, int y, int z, int side) {
+ if (mTilePos == null) {
+ return false;
+ }
+ return getBlock().isNormalCube();
+ }
+
+ /**
+ * If this block should be notified of weak changes.
+ * Weak changes are changes 1 block away through a solid block.
+ * Similar to comparators.
+ *
+ * @param world The current world
+ * @param x X Position
+ * @param y Y position
+ * @param z Z position
+ * @param side The side to check
+ * @return true To be notified of changes
+ */
+ public boolean getWeakChanges(IBlockAccess world, int x, int y, int z) {
+ if (mTilePos == null) {
+ return false;
+ }
+ return false;
+ }
+
+
+ /**
+ * Override this to change the level of redstone output.
+ * @return
+ */
+ public int getRedstoneLevel() {
+ if (mTilePos == null || mRedstoneLevel == null) {
+ return 0;
+ }
+ else {
+ if (canSupplyRedstoneSignal()) {
+ if (this.hasUpdatedRecently()) {
+ int aInputPower = getInputPowerLevel();
+ mRedstoneLevel = (byte) ((aInputPower >= 0 && aInputPower <= 127) ? aInputPower : 0);
+ }
+ return mRedstoneLevel;
+ }
+ }
+ return 0;
+ }
+
+
+ public boolean providesWeakPower() {
+ return isProvidingPower();
+ }
+
+ public boolean providesStrongPower() {
+ return isProvidingPower();
+ }
+
+
+ /**
+ * Returns the amount of week power this block is providing to a side.
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param side
+ * @return
+ */
+ public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
+ if (!providesWeakPower()) {
+ return 0;
+ }
+ return getOutputPowerLevel();
+ }
+ /**
+ * Returns the amount of strong power this block is providing to a side.
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param side
+ * @return
+ */
+ public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
+ if (!providesStrongPower()) {
+ return 0;
+ }
+ return getOutputPowerLevel();
+ }
+
+
+
+
+
+
+
+ /*
+ * Alk's Simplified Redstone Handling functions (Fuck redstone)
+ */
+
+ /**
+ *
+ * @return - Does this Block supply redstone signal at all?
+ */
+ public final boolean isPowered() {
+ return canAcceptRedstoneSignal() && getInputPowerLevel() > 0;
+ }
+
+ /**
+ *
+ * @return - Can this Block provide redstone signal at all?
+ */
+ public final boolean isProvidingPower() {
+ return canSupplyRedstoneSignal() && getOutputPowerLevel() > 0;
+ }
+
+ /**
+ *
+ * @return - (0-15) Redstone Output signal level
+ */
+ public final int getOutputPowerLevel() {
+ return getRedstoneLevel();
+ }
+
+ /**
+ *
+ * @return (0-15) Redstone Input Signal level
+ */
+ public final int getInputPowerLevel() {
+ return getBlockPowerInput();
+ }
+
+ /**
+ *
+ * @return - Does this Tile Entity support outputting redstone?
+ */
+ public final boolean canSupplyRedstoneSignal() {
+ return mTileType == 1 || mTileType == 2;
+ }
+
+ /**
+ *
+ * @return - Does this Tile Entity support inputting redstone?
+ */
+ public final boolean canAcceptRedstoneSignal() {
+ return mTileType == 0 || mTileType == 2;
+ }
+
+
+ @Override
+ public boolean isScrewdriverable() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onScrewdriverLMB() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onScrewdriverRMB() {
+ return false;
+ }
+
+
+ @Override
+ public boolean isWrenchable() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onWrenchLMB() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onWrenchRMB() {
+ return false;
+ }
+
+
+ @Override
+ public boolean isMalletable() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onMalletLMB() {
+ return false;
+ }
+
+
+ @Override
+ public boolean onMalletRMB() {
+ return false;
+ }
+
+
+ public void setCustomName(String displayName) {
+ this.mInvName = displayName;
+ }
+
+ public String getCustomName() {
+ return this.mInvName;
+ }
+
+ public String getInventoryName() {
+ return this.hasCustomInventoryName() ? this.mInvName : "container.redstone.generic";
+ }
+
+ public boolean hasCustomInventoryName() {
+ return (this.mInvName != null) && !this.mInvName.equals("");
+ }
+
+
+
+
+
+
+}
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityAdvPooCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityAdvPooCollector.java
index 18954f12b6..6bb4c932dc 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityAdvPooCollector.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityAdvPooCollector.java
@@ -1,6 +1,5 @@
package gtPlusPlus.core.tileentities.machines;
-import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.item.chemistry.AgriculturalChem;
import gtPlusPlus.core.util.math.MathUtils;
@@ -15,7 +14,6 @@ import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
@@ -132,17 +130,17 @@ public class TileEntityAdvPooCollector extends TileEntityBaseFluidCollector {
}
@Override
- public Item itemToSpawnInWorldIfTankIsFull() {
+ public ItemStack itemToSpawnInWorldIfTankIsFull() {
int a = MathUtils.randInt(0, 75);
- Item aItem = null;
+ ItemStack aItem = null;
if (a <= 30) {
- aItem = AgriculturalChem.dustDirt;
+ aItem = ItemUtils.getSimpleStack(AgriculturalChem.dustDirt);
}
else if (a <= 40) {
- aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustManureByproducts", 1).getItem();
+ aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustManureByproducts", 1);
}
else if (a <= 55) {
- aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1).getItem();
+ aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1);
}
return aItem;
}
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java
index 78b8f74799..cdae4cf829 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java
@@ -2,7 +2,6 @@ package gtPlusPlus.core.tileentities.machines;
import java.util.List;
-import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.minecraft.BTF_FluidTank;
import gtPlusPlus.api.objects.minecraft.BlockPos;
@@ -11,7 +10,6 @@ import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import net.minecraft.entity.item.EntityItem;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@@ -208,9 +206,11 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem
this.tank.fill(FluidUtils.getFluidStack(fluidToProvide(), aFluidAmount), true);
}
else {
- ItemStack aDirtStack = ItemUtils.getSimpleStack(itemToSpawnInWorldIfTankIsFull());
- if (aDirtStack != null)
- if (!this.mInventory.addItemStack(aDirtStack)) {
+ ItemStack aDirtStack = ItemUtils.getSimpleStack(itemToSpawnInWorldIfTankIsFull(), 1);
+ if (!ItemUtils.checkForInvalidItems(aDirtStack)) {
+ return;
+ }
+ if (!this.mInventory.addItemStack(aDirtStack)) {
EntityItem entity = new EntityItem(worldObj, xCoord, yCoord+1.5, zCoord, aDirtStack);
worldObj.spawnEntityInWorld(entity);
}
@@ -230,7 +230,7 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem
public abstract Fluid fluidToProvide();
- public abstract Item itemToSpawnInWorldIfTankIsFull();
+ public abstract ItemStack itemToSpawnInWorldIfTankIsFull();
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java
index f6570c6cc6..25348a31f8 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java
@@ -12,7 +12,6 @@ import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityMooshroom;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.IAnimals;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
@@ -53,7 +52,11 @@ public class TileEntityPooCollector extends TileEntityBaseFluidCollector {
}
else {
return false;
+ }
+ if (!ItemUtils.checkForInvalidItems(aPoop)) {
+ return false;
}
+
//Add poop to world
//Logger.INFO("Adding animal waste for "+aPooMaker.getCommandSenderName());
@@ -123,17 +126,17 @@ public class TileEntityPooCollector extends TileEntityBaseFluidCollector {
}
@Override
- public Item itemToSpawnInWorldIfTankIsFull() {
+ public ItemStack itemToSpawnInWorldIfTankIsFull() {
int a = MathUtils.randInt(0, 100);
- Item aItem = null;
+ ItemStack aItem = null;
if (a <= 30) {
- aItem = AgriculturalChem.dustDirt;
+ aItem = ItemUtils.getSimpleStack(AgriculturalChem.dustDirt);
}
else if (a <= 40) {
- aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1).getItem();
+ aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1);
}
else if (a <= 55) {
- aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1).getItem();
+ aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1);
}
return aItem;
}