Added a Redstone Pulse Responding Mode to some machines

This commit is contained in:
Ellpeck 2015-12-17 18:47:46 +01:00
parent 69bf0c36d3
commit 5082bf62eb
12 changed files with 291 additions and 127 deletions

View file

@ -80,6 +80,9 @@ public class BlockBreaker 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){
TileEntityBreaker breaker = (TileEntityBreaker)world.getTileEntity(x, y, z);
if(breaker != null){

View file

@ -77,6 +77,9 @@ public class BlockDirectionalBreaker 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){
TileEntityDirectionalBreaker breaker = (TileEntityDirectionalBreaker)world.getTileEntity(x, y, z);
if(breaker != null){

View file

@ -77,6 +77,9 @@ public class BlockDropper 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){
TileEntityDropper dropper = (TileEntityDropper)world.getTileEntity(x, y, z);
if(dropper != null){

View file

@ -80,6 +80,9 @@ public class BlockFluidCollector 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){
TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(x, y, z);
if(collector != null){

View file

@ -87,6 +87,9 @@ public class BlockPhantom extends BlockContainerBase{
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ){
if(this.tryToggleRedstone(world, x, y, z, player)){
return true;
}
if(!world.isRemote){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile != null){

View file

@ -12,14 +12,12 @@ package ellpeck.actuallyadditions.blocks.base;
import cpw.mods.fml.common.registry.GameRegistry;
import ellpeck.actuallyadditions.creative.CreativeTab;
import ellpeck.actuallyadditions.tile.IEnergySaver;
import ellpeck.actuallyadditions.tile.IFluidSaver;
import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
import ellpeck.actuallyadditions.tile.*;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
@ -30,6 +28,7 @@ import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
@ -129,10 +128,16 @@ public abstract class BlockContainerBase extends BlockContainer{
public void updateRedstoneState(World world, int x, int y, int z){
TileEntity tile = world.getTileEntity(x, y, z);
boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z);
if(tile instanceof TileEntityBase){
((TileEntityBase)tile).setRedstonePowered(world.isBlockIndirectlyGettingPowered(x, y, z));
((TileEntityBase)tile).setRedstonePowered(powered);
tile.markDirty();
}
if(tile instanceof IRedstoneToggle){
if(((IRedstoneToggle)tile).isRightMode() && powered){
((IRedstoneToggle)tile).activateOnPulse();
}
}
}
@Override
@ -142,6 +147,26 @@ public abstract class BlockContainerBase extends BlockContainer{
}
}
public boolean tryToggleRedstone(World world, int x, int y, int z, EntityPlayer player){
ItemStack stack = player.getCurrentEquippedItem();
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof IRedstoneToggle){
if(!world.isRemote){
if(((IRedstoneToggle)tile).toggle()){
player.addChatComponentMessage(new ChatComponentText("Changed to Redstone Pulse Mode"));
}
else{
player.addChatComponentMessage(new ChatComponentText("Changed to Redstone Deactivation Mode"));
}
}
return true;
}
}
return false;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();

View file

@ -0,0 +1,20 @@
/*
* This file ("IRedstoneToggle.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.tile;
public interface IRedstoneToggle{
boolean toggle();
boolean isRightMode();
void activateOnPulse();
}

View file

@ -20,7 +20,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityBreaker extends TileEntityInventoryBase{
public class TileEntityBreaker extends TileEntityInventoryBase implements IRedstoneToggle{
public boolean isPlacer;
private int currentTime;
@ -51,35 +51,11 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(!this.isPlacer && blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
drops.addAll(blockToBreak.getDrops(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
worldObj.playAuxSFX(2001, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
WorldUtil.addToInventory(this, drops, true);
this.markDirty();
}
}
else if(this.isPlacer && worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()).isReplaceable(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, this.slots[theSlot]));
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
}
}
}
this.doWork();
}
}
else{
@ -89,6 +65,34 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
}
}
private void doWork(){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(!this.isPlacer && blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
drops.addAll(blockToBreak.getDrops(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
worldObj.playAuxSFX(2001, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
WorldUtil.addToInventory(this, drops, true);
this.markDirty();
}
}
else if(this.isPlacer && worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()).isReplaceable(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, this.slots[theSlot]));
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
}
}
}
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return this.isPlacer;
@ -104,6 +108,23 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
return true;
}
private boolean activateOnceWithSignal;
@Override
public boolean toggle(){
return this.activateOnceWithSignal = !this.activateOnceWithSignal;
}
@Override
public void activateOnPulse(){
this.doWork();
}
@Override
public boolean isRightMode(){
return this.activateOnceWithSignal;
}
public static class TileEntityPlacer extends TileEntityBreaker{
public TileEntityPlacer(){

View file

@ -24,7 +24,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver{
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver, IRedstoneToggle{
public static final int RANGE = 8;
public static final int ENERGY_USE = 5;
@ -41,32 +41,12 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
for(int i = 0; i < RANGE; i++){
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
drops.addAll(blockToBreak.getDrops(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
worldObj.playAuxSFX(2001, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i);
WorldUtil.addToInventory(this, drops, true);
this.storage.extractEnergy(ENERGY_USE, false);
this.markDirty();
}
}
}
}
this.doWork();
}
}
else{
@ -81,6 +61,30 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
}
}
private void doWork(){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
for(int i = 0; i < RANGE; i++){
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
drops.addAll(blockToBreak.getDrops(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
worldObj.playAuxSFX(2001, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, i);
WorldUtil.addToInventory(this, drops, true);
this.storage.extractEnergy(ENERGY_USE, false);
this.markDirty();
}
}
}
}
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
super.writeSyncableNBT(compound, sync);
@ -144,4 +148,21 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
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();
}
}

View file

@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDropper extends TileEntityInventoryBase{
public class TileEntityDropper extends TileEntityInventoryBase implements IRedstoneToggle{
private int currentTime;
@ -40,15 +40,11 @@ public class TileEntityDropper extends TileEntityInventoryBase{
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
if(this.removeFromInventory(false) != null){
ItemStack stack = this.removeFromInventory(true);
stack.stackSize = 1;
WorldUtil.dropItemAtSide(ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)), worldObj, xCoord, yCoord, zCoord, stack);
}
this.doWork();
}
}
else{
@ -58,6 +54,14 @@ public class TileEntityDropper extends TileEntityInventoryBase{
}
}
private void doWork(){
if(this.removeFromInventory(false) != null){
ItemStack stack = this.removeFromInventory(true);
stack.stackSize = 1;
WorldUtil.dropItemAtSide(ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)), worldObj, xCoord, yCoord, zCoord, stack);
}
}
public ItemStack removeFromInventory(boolean actuallyDo){
for(int i = 0; i < this.slots.length; i++){
if(this.slots[i] != null){
@ -89,4 +93,20 @@ public class TileEntityDropper extends TileEntityInventoryBase{
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();
}
}

View file

@ -21,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
public class TileEntityFluidCollector extends TileEntityInventoryBase implements IFluidHandler, IFluidSaver{
public class TileEntityFluidCollector extends TileEntityInventoryBase implements IFluidHandler, IFluidSaver, IRedstoneToggle{
public FluidTank tank = new FluidTank(8*FluidContainerRegistry.BUCKET_VOLUME);
public boolean isPlacer;
@ -32,6 +32,23 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
super(slots, name);
}
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();
}
public TileEntityFluidCollector(){
super(2, "fluidCollector");
this.isPlacer = false;
@ -76,52 +93,56 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
return new FluidTankInfo[]{this.tank.getInfo()};
}
private void doWork(){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(!this.isPlacer && blockToBreak != null && worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) == 0 && FluidContainerRegistry.BUCKET_VOLUME <= this.tank.getCapacity()-this.tank.getFluidAmount()){
if(blockToBreak instanceof IFluidBlock && ((IFluidBlock)blockToBreak).getFluid() != null){
if(this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
else if(blockToBreak == Blocks.lava || blockToBreak == Blocks.flowing_lava){
if(this.tank.fill(new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
else if(blockToBreak == Blocks.water || blockToBreak == Blocks.flowing_water){
if(this.tank.fill(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
}
else if(this.isPlacer && worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()).isReplaceable(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){
if(this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
if(this.tank.getFluid().getFluid().getBlock() != null){
Block block = worldObj.getBlock(xCoord+sideToManipulate.offsetX, yCoord+sideToManipulate.offsetY, zCoord+sideToManipulate.offsetZ);
if(!(block instanceof IFluidBlock) && block != Blocks.lava && block != Blocks.water && block != Blocks.flowing_lava && block != Blocks.flowing_water){
WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, new ItemStack(this.tank.getFluid().getFluid().getBlock()));
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
}
}
}
}
}
}
@Override
@SuppressWarnings("unchecked")
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
if(coordsBlock != null){
Block blockToBreak = worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ());
if(!this.isPlacer && blockToBreak != null && worldObj.getBlockMetadata(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()) == 0 && FluidContainerRegistry.BUCKET_VOLUME <= this.tank.getCapacity()-this.tank.getFluidAmount()){
if(blockToBreak instanceof IFluidBlock && ((IFluidBlock)blockToBreak).getFluid() != null){
if(this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
else if(blockToBreak == Blocks.lava || blockToBreak == Blocks.flowing_lava){
if(this.tank.fill(new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
else if(blockToBreak == Blocks.water || blockToBreak == Blocks.flowing_water){
if(this.tank.fill(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), false) >= FluidContainerRegistry.BUCKET_VOLUME){
this.tank.fill(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
WorldUtil.breakBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord);
}
}
}
else if(this.isPlacer && worldObj.getBlock(coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ()).isReplaceable(worldObj, coordsBlock.getX(), coordsBlock.getY(), coordsBlock.getZ())){
if(this.tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME){
if(this.tank.getFluid().getFluid().getBlock() != null){
Block block = worldObj.getBlock(xCoord+sideToManipulate.offsetX, yCoord+sideToManipulate.offsetY, zCoord+sideToManipulate.offsetZ);
if(!(block instanceof IFluidBlock) && block != Blocks.lava && block != Blocks.water && block != Blocks.flowing_lava && block != Blocks.flowing_water){
WorldUtil.placeBlockAtSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, new ItemStack(this.tank.getFluid().getFluid().getBlock()));
this.tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
}
}
}
}
}
this.doWork();
}
}
else{

View file

@ -25,7 +25,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile{
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile, IRedstoneToggle{
public static final int RANGE = 3;
public WorldPos boundPosition;
@ -42,6 +42,33 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.isBreaker = false;
}
private void doWork(){
if(this.isBreaker){
Block blockToBreak = boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
if(blockToBreak != null && blockToBreak.getBlockHardness(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = boundPosition.getWorld().getBlockMetadata(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
drops.addAll(blockToBreak.getDrops(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
boundPosition.getWorld().playAuxSFX(2001, boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
WorldUtil.addToInventory(this, drops, true);
this.markDirty();
}
}
}
else{
if(boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()).isReplaceable(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ())){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), this.slots[theSlot]));
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
}
}
}
}
@Override
public void updateEntity(){
super.updateEntity();
@ -53,34 +80,11 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
}
if(this.isBoundThingInRange()){
if(!this.isRedstonePowered){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
if(this.isBreaker){
Block blockToBreak = boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
if(blockToBreak != null && blockToBreak.getBlockHardness(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) > -1.0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
int meta = boundPosition.getWorld().getBlockMetadata(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
drops.addAll(blockToBreak.getDrops(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), meta, 0));
if(WorldUtil.addToInventory(this, drops, false)){
boundPosition.getWorld().playAuxSFX(2001, boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
WorldUtil.breakBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
WorldUtil.addToInventory(this, drops, true);
this.markDirty();
}
}
}
else{
if(boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()).isReplaceable(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ())){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), this.slots[theSlot]));
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0){
this.slots[theSlot] = null;
}
}
}
this.doWork();
}
}
else{
@ -191,6 +195,23 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
return this.isBreaker;
}
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();
}
public static class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
public TileEntityPhantomBreaker(){