diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-04-02 17:44:13 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-04-02 17:44:13 +1000 |
commit | 70a0df8a68725c16f0c0b959639b8e82cbbcf3a0 (patch) | |
tree | a532180e57e9172dba7fc03f3b7988c4fcd44fcd /src/Java/gtPlusPlus/core/tileentities | |
parent | f6a126e4467c5bf7ab72249c7fc55df3bc574d94 (diff) | |
download | GT5-Unofficial-70a0df8a68725c16f0c0b959639b8e82cbbcf3a0.tar.gz GT5-Unofficial-70a0df8a68725c16f0c0b959639b8e82cbbcf3a0.tar.bz2 GT5-Unofficial-70a0df8a68725c16f0c0b959639b8e82cbbcf3a0.zip |
% Work work
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities')
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java | 1 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java | 36 |
2 files changed, 26 insertions, 11 deletions
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(); } } |