From e8e899fb8ec40fc2a8094e3a1f65527af23b11e4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 14:47:39 +1000 Subject: + Added some basis for new redstone things. --- .../redstone/TileEntityRedstoneHandler.java | 398 +++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java (limited to 'src/Java/gtPlusPlus/core/tileentities/general') 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..fbd5f4280d --- /dev/null +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -0,0 +1,398 @@ +package gtPlusPlus.core.tileentities.general.redstone; + +import gtPlusPlus.api.interfaces.IToolable; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.Utils; +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 class TileEntityRedstoneHandler extends TileEntity implements IToolable { + + private final int mTileType; + private BlockPos mTilePos; + private boolean mRequiresUpdate = false; + private Long mStartTime; + private int 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; + } + + public Block getBlock() { + return mTilePos != null ? mTilePos.getBlockAtPos() : Blocks.redstone_block; + } + + + @Override + public void readFromNBT(NBTTagCompound aNBT) { + mStartTime = aNBT.getLong("mStartTime"); + mInvName = aNBT.getString("mInvName"); + mLightValue = aNBT.getInteger("mLightValue"); + super.readFromNBT(aNBT); + } + + @Override + public void writeToNBT(NBTTagCompound aNBT) { + aNBT.setInteger("mTileType", mTileType); + aNBT.setLong("mStartTime", mStartTime); + aNBT.setString("mInvName", mInvName); + aNBT.setInteger("mLightValue", mLightValue); + 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) { + mRequiresUpdate = false; + mHasUpdatedRecently = true; + mLastUpdate = System.currentTimeMillis(); + if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != mLightValue) { + mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); + } + markDirty(); + } + if (Utils.getMillisSince(mLastUpdate, System.currentTimeMillis()) >= 5000) { + if (mHasUpdatedRecently) { + mHasUpdatedRecently = false; + } + } + + 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 getBlock().canConnectRedstone(world, xCoord, yCoord, zCoord, side); + } + + /** + * 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().shouldCheckWeakPower(world, xCoord, yCoord, zCoord, side); + } + + /** + * 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 getBlock().getWeakChanges(world, xCoord, yCoord, zCoord); + } + + + /** + * Override this to change the level of redstone output. + * @return + */ + public int getRedstoneLevel() { + if (mTilePos == null) { + return 0; + } + if (canSupplyRedstoneSignal()) { + int aInputPower = getInputPowerLevel(); + if (aInputPower > 0) { + return aInputPower; + } + } + return 0; + } + + + + + + + + + + /* + * 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(""); + } + + public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) { + // TODO Auto-generated method stub + return 0; + } + + public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) { + // TODO Auto-generated method stub + return 0; + } + + + + + + +} -- cgit From f6a126e4467c5bf7ab72249c7fc55df3bc574d94 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 15:39:02 +1000 Subject: + Added TexturePackages. $ More work on redstone systems. --- .../api/objects/minecraft/TexturePackage.java | 55 ++++++++++ src/Java/gtPlusPlus/core/block/ModBlocks.java | 3 + .../general/redstone/BlockGenericRedstone.java | 25 ++++- .../redstone/BlockGenericRedstoneDetector.java | 113 +++++++++++---------- .../redstone/TileEntityRedstoneHandler.java | 67 ++++++++++-- .../blocks/redstone/redstone_meter/top.png | Bin 0 -> 822 bytes 6 files changed, 195 insertions(+), 68 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java create mode 100644 src/resources/assets/miscutils/textures/blocks/redstone/redstone_meter/top.png (limited to 'src/Java/gtPlusPlus/core/tileentities/general') diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java b/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java new file mode 100644 index 0000000000..e610f8fdf0 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java @@ -0,0 +1,55 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.LinkedHashMap; +import java.util.Set; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.util.IIcon; + +public class TexturePackage { + + private AutoMap mAnimationArray = new AutoMap(); + + public IIcon getFrame(int aFrame) { + if (aFrame < 0 || aFrame >= mAnimationArray.size()) { + return mAnimationArray.get(0); + } + return mAnimationArray.get(aFrame); + } + + public boolean addFrame(IIcon aFrame) { + if (aFrame != null) { + return mAnimationArray.add(aFrame); + } + return false; + } + + public boolean addFrames(AutoMap aFrames) { + for (IIcon h : aFrames) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + public boolean addFrames(LinkedHashMap aFrames) { + for (IIcon h : aFrames.values()) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + public boolean addFrames(Set aFrames) { + for (IIcon h : aFrames) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + +} diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index 2b04356f52..8471c13351 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -11,6 +11,7 @@ import gtPlusPlus.core.block.general.LightGlass; 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.machine.CircuitProgrammer; import gtPlusPlus.core.block.machine.DecayablesChest; import gtPlusPlus.core.block.machine.FishTrap; @@ -140,6 +141,8 @@ public final class ModBlocks { blockCustomJukebox = new Machine_SuperJukebox(); blockPooCollector = new Machine_PooCollector(); + + new BlockGenericRedstoneDetector(); } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index 14dac32b63..3197d149c8 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -53,13 +53,18 @@ public abstract class BlockGenericRedstone extends BlockContainer { * A map of the textures used for this blocks. The key is the meta, then each internal map holds textures tied to each forge direction. Do not use unknown direction. * @return */ - public abstract HashMap> getTextureArray(); + public HashMap> getTextureArray() { + return mTextures; + } + + public abstract void generateTextureArray(final IIconRegister iicon); @Override @SideOnly(Side.CLIENT) - public final void registerBlockIcons(final IIconRegister p_149651_1_) { - this.blockIcon = p_149651_1_.registerIcon("redstone_block"); + public final void registerBlockIcons(final IIconRegister iicon) { + generateTextureArray(iicon); + this.blockIcon = iicon.registerIcon("redstone_block"); } @@ -305,8 +310,18 @@ public abstract class BlockGenericRedstone extends BlockContainer { * Ticks the block if it's been scheduled */ public void updateTick(World aWorld, int aX, int aY, int aZ, Random p_149674_5_) { - if (!aWorld.isRemote && !aWorld.isBlockIndirectlyGettingPowered(aX, aY, aZ)) { - // aWorld.setBlock(aX, aY, aZ, Blocks.redstone_lamp, 0, 2); + TileEntityRedstoneHandler aTile = getTileEntity(aWorld, aX, aY, aZ); + // Client side handling + if (aTile != null) { + this.setLightLevel(aTile.getLightBrightness()); + } + // Only continue on server + if (aWorld.isRemote) { + return; + } + if (aTile != null) { + if (aTile.isGettingIndirectlyPowered()) { + } } } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java index 3e7816f83a..7728b29a7c 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java @@ -1,17 +1,21 @@ package gtPlusPlus.core.block.general.redstone; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Random; +import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler; -import net.minecraft.block.Block; +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.world.IBlockAccess; +import net.minecraft.util.IIcon; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class BlockGenericRedstoneDetector extends BlockGenericRedstone { @@ -32,81 +36,86 @@ public class BlockGenericRedstoneDetector extends BlockGenericRedstone { } @Override - public void registerBlockIcons(IIconRegister p_149651_1_) { - // TODO Auto-generated method stub - super.registerBlockIcons(p_149651_1_); - } - - @Override - public int getLightValue() { - // TODO Auto-generated method stub - return super.getLightValue(); + public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List aList) { + aList.add(ItemUtils.getSimpleStack(this)); } - @Override - public int isProvidingWeakPower(IBlockAccess p_149709_1_, int p_149709_2_, int p_149709_3_, int p_149709_4_, - int p_149709_5_) { - return 0; - } @Override - public boolean canProvidePower() { - return false; - } - - @Override - public int isProvidingStrongPower(IBlockAccess p_149748_1_, int p_149748_2_, int p_149748_3_, int p_149748_4_, - int p_149748_5_) { - return 0; + public void updateTick(World aWorld, int aX, int aY, int aZ, Random aRand) { + super.updateTick(aWorld, aX, aY, aZ, aRand); } @Override - public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_) { + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { // TODO Auto-generated method stub - super.getSubBlocks(p_149666_1_, p_149666_2_, p_149666_3_); + return ItemUtils.getSimpleStack(this).getItem(); } @Override - public int getLightValue(IBlockAccess world, int x, int y, int z) { + 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 super.getLightValue(world, x, y, z); + return ItemUtils.getSimpleStack(this).getItem(); } @Override - public boolean shouldCheckWeakPower(IBlockAccess world, int x, int y, int z, int side) { - // TODO Auto-generated method stub - return super.shouldCheckWeakPower(world, x, y, z, side); - } + protected ItemStack createStackedBlock(int p_149644_1_) { + return ItemUtils.simpleMetaStack(this, p_149644_1_, 1); + } + + public void generateTextureArray(final IIconRegister iicon) { + HashMap> aTextures = new HashMap>(); - @Override - public void updateTick(World aWorld, int aX, int aY, int aZ, Random aRand) { - TileEntity aThisTile = aWorld.getTileEntity(aX, aY, aZ); - if (aThisTile != null) { - TileEntityRedstoneHandler aRedstoneTile = (TileEntityRedstoneHandler) aThisTile; - aRedstoneTile.setCurrentTextureArray(null); + //New Block for Each Meta + int aMeta = 0; + { + HashMap aTempMap = new HashMap(); + 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); } - - 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 null; - } - - @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 null; + public IIcon getIcon(int side, int meta) { + HashMap 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 - protected ItemStack createStackedBlock(int p_149644_1_) { - // TODO Auto-generated method stub - return null; + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + ArrayList aDrops = new ArrayList(); + aDrops.add(ItemUtils.getSimpleStack(this)); + return aDrops; } } diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index fbd5f4280d..163c4453b6 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -17,7 +17,9 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { private BlockPos mTilePos; private boolean mRequiresUpdate = false; private Long mStartTime; - private int mLightValue = 0; + + public boolean mLightMode = false; + public int mLightValue = 0; /** * Sets the Redstone Handler Type. @@ -30,13 +32,26 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { public Block getBlock() { return mTilePos != null ? mTilePos.getBlockAtPos() : Blocks.redstone_block; } + + public final boolean isLight() { + return mLightMode; + } + public final int getLightBrightness() { + if (!isLight()) { + return 0; + } + else { + return mLightValue; + } + } @Override public void readFromNBT(NBTTagCompound aNBT) { mStartTime = aNBT.getLong("mStartTime"); mInvName = aNBT.getString("mInvName"); mLightValue = aNBT.getInteger("mLightValue"); + mLightMode = aNBT.getBoolean("mLightMode"); super.readFromNBT(aNBT); } @@ -46,6 +61,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { aNBT.setLong("mStartTime", mStartTime); aNBT.setString("mInvName", mInvName); aNBT.setInteger("mLightValue", mLightValue); + aNBT.setBoolean("mLightMode", mLightMode); super.writeToNBT(aNBT); } @@ -250,6 +266,45 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { } + 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(); + } @@ -379,16 +434,6 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { public boolean hasCustomInventoryName() { return (this.mInvName != null) && !this.mInvName.equals(""); } - - public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) { - // TODO Auto-generated method stub - return 0; - } - - public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) { - // TODO Auto-generated method stub - return 0; - } diff --git a/src/resources/assets/miscutils/textures/blocks/redstone/redstone_meter/top.png b/src/resources/assets/miscutils/textures/blocks/redstone/redstone_meter/top.png new file mode 100644 index 0000000000..ba45c43891 Binary files /dev/null and b/src/resources/assets/miscutils/textures/blocks/redstone/redstone_meter/top.png differ -- cgit From 70a0df8a68725c16f0c0b959639b8e82cbbcf3a0 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 17:44:13 +1000 Subject: % Work work --- src/Java/gtPlusPlus/core/block/ModBlocks.java | 4 +- .../general/redstone/BlockGenericRedstone.java | 24 ++- .../redstone/BlockGenericRedstoneDetector.java | 10 + .../general/redstone/BlockGenericRedstoneTest.java | 205 +++++++++++++++++++++ .../core/tileentities/ModTileEntities.java | 1 - .../redstone/TileEntityRedstoneHandler.java | 36 +++- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 61 ++++++ 7 files changed, 319 insertions(+), 22 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java (limited to 'src/Java/gtPlusPlus/core/tileentities/general') 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 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 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> aTextures = new HashMap>(); + + + //New Block for Each Meta + int aMeta = 0; + { + HashMap aTempMap = new HashMap(); + 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 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 getDrops(World world, int x, int y, int z, int metadata, int fortune) { + ArrayList aDrops = new ArrayList(); + 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 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; + } } -- cgit From af61708010aef717ecc3537fa115547acb9aa9c7 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 18:20:28 +1000 Subject: $ More fixes. --- .../general/redstone/BlockGenericRedstone.java | 8 +++-- .../general/redstone/BlockGenericRedstoneTest.java | 17 ++++++----- .../redstone/TileEntityRedstoneHandler.java | 16 +++++++--- .../core/util/minecraft/EntityUtils.java | 35 +++++++++++++++++++++- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 10 ++++--- .../common/items/MetaGeneratedGregtechTools.java | 14 --------- 6 files changed, 67 insertions(+), 33 deletions(-) (limited to 'src/Java/gtPlusPlus/core/tileentities/general') diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index a021a39ac8..65d89c0577 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -92,17 +92,19 @@ public abstract class BlockGenericRedstone extends BlockContainer { final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) world.getTileEntity(x, y, z); if (tile != null) { - if (tile.isScrewdriverable() || player.capabilities.isCreativeMode) { + if (tile.isScrewdriverable()) { if (ItemUtils.isToolScrewdriver(mHandStack)){ mDidTool = tile.onScrewdriverRMB(); + PlayerUtils.messagePlayer(player, "Adjusted Light level by 0.0625f. "+tile.getLightBrightness()); } } - if (tile.isMalletable() || player.capabilities.isCreativeMode) { + if (tile.isMalletable()) { if (ItemUtils.isToolMallet(mHandStack)){ mDidTool = tile.onMalletRMB(); + PlayerUtils.messagePlayer(player, "Light Mode active: "+mDidTool); } } - if (tile.isWrenchable() || player.capabilities.isCreativeMode) { + if (tile.isWrenchable()) { if (ItemUtils.isToolWrench(mHandStack)){ mDidTool = tile.onWrenchRMB(); } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java index f2a5c3f36a..ad59a83d0c 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java @@ -10,6 +10,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.world.explosions.ExplosionHandler; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @@ -50,15 +51,14 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onScrewdriverRMB() { - if (this.mLightValue + 1 <= 1) { - this.mLightValue += 1; + if (this.mLightValue + 0.0625f <= 1) { + this.mLightValue += 0.0625f; } else { this.mLightValue = 0; } - Logger.INFO("Screwdriver | "+this.getLightBrightness()); this.markForUpdate(); - return super.onScrewdriverRMB(); + return true; } @Override @@ -75,7 +75,8 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onMalletRMB() { this.mLightMode = Utils.invertBoolean(mLightMode); - return super.onMalletRMB(); + this.markForUpdate(); + return mLightMode; } @Override @@ -91,8 +92,10 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onWrenchRMB() { - // TODO Auto-generated method stub - return super.onWrenchRMB(); + Logger.INFO("Found Wrench"); + ExplosionHandler explode = new ExplosionHandler(); + explode.createExplosion(this.worldObj, null, this.xCoord, this.yCoord, this.zCoord, 1f, false, true); + return true; } @Override diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index 152790951a..43f2c15251 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -1,10 +1,16 @@ package gtPlusPlus.core.tileentities.general.redstone; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + 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 gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; @@ -33,7 +39,9 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT } private void registerTileEntity() { - GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration()); + if (!EntityUtils.isTileEntityRegistered(getTileEntityClass(), getTileEntityNameForRegistration())) { + GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration()); + } } protected abstract Class getTileEntityClass(); @@ -109,9 +117,9 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT mRequiresUpdate = false; mHasUpdatedRecently = true; mLastUpdate = System.currentTimeMillis(); - if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()) { - mTilePos.getBlockAtPos().setLightLevel(getLightBrightness()); - mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.625f)); + 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"); } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java index 839cb164cb..844bb0bcaf 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -1,10 +1,13 @@ package gtPlusPlus.core.util.minecraft; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; import cpw.mods.fml.common.registry.EntityRegistry; - +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.entity.*; import net.minecraft.entity.player.EntityPlayer; @@ -16,6 +19,7 @@ import net.minecraft.world.biome.BiomeGenBase; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import ic2.core.IC2Potion; import ic2.core.item.armor.ItemArmorHazmat; @@ -125,5 +129,34 @@ public class EntityUtils { public static void doDamage(Entity entity, DamageSource dmg, int i) { entity.attackEntityFrom(dmg, i); } + + public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) { + Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap"); + Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap"); + try { + Object o = aRegistry.get(null); + if (o != null) { + Map nameToClassMap = (Map) o; + if (!nameToClassMap.containsKey(aTileName)) { + o = aRegistry2.get(null); + if (o != null) { + Map classToNameMap = (Map) o; + if (!classToNameMap.containsKey(aTileClass)) { + return false; + } + else { + return true; + } + } + } + else { + return true; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index e266ee02d4..9617d12b66 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -30,6 +30,8 @@ import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration; import net.minecraft.block.Block; import net.minecraft.init.Items; @@ -1120,14 +1122,14 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01) { + if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { 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)) { + if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124 || aWrench.getItemDamage() == 7734)) { return true; } return false; @@ -1162,7 +1164,7 @@ public class ItemUtils { } public static boolean isToolHammer(ItemStack aHammer) { - if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) { + if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12 || aHammer.getItemDamage() == 7734)) { return true; } return false; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java index d228fdc04a..f6bbbfcabe 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java @@ -1,25 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.items; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; - import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.TC_Aspects; import gregtech.api.enums.ToolDictNames; -import gregtech.api.interfaces.IItemBehaviour; -import gregtech.api.items.GT_MetaBase_Item; import gregtech.api.items.GT_MetaGenerated_Tool; -import gregtech.api.util.GT_Log; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.enums.GregtechToolDictNames; import gtPlusPlus.xmod.gregtech.common.tools.TOOL_Gregtech_Choocher; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; public class MetaGeneratedGregtechTools extends GT_MetaGenerated_Tool { -- cgit From 60b9e2b720abca8908a1ac2a7f5767af08bccaf9 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:12:52 +1000 Subject: % Allowed Skookum Choocher as a valid Wrench and Hard Hammer. $ Fixed infinite loop between TE and Block functions. --- .../core/block/general/redstone/BlockGenericRedstone.java | 4 ++-- .../general/redstone/TileEntityRedstoneHandler.java | 11 +++-------- src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/Java/gtPlusPlus/core/tileentities/general') diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index 65d89c0577..b84c96be99 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -86,7 +86,7 @@ public abstract class BlockGenericRedstone extends BlockContainer { try { final ItemStack mHandStack = PlayerUtils.getItemStackInPlayersHand(world, player.getDisplayName()); final Item mHandItem = mHandStack.getItem(); - if (mHandItem instanceof GT_MetaGenerated_Tool_01) { + if (ItemUtils.isItemGregtechTool(mHandStack)) { Logger.INFO("Found Tool in players hand!"); @@ -250,7 +250,7 @@ public abstract class BlockGenericRedstone extends BlockContainer { if (aThis != null) { return aThis.shouldCheckWeakPower(world, x, y, z, side); } - return false; + return isNormalCube(); } @Override diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index 43f2c15251..fa2597eae9 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -1,16 +1,11 @@ package gtPlusPlus.core.tileentities.general.redstone; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - 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 gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; @@ -233,7 +228,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().canConnectRedstone(world, xCoord, yCoord, zCoord, side); + return canAcceptRedstoneSignal() || canSupplyRedstoneSignal(); } /** @@ -249,7 +244,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().shouldCheckWeakPower(world, xCoord, yCoord, zCoord, side); + return getBlock().isNormalCube(); } /** @@ -268,7 +263,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().getWeakChanges(world, xCoord, yCoord, zCoord); + return false; } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 9617d12b66..ae799baa2b 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -1122,7 +1122,9 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { + final Item aSkookum = ItemUtils.getItemFromFQRN("miscutils:gt.plusplus.metatool.01"); + final Class aSkookClass = aSkookum.getClass(); + if (aSkookClass.isInstance(mItem) || mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool || mItem == aSkookum) { return true; } return false; -- cgit From 079256e5324a6f72a08a77878685302f7b24dc58 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:23:59 +1000 Subject: $ Fixed another small infinite loop. (Redstone is fucking complicated, damn you Notch) --- .../general/redstone/TileEntityRedstoneHandler.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/Java/gtPlusPlus/core/tileentities/general') diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index fa2597eae9..eda0c65e46 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -20,6 +20,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT private BlockPos mTilePos; private boolean mRequiresUpdate = false; private Long mStartTime; + private Byte mRedstoneLevel; public boolean mLightMode = false; public float mLightValue = 0; @@ -66,6 +67,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT mInvName = aNBT.getString("mInvName"); mLightValue = aNBT.getFloat("mLightValue"); mLightMode = aNBT.getBoolean("mLightMode"); + mRedstoneLevel = aNBT.getByte("mRedstoneLevel"); super.readFromNBT(aNBT); } @@ -76,6 +78,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT aNBT.setString("mInvName", mInvName); aNBT.setFloat("mLightValue", getLightBrightness()); aNBT.setBoolean("mLightMode", isLight()); + aNBT.setByte("mRedstoneLevel", mRedstoneLevel); super.writeToNBT(aNBT); } @@ -272,15 +275,18 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT * @return */ public int getRedstoneLevel() { - if (mTilePos == null) { + if (mTilePos == null || mRedstoneLevel == null) { return 0; } - if (canSupplyRedstoneSignal()) { - int aInputPower = getInputPowerLevel(); - if (aInputPower > 0) { - return aInputPower; + else { + if (canSupplyRedstoneSignal()) { + if (this.hasUpdatedRecently()) { + int aInputPower = getInputPowerLevel(); + mRedstoneLevel = (byte) ((aInputPower >= 0 && aInputPower <= 127) ? aInputPower : 0); + } + return mRedstoneLevel; } - } + } return 0; } -- cgit