From b6a02d81894a1ea56085f9b4f635cba6e5d6c125 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 5 May 2016 17:29:39 +0200 Subject: [PATCH] Added Phantom Redstoneface --- .../mod/blocks/BlockPhantom.java | 35 ++++++++++++- .../mod/blocks/InitBlocks.java | 2 + .../mod/creative/CreativeTab.java | 1 + .../mod/tile/TileEntityBase.java | 1 + .../tile/TileEntityPhantomRedstoneface.java | 49 ++++++++++++++++++ .../mod/tile/TileEntityPhantomface.java | 3 +- .../blockstates/blockPhantomRedstoneface.json | 14 +++++ .../assets/actuallyadditions/lang/en_US.lang | 1 + .../blocks/blockPhantomRedstoneface.png | Bin 0 -> 732 bytes 9 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java create mode 100644 src/main/resources/assets/actuallyadditions/blockstates/blockPhantomRedstoneface.json create mode 100644 src/main/resources/assets/actuallyadditions/textures/blocks/blockPhantomRedstoneface.png diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java index 67a3035d6..6bde56158 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPhantom.java @@ -17,6 +17,8 @@ import de.ellpeck.actuallyadditions.mod.tile.*; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.PosUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import de.ellpeck.actuallyadditions.mod.util.WorldUtil; +import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -34,6 +36,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -51,6 +54,33 @@ public class BlockPhantom extends BlockContainerBase implements IHudDisplay{ this.setSoundType(SoundType.STONE); } + @Override + public boolean canProvidePower(IBlockState state){ + return this.type == Type.REDSTONEFACE; + } + + @Override + public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){ + if(this.type == Type.REDSTONEFACE){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityPhantomRedstoneface){ + return ((TileEntityPhantomRedstoneface)tile).providesWeak[side.ordinal()]; + } + } + return super.getWeakPower(state, world, pos, side); + } + + @Override + public int getStrongPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){ + if(this.type == Type.REDSTONEFACE){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityPhantomRedstoneface){ + return ((TileEntityPhantomRedstoneface)tile).providesStrong[side.ordinal()]; + } + } + return super.getStrongPower(state, world, pos, side); + } + @Override public void breakBlock(World world, BlockPos pos, IBlockState state){ if(this.type == Type.PLACER || this.type == Type.BREAKER){ @@ -70,6 +100,8 @@ public class BlockPhantom extends BlockContainerBase implements IHudDisplay{ return new TileEntityPhantomLiquiface(); case ENERGYFACE: return new TileEntityPhantomEnergyface(); + case REDSTONEFACE: + return new TileEntityPhantomRedstoneface(); default: return new TileEntityPhantomItemface(); } @@ -127,6 +159,7 @@ public class BlockPhantom extends BlockContainerBase implements IHudDisplay{ PLACER, BREAKER, LIQUIFACE, - ENERGYFACE + ENERGYFACE, + REDSTONEFACE } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java index 03c5e14d1..caa146106 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java @@ -56,6 +56,7 @@ public class InitBlocks{ public static Block blockPhantomBreaker; public static Block blockPhantomLiquiface; public static Block blockPhantomEnergyface; + public static Block blockPhantomRedstoneface; public static Block blockFluidPlacer; public static Block blockFluidCollector; @@ -144,6 +145,7 @@ public class InitBlocks{ blockPhantomPlacer = new BlockPhantom(BlockPhantom.Type.PLACER, "blockPhantomPlacer"); blockPhantomLiquiface = new BlockPhantom(BlockPhantom.Type.LIQUIFACE, "blockPhantomLiquiface"); blockPhantomEnergyface = new BlockPhantom(BlockPhantom.Type.ENERGYFACE, "blockPhantomEnergyface"); + blockPhantomRedstoneface = new BlockPhantom(BlockPhantom.Type.REDSTONEFACE, "blockPhantomRedstoneface"); blockPhantomBreaker = new BlockPhantom(BlockPhantom.Type.BREAKER, "blockPhantomBreaker"); blockCoalGenerator = new BlockCoalGenerator("blockCoalGenerator"); blockOilGenerator = new BlockOilGenerator("blockOilGenerator"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java index ef8826037..bbe32fa5e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java @@ -56,6 +56,7 @@ public class CreativeTab extends CreativeTabs{ this.add(InitBlocks.blockPhantomface); this.add(InitBlocks.blockPhantomEnergyface); this.add(InitBlocks.blockPhantomLiquiface); + this.add(InitBlocks.blockPhantomRedstoneface); this.add(InitBlocks.blockPhantomPlacer); this.add(InitBlocks.blockPhantomBreaker); this.add(InitBlocks.blockInputter); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 33c10e249..fc082c81a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -75,6 +75,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ GameRegistry.registerTileEntity(TileEntityAtomicReconstructor.class, ModUtil.MOD_ID+":tileEntityAtomicReconstructor"); GameRegistry.registerTileEntity(TileEntityMiner.class, ModUtil.MOD_ID+":tileEntityMiner"); GameRegistry.registerTileEntity(TileEntityFireworkBox.class, ModUtil.MOD_ID+":tileEntityFireworkBox"); + GameRegistry.registerTileEntity(TileEntityPhantomRedstoneface.class, ModUtil.MOD_ID+":tileEntityPhantomRedstoneface"); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java new file mode 100644 index 000000000..17004796d --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java @@ -0,0 +1,49 @@ +package de.ellpeck.actuallyadditions.mod.tile; + +import de.ellpeck.actuallyadditions.mod.util.PosUtil; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; + +import java.util.Arrays; + +public class TileEntityPhantomRedstoneface extends TileEntityPhantomface{ + + public int[] providesStrong = new int[EnumFacing.values().length]; + public int[] providesWeak = new int[EnumFacing.values().length]; + + private int[] lastProvidesStrong = new int[this.providesStrong.length]; + private int[] lastProvidesWeak = new int[this.providesWeak.length]; + + public TileEntityPhantomRedstoneface(){ + super("redstoneface"); + } + + @Override + public void updateEntity(){ + super.updateEntity(); + + if(!this.worldObj.isRemote){ + if(this.isBoundThingInRange()){ + IBlockState boundState = this.worldObj.getBlockState(this.boundPosition); + if(boundState != null){ + Block boundBlock = boundState.getBlock(); + if(boundBlock != null){ + for(int i = 0; i < EnumFacing.values().length; i++){ + EnumFacing facing = EnumFacing.values()[i]; + this.providesWeak[i] = boundBlock.getWeakPower(boundState, this.worldObj, this.boundPosition, facing); + this.providesStrong[i] = boundBlock.getStrongPower(boundState, this.worldObj, this.boundPosition, facing); + } + } + } + } + + if(!Arrays.equals(this.providesStrong, this.lastProvidesStrong) || !Arrays.equals(this.providesWeak, this.lastProvidesWeak)){ + System.arraycopy(this.providesWeak, 0, this.lastProvidesWeak, 0, this.providesWeak.length); + System.arraycopy(this.providesStrong, 0, this.lastProvidesStrong, 0, this.providesStrong.length); + + this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); + } + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index 1e45ae82a..0ac068edf 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -95,8 +95,7 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP this.boundPosBefore = this.boundPosition; this.boundBlockBefore = this.boundPosition == null ? null : PosUtil.getBlock(this.boundPosition, this.worldObj); - IBlockState myState = this.worldObj.getBlockState(this.pos); - this.worldObj.notifyBlockUpdate(this.pos, myState, myState, 3); + this.worldObj.notifyNeighborsOfStateChange(this.pos, PosUtil.getBlock(this.pos, this.worldObj)); this.sendUpdate(); this.markDirty(); diff --git a/src/main/resources/assets/actuallyadditions/blockstates/blockPhantomRedstoneface.json b/src/main/resources/assets/actuallyadditions/blockstates/blockPhantomRedstoneface.json new file mode 100644 index 000000000..9030482ce --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/blockstates/blockPhantomRedstoneface.json @@ -0,0 +1,14 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "minecraft:cube_all", + "textures": { + "all": "actuallyadditions:blocks/blockPhantomRedstoneface" + }, + "transform": "forge:default-block" + }, + "variants": { + "normal": [{}], + "inventory": [{}] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 401fd2ebc..4f3ac7243 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -73,6 +73,7 @@ tile.actuallyadditions.blockColoredLampCyan.name=Cyan Lamp tile.actuallyadditions.blockColoredLampPurple.name=Purple Lamp tile.actuallyadditions.blockPhantomface.name=Phantomface tile.actuallyadditions.blockPhantomEnergyface.name=Phantom Energyface +tile.actuallyadditions.blockPhantomRedstoneface.name=Phantom Redstoneface tile.actuallyadditions.blockPhantomLiquiface.name=Phantom Liquiface tile.actuallyadditions.blockPhantomPlacer.name=Phantom Placer tile.actuallyadditions.blockPhantomBreaker.name=Phantom Breaker diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockPhantomRedstoneface.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockPhantomRedstoneface.png new file mode 100644 index 0000000000000000000000000000000000000000..31cf7d4d37ff8d7de79f664f058ae8c6885bbb44 GIT binary patch literal 732 zcmV<20wev2P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5&!@T5&_cPe*6Fc00(qQO+^Ra1sxL( zJ9Nk0>i_@%7<5HgbW?9;ba!ELWdLwtX>N2bZe?^JG%heMIczh2P5=M`I!Q!9R5(vf zlS^xpQ4od?TCb?Ma8(o(FCd7Dpdg~6D6YJVAkjq?6x@iYpio!o1=2{;T6#;gjY%3M zmoBV`B3OlL>#D||qWkfECf^rbyvclX&OCF@%$%^NBiP{;!A`9Vc1AiaosjVD*V=Ar z*YaRHrR~zzNZ9zoL2V@P@~U9hRtLKwU6(HE8_I04Tlt` z7p+=b`VZ1}av^Ln|NZ9yTn`yL8(!RnW0nX_Pxv4pa zu#uqjx?tmxu<@}LpM>Lk5h)NwELVQm#N=ns)~|rdhF}XDTf)Z28o~AI(!VayCh9O% zoOcMD$V%X!O)X*LV=XQ$!E`3@vrmxxT_+LSI}<-BW!#CC@c^XqX21#G&nYE z`N9{!XP-8|T;B>r*!Wl*&3{yj7ktqC1l)yo^kv@I(D*y+Ql;-H69L&s*!b=UkRG0~ zvHT}HtHL{gU|MqjNyd7gy|xQl075o`5H`L`TI(4oJA~Qc>TN*c)~ literal 0 HcmV?d00001