aboutsummaryrefslogtreecommitdiff
path: root/src/Java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java')
-rw-r--r--src/Java/gtPlusPlus/core/block/ModBlocks.java4
-rw-r--r--src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java24
-rw-r--r--src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java10
-rw-r--r--src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java205
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java1
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java36
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java61
7 files changed, 319 insertions, 22 deletions
diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java
index 8471c13351..b904b04556 100644
--- a/src/Java/gtPlusPlus/core/block/ModBlocks.java
+++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java
@@ -12,6 +12,7 @@ import gtPlusPlus.core.block.general.MiningExplosives;
import gtPlusPlus.core.block.general.PlayerDoors;
import gtPlusPlus.core.block.general.antigrief.BlockWitherProof;
import gtPlusPlus.core.block.general.redstone.BlockGenericRedstoneDetector;
+import gtPlusPlus.core.block.general.redstone.BlockGenericRedstoneTest;
import gtPlusPlus.core.block.machine.CircuitProgrammer;
import gtPlusPlus.core.block.machine.DecayablesChest;
import gtPlusPlus.core.block.machine.FishTrap;
@@ -141,8 +142,9 @@ public final class ModBlocks {
blockCustomJukebox = new Machine_SuperJukebox();
blockPooCollector = new Machine_PooCollector();
-
+
new BlockGenericRedstoneDetector();
+ new BlockGenericRedstoneTest();
}
diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java
index 3197d149c8..a021a39ac8 100644
--- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java
+++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java
@@ -10,10 +10,12 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
+import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.item.base.itemblock.ItemBlockMeta;
import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler;
import gtPlusPlus.core.util.minecraft.InventoryUtils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
@@ -86,20 +88,22 @@ public abstract class BlockGenericRedstone extends BlockContainer {
final Item mHandItem = mHandStack.getItem();
if (mHandItem instanceof GT_MetaGenerated_Tool_01) {
+ Logger.INFO("Found Tool in players hand!");
+
final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) world.getTileEntity(x, y, z);
if (tile != null) {
- if (tile.isScrewdriverable()) {
- if ((mHandItem.getDamage(mHandStack) == 22) || (mHandItem.getDamage(mHandStack) == 150)){
+ if (tile.isScrewdriverable() || player.capabilities.isCreativeMode) {
+ if (ItemUtils.isToolScrewdriver(mHandStack)){
mDidTool = tile.onScrewdriverRMB();
}
}
- if (tile.isMalletable()) {
- if ((mHandItem.getDamage(mHandStack) == 24) || (mHandItem.getDamage(mHandStack) == 154)){
+ if (tile.isMalletable() || player.capabilities.isCreativeMode) {
+ if (ItemUtils.isToolMallet(mHandStack)){
mDidTool = tile.onMalletRMB();
}
}
- if (tile.isWrenchable()) {
- if ((mHandItem.getDamage(mHandStack) == 26) || (mHandItem.getDamage(mHandStack) == 164)){
+ if (tile.isWrenchable() || player.capabilities.isCreativeMode) {
+ if (ItemUtils.isToolWrench(mHandStack)){
mDidTool = tile.onWrenchRMB();
}
}
@@ -129,17 +133,17 @@ public abstract class BlockGenericRedstone extends BlockContainer {
final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) aWorld.getTileEntity(aX, aY, aZ);
if (tile != null) {
if (tile.isScrewdriverable()) {
- if ((mHandItem.getDamage(mHandStack) == 22) || (mHandItem.getDamage(mHandStack) == 150)){
+ if (ItemUtils.isToolScrewdriver(mHandStack)){
mDidTool = tile.onScrewdriverLMB();
}
}
if (tile.isMalletable()) {
- if ((mHandItem.getDamage(mHandStack) == 24) || (mHandItem.getDamage(mHandStack) == 154)){
+ if (ItemUtils.isToolMallet(mHandStack)){
mDidTool = tile.onMalletLMB();
}
}
if (tile.isWrenchable()) {
- if ((mHandItem.getDamage(mHandStack) == 26) || (mHandItem.getDamage(mHandStack) == 164)){
+ if (ItemUtils.isToolWrench(mHandStack)){
mDidTool = tile.onWrenchLMB();
}
}
@@ -148,7 +152,7 @@ public abstract class BlockGenericRedstone extends BlockContainer {
}
catch (Throwable t) {}
- if (!mDidTool) {
+ if (!mDidTool && !aPlayer.capabilities.isCreativeMode) {
super.onBlockClicked(aWorld, aX, aY, aZ, aPlayer);
}
else {
diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java
index 7728b29a7c..43247110f1 100644
--- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java
+++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java
@@ -32,6 +32,16 @@ public class BlockGenericRedstoneDetector extends BlockGenericRedstone {
public class TileEntityRedstoneDetector extends TileEntityRedstoneHandler {
public TileEntityRedstoneDetector() {
super(0);
+ }
+
+ @Override
+ protected Class<? extends TileEntity> getTileEntityClass() {
+ return this.getClass();
+ }
+
+ @Override
+ protected String getTileEntityNameForRegistration() {
+ return "TileEntityRedstoneDetector";
}
}
diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java
new file mode 100644
index 0000000000..f2a5c3f36a
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java
@@ -0,0 +1,205 @@
+package gtPlusPlus.core.block.general.redstone;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.creativetab.CreativeTabs;
+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 net.minecraftforge.common.util.ForgeDirection;
+
+public class BlockGenericRedstoneTest extends BlockGenericRedstone {
+
+ public BlockGenericRedstoneTest() {
+ super("test", "Redstone Test");
+ setTickRandomly(true);
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world, int p_149915_2_) {
+ return new TileEntityRedstoneTest();
+ }
+
+ public class TileEntityRedstoneTest extends TileEntityRedstoneHandler {
+ public TileEntityRedstoneTest() {
+ super(2);
+ }
+
+ @Override
+ public boolean isScrewdriverable() {
+ return true;
+ }
+
+ @Override
+ public boolean onScrewdriverLMB() {
+ // TODO Auto-generated method stub
+ return super.onScrewdriverLMB();
+ }
+
+ @Override
+ public boolean onScrewdriverRMB() {
+ if (this.mLightValue + 1 <= 1) {
+ this.mLightValue += 1;
+ }
+ else {
+ this.mLightValue = 0;
+ }
+ Logger.INFO("Screwdriver | "+this.getLightBrightness());
+ this.markForUpdate();
+ return super.onScrewdriverRMB();
+ }
+
+ @Override
+ public boolean isMalletable() {
+ return true;
+ }
+
+ @Override
+ public boolean onMalletLMB() {
+ // TODO Auto-generated method stub
+ return super.onMalletLMB();
+ }
+
+ @Override
+ public boolean onMalletRMB() {
+ this.mLightMode = Utils.invertBoolean(mLightMode);
+ return super.onMalletRMB();
+ }
+
+ @Override
+ public boolean isWrenchable() {
+ return true;
+ }
+
+ @Override
+ public boolean onWrenchLMB() {
+ // TODO Auto-generated method stub
+ return super.onWrenchLMB();
+ }
+
+ @Override
+ public boolean onWrenchRMB() {
+ // TODO Auto-generated method stub
+ return super.onWrenchRMB();
+ }
+
+ @Override
+ protected Class<? extends TileEntity> getTileEntityClass() {
+ return this.getClass();
+ }
+
+ @Override
+ protected String getTileEntityNameForRegistration() {
+ // TODO Auto-generated method stub
+ return "TileEntityRedstoneTest";
+ }
+
+ @Override
+ public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
+ // TODO Auto-generated method stub
+ return super.isProvidingWeakPower(world, x, y, z, side);
+ }
+
+ @Override
+ public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
+ // TODO Auto-generated method stub
+ return super.isProvidingStrongPower(world, x, y, z, side);
+ }
+ }
+
+ @Override
+ public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List aList) {
+ aList.add(ItemUtils.getSimpleStack(this));
+ }
+
+
+ @Override
+ public void updateTick(World aWorld, int aX, int aY, int aZ, Random aRand) {
+ super.updateTick(aWorld, aX, aY, aZ, aRand);
+ }
+
+ @Override
+ public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) {
+ // TODO Auto-generated method stub
+ return ItemUtils.getSimpleStack(this).getItem();
+ }
+
+ @Override
+ public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) {
+ // TODO Auto-generated method stub
+ return ItemUtils.getSimpleStack(this).getItem();
+ }
+
+ @Override
+ protected ItemStack createStackedBlock(int p_149644_1_) {
+ return ItemUtils.simpleMetaStack(this, p_149644_1_, 1);
+ }
+
+ public void generateTextureArray(final IIconRegister iicon) {
+ HashMap<Integer, HashMap<ForgeDirection, IIcon>> aTextures = new HashMap<Integer, HashMap<ForgeDirection, IIcon>>();
+
+
+ //New Block for Each Meta
+ int aMeta = 0;
+ {
+ HashMap<ForgeDirection, IIcon> aTempMap = new HashMap<ForgeDirection, IIcon>();
+ aTempMap.put(ForgeDirection.UP, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTempMap.put(ForgeDirection.DOWN, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTempMap.put(ForgeDirection.NORTH, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTempMap.put(ForgeDirection.SOUTH, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTempMap.put(ForgeDirection.EAST, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTempMap.put(ForgeDirection.WEST, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top"));
+ aTextures.put(aMeta++, aTempMap);
+ }
+
+ }
+
+ @Override
+ public IIcon getIcon(int side, int meta) {
+ HashMap<ForgeDirection, IIcon> aTemp = getTextureArray().get(meta);
+ if (aTemp != null) {
+ IIcon aSide = aTemp.get(ForgeDirection.getOrientation(side));
+ if (aSide != null) {
+ return aSide;
+ }
+ else {
+ //Smart calculate missing sides
+ if (side <= 1) {
+ for (int ss = 0; ss < 2; ss++) {
+ aSide = aTemp.get(ForgeDirection.getOrientation(side));
+ if (aSide != null) {
+ return aSide;
+ }
+ }
+ }
+ for (int ss = 2; ss < 6; ss++) {
+ aSide = aTemp.get(ForgeDirection.getOrientation(side));
+ if (aSide != null) {
+ return aSide;
+ }
+ }
+ }
+ }
+ return blockIcon;
+ }
+
+ @Override
+ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
+ ArrayList<ItemStack> aDrops = new ArrayList<ItemStack>();
+ aDrops.add(ItemUtils.getSimpleStack(this));
+ return aDrops;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
index 5a0d2cc256..c3670ef959 100644
--- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
+++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java
@@ -32,7 +32,6 @@ public class ModTileEntities {
GameRegistry.registerTileEntity(TileEntityDecayablesChest.class, "TileDecayablesChest");
GameRegistry.registerTileEntity(TileEntitySuperJukebox.class, "TileEntitySuperJukebox");
GameRegistry.registerTileEntity(TileEntitySuperLight.class, "TileEntitySuperLight");
- GameRegistry.registerTileEntity(TileEntityRedstoneHandler.class, "TileEntityRedstoneHandler");
//Mod TEs
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java
index 163c4453b6..152790951a 100644
--- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java
+++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java
@@ -1,6 +1,8 @@
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 net.minecraft.block.Block;
@@ -11,7 +13,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
-public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
+public abstract class TileEntityRedstoneHandler extends TileEntity implements IToolable {
private final int mTileType;
private BlockPos mTilePos;
@@ -19,7 +21,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
private Long mStartTime;
public boolean mLightMode = false;
- public int mLightValue = 0;
+ public float mLightValue = 0;
/**
* Sets the Redstone Handler Type.
@@ -27,8 +29,17 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
*/
public TileEntityRedstoneHandler(int aTileType) {
mTileType = aTileType;
+ registerTileEntity();
}
+ private void registerTileEntity() {
+ 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;
}
@@ -37,7 +48,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
return mLightMode;
}
- public final int getLightBrightness() {
+ public final float getLightBrightness() {
if (!isLight()) {
return 0;
}
@@ -50,7 +61,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
public void readFromNBT(NBTTagCompound aNBT) {
mStartTime = aNBT.getLong("mStartTime");
mInvName = aNBT.getString("mInvName");
- mLightValue = aNBT.getInteger("mLightValue");
+ mLightValue = aNBT.getFloat("mLightValue");
mLightMode = aNBT.getBoolean("mLightMode");
super.readFromNBT(aNBT);
}
@@ -60,8 +71,8 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
aNBT.setInteger("mTileType", mTileType);
aNBT.setLong("mStartTime", mStartTime);
aNBT.setString("mInvName", mInvName);
- aNBT.setInteger("mLightValue", mLightValue);
- aNBT.setBoolean("mLightMode", mLightMode);
+ aNBT.setFloat("mLightValue", getLightBrightness());
+ aNBT.setBoolean("mLightMode", isLight());
super.writeToNBT(aNBT);
}
@@ -94,18 +105,23 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable {
if (!init()) {
return;
}
- if (mRequiresUpdate) {
+ if (mRequiresUpdate || mLastUpdate == null) {
mRequiresUpdate = false;
mHasUpdatedRecently = true;
mLastUpdate = System.currentTimeMillis();
- if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != mLightValue) {
- mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue);
- }
+ if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()) {
+ mTilePos.getBlockAtPos().setLightLevel(getLightBrightness());
+ mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.625f));
+ 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();
}
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
index d32ff4e160..e266ee02d4 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
@@ -13,6 +13,7 @@ import gregtech.api.enums.OrePrefixes;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
+import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.api.objects.minecraft.BlockPos;
@@ -1113,5 +1114,65 @@ public class ItemUtils {
}
return aDisplay;
}
+
+ public static boolean isItemGregtechTool(ItemStack aStack) {
+ if (aStack == null) {
+ return false;
+ }
+ final Item mItem = aStack.getItem();
+ if (mItem instanceof GT_MetaGenerated_Tool_01) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolWrench(ItemStack aWrench) {
+ if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolMallet(ItemStack aMallet) {
+ if (isItemGregtechTool(aMallet) && (aMallet.getItemDamage() == 14)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolScrewdriver(ItemStack aScrewdriver) {
+ if (isItemGregtechTool(aScrewdriver) && (aScrewdriver.getItemDamage() == 22 || aScrewdriver.getItemDamage() == 150)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolCrowbar(ItemStack aCrowbar) {
+ if (isItemGregtechTool(aCrowbar) && (aCrowbar.getItemDamage() == 20)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolWirecutters(ItemStack aWirecutters) {
+ if (isItemGregtechTool(aWirecutters) && (aWirecutters.getItemDamage() == 26)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolHammer(ItemStack aHammer) {
+ if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isToolSolderingIron(ItemStack aSoldering) {
+ if (isItemGregtechTool(aSoldering) && (aSoldering.getItemDamage() == 160)) {
+ return true;
+ }
+ return false;
+ }
}