From 34bf9e4aa7985e14da4849a93b8ff0f9685d39a1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 12 Mar 2017 09:07:51 +0100 Subject: [PATCH] added a pulse mode to the ranged collector --- .../mod/blocks/BlockRangedCollector.java | 4 ++ .../mod/blocks/base/BlockContainerBase.java | 8 +--- .../mod/tile/TileEntityRangedCollector.java | 46 +++++++++++-------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockRangedCollector.java index f8c58bcb4..c50767c99 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockRangedCollector.java @@ -44,6 +44,10 @@ public class BlockRangedCollector extends BlockContainerBase{ @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9){ + if(this.tryToggleRedstone(world, pos, player)){ + return true; + } + if(!world.isRemote){ TileEntityRangedCollector breaker = (TileEntityRangedCollector)world.getTileEntity(pos); if(breaker != null){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java index 1e4556f5d..e173f6356 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java @@ -18,7 +18,6 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; -import net.minecraft.block.BlockRedstoneTorch; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; @@ -118,11 +117,8 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB TileEntityBase base = (TileEntityBase)tile; if(!world.isRemote && base.isRedstoneToggle()){ base.isPulseMode = !base.isPulseMode; - tile.markDirty(); - - if(tile instanceof TileEntityBase){ - ((TileEntityBase)tile).sendUpdate(); - } + base.markDirty(); + base.sendUpdate(); } return true; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java index 659ad2fd7..b96f1c149 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java @@ -51,30 +51,40 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement } @Override - public void updateEntity(){ - super.updateEntity(); - if(!this.worldObj.isRemote){ - if(!this.isRedstonePowered){ - ArrayList items = (ArrayList)this.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(this.pos.getX()-RANGE, this.pos.getY()-RANGE, this.pos.getZ()-RANGE, this.pos.getX()+RANGE, this.pos.getY()+RANGE, this.pos.getZ()+RANGE)); - if(!items.isEmpty()){ - for(EntityItem item : items){ - if(!item.isDead && !item.cannotPickup() && StackUtil.isValid(item.getEntityItem())){ - ItemStack toAdd = item.getEntityItem().copy(); - if(this.filter.check(toAdd, this.slots)){ - ArrayList checkList = new ArrayList(); - checkList.add(toAdd); - if(WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, false, true)){ - WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, true, true); + public boolean isRedstoneToggle(){ + return true; + } - ((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D); + @Override + public void activateOnPulse(){ + ArrayList items = (ArrayList)this.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(this.pos.getX()-RANGE, this.pos.getY()-RANGE, this.pos.getZ()-RANGE, this.pos.getX()+RANGE, this.pos.getY()+RANGE, this.pos.getZ()+RANGE)); + if(!items.isEmpty()){ + for(EntityItem item : items){ + if(!item.isDead && !item.cannotPickup() && StackUtil.isValid(item.getEntityItem())){ + ItemStack toAdd = item.getEntityItem().copy(); + if(this.filter.check(toAdd, this.slots)){ + ArrayList checkList = new ArrayList(); + checkList.add(toAdd); + if(WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, false, true)){ + WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, true, true); - item.setDead(); - } - } + ((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D); + + item.setDead(); } } } } + } + } + + @Override + public void updateEntity(){ + super.updateEntity(); + if(!this.worldObj.isRemote){ + if(!this.isRedstonePowered && !this.isPulseMode){ + this.activateOnPulse(); + } if(this.filter.needsUpdateSend() && this.sendUpdateWithInterval()){ this.filter.updateLasts();