From 11935c06983b77dab6c016d23d10785d9c022f51 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 18 Dec 2015 16:25:12 +0100 Subject: [PATCH] Firework Box reacts to redstone torch mode changing now --- .../blocks/BlockFireworkBox.java | 3 ++ .../tile/TileEntityAtomicReconstructor.java | 32 ++++++------ .../tile/TileEntityFireworkBox.java | 51 ++++++++++++++----- .../assets/actuallyadditions/lang/en_US.lang | 4 +- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockFireworkBox.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockFireworkBox.java index 24caea01a..a99e40a97 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockFireworkBox.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockFireworkBox.java @@ -52,6 +52,9 @@ public class BlockFireworkBox extends BlockContainerBase{ @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ + if(this.tryToggleRedstone(world, x, y, z, player)){ + return true; + } if(!world.isRemote){ TileEntityFireworkBox box = (TileEntityFireworkBox)world.getTileEntity(x, y, z); if(box != null){ diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java index 6594217ff..4fc8a8856 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityAtomicReconstructor.java @@ -40,7 +40,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public void updateEntity(){ super.updateEntity(); if(!this.worldObj.isRemote){ - if(!this.isRedstonePowered && this.storage.getEnergyStored() >= ENERGY_USE){ + if(!this.isRedstonePowered){ if(this.currentTime > 0){ this.currentTime--; if(this.currentTime <= 0){ @@ -56,22 +56,24 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple } private void doWork(){ - ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); - //Extract energy for shooting the laser itself too! - this.storage.extractEnergy(ENERGY_USE, false); + if(this.storage.getEnergyStored() >= ENERGY_USE){ + ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + //Extract energy for shooting the laser itself too! + this.storage.extractEnergy(ENERGY_USE, false); - //The Lens the Reconstructor currently has installed - Lens currentLens = this.getCurrentLens(); - int distance = currentLens.getDistance(); - for(int i = 0; i < distance; i++){ - WorldPos hitBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i); + //The Lens the Reconstructor currently has installed + Lens currentLens = this.getCurrentLens(); + int distance = currentLens.getDistance(); + for(int i = 0; i < distance; i++){ + WorldPos hitBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i); - if(currentLens.invoke(hitBlock, this)){ - this.shootLaser(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens); - break; - } - else if(i >= distance-1){ - this.shootLaser(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens); + if(currentLens.invoke(hitBlock, this)){ + this.shootLaser(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens); + break; + } + else if(i >= distance-1){ + this.shootLaser(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens); + } } } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityFireworkBox.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityFireworkBox.java index 281f75cfe..90133dc90 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityFireworkBox.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityFireworkBox.java @@ -22,7 +22,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.util.MathHelper; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityFireworkBox extends TileEntityBase implements IEnergyReceiver{ +public class TileEntityFireworkBox extends TileEntityBase implements IEnergyReceiver, IRedstoneToggle{ public EnergyStorage storage = new EnergyStorage(20000); @@ -35,19 +35,8 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyRece if(!this.worldObj.isRemote && !this.isRedstonePowered){ if(this.timeUntilNextFirework > 0){ this.timeUntilNextFirework--; - if(this.timeUntilNextFirework <= 0 && this.storage.getEnergyStored() >= USE_PER_SHOT){ - int range = 4; - int amount = Util.RANDOM.nextInt(5)+1; - for(int i = 0; i < amount; i++){ - ItemStack firework = this.makeFirework(); - - double x = this.xCoord+MathHelper.getRandomDoubleInRange(Util.RANDOM, 0, range*2)-range; - double z = this.zCoord+MathHelper.getRandomDoubleInRange(Util.RANDOM, 0, range*2)-range; - EntityFireworkRocket rocket = new EntityFireworkRocket(this.worldObj, x, this.yCoord+0.5, z, firework); - this.worldObj.spawnEntityInWorld(rocket); - } - - this.storage.extractEnergy(USE_PER_SHOT, false); + if(this.timeUntilNextFirework <= 0){ + this.doWork(); } } else{ @@ -56,6 +45,23 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyRece } } + private void doWork(){ + if(this.storage.getEnergyStored() >= USE_PER_SHOT){ + int range = 4; + int amount = Util.RANDOM.nextInt(5)+1; + for(int i = 0; i < amount; i++){ + ItemStack firework = this.makeFirework(); + + double x = this.xCoord+MathHelper.getRandomDoubleInRange(Util.RANDOM, 0, range*2)-range; + double z = this.zCoord+MathHelper.getRandomDoubleInRange(Util.RANDOM, 0, range*2)-range; + EntityFireworkRocket rocket = new EntityFireworkRocket(this.worldObj, x, this.yCoord+0.5, z, firework); + this.worldObj.spawnEntityInWorld(rocket); + } + + this.storage.extractEnergy(USE_PER_SHOT, false); + } + } + private ItemStack makeFirework(){ NBTTagList list = new NBTTagList(); int chargesAmount = Util.RANDOM.nextInt(2)+1; @@ -118,4 +124,21 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyRece public boolean canConnectEnergy(ForgeDirection from){ return true; } + + private boolean activateOnceWithSignal; + + @Override + public boolean toggle(){ + return this.activateOnceWithSignal = !this.activateOnceWithSignal; + } + + @Override + public boolean isRightMode(){ + return this.activateOnceWithSignal; + } + + @Override + public void activateOnPulse(){ + this.doWork(); + } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index fa2cef2c0..53474f862 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -651,7 +651,7 @@ booklet.actuallyadditions.chapter.blackLotus.text.2=No, not that one, Vaz booklet.actuallyadditions.chapter.crystals.name=Crystals and Reconstructor booklet.actuallyadditions.chapter.crystals.text.1=The Atomic Reconstructor is used to craft Crystals, which are the main crafting ingredient in most items from Actually Additions. Upon being supplied with power, it shoots out a Laser. When the Laser hits a block, it will convert all surrounding items and blocks, provided they can be converted. When shooting a laser, it uses RF, but additional rates vary depending on the conversion. -booklet.actuallyadditions.chapter.crystals.text.2=There are various Lenses that can be attached to the Reconstructor that don't all follow the default behavior of the Reconstructor and are able to do some neat things. See the "Reconstructor Lenses & Misc" chapter in the booklet's Miscellaneous section for more information. When right-clicking the Reconstructor with a Redstone Torch in hand, it will change between a mode where it gets deactivated by Redstone and a mode where it responds to pulses. +booklet.actuallyadditions.chapter.crystals.text.2=There are various Lenses that can be attached to the Reconstructor that don't all follow the default behavior of the Reconstructor and are able to do some neat things. See the "Reconstructor Lenses & Misc" chapter in the booklet's Miscellaneous section for more information. When right-clicking the Reconstructor with a Redstone Torch in hand, it will change between a mode where it gets deactivated by Redstone and a mode where it responds to pulses. booklet.actuallyadditions.chapter.crystals.text.4=When you have crafted a couple of items, you might want to find a way to automate this. There is a very simple way to do accomplish this: Place the Atomic Reconstructor down facing into a Precision Dropper (to find it, look it up in the All Items and Search Entry!). Next, place a Ranged Collector in the area that has the converted items set as a whitelist. Now you can just chuck your raw materials into the Dropper to convert them! booklet.actuallyadditions.chapter.bookTutorial.name=Intro to the Manual @@ -678,4 +678,4 @@ booklet.actuallyadditions.chapter.miner.text.2=(Works with any colored Drill) Firework Box is a perfect thing for New Year's! When placed down and supplied with some RF, it will shoot out some randomly generated Fireworks around it. For each shot, it uses RF. You know, Vanilla Fireworks are just too bloody annoying to craft, but too awesome not to use. So here's the solution. -booklet.actuallyadditions.chapter.fireworkBox.text.2=Keep it safe. It won't explode. \ No newline at end of file +booklet.actuallyadditions.chapter.fireworkBox.text.2=When right-clicking it with a Redstone Torch in hand, it will change between a mode where it gets deactivated by Redstone and a mode where it responds to pulses. \ No newline at end of file