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 @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ 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){ if(!world.isRemote){
TileEntityBreaker breaker = (TileEntityBreaker)world.getTileEntity(x, y, z); TileEntityBreaker breaker = (TileEntityBreaker)world.getTileEntity(x, y, z);
if(breaker != null){ if(breaker != null){

View file

@ -77,6 +77,9 @@ public class BlockDirectionalBreaker extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ 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){ if(!world.isRemote){
TileEntityDirectionalBreaker breaker = (TileEntityDirectionalBreaker)world.getTileEntity(x, y, z); TileEntityDirectionalBreaker breaker = (TileEntityDirectionalBreaker)world.getTileEntity(x, y, z);
if(breaker != null){ if(breaker != null){

View file

@ -77,6 +77,9 @@ public class BlockDropper extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ 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){ if(!world.isRemote){
TileEntityDropper dropper = (TileEntityDropper)world.getTileEntity(x, y, z); TileEntityDropper dropper = (TileEntityDropper)world.getTileEntity(x, y, z);
if(dropper != null){ if(dropper != null){

View file

@ -80,6 +80,9 @@ public class BlockFluidCollector extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ 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){ if(!world.isRemote){
TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(x, y, z); TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(x, y, z);
if(collector != null){ if(collector != null){

View file

@ -87,6 +87,9 @@ public class BlockPhantom extends BlockContainerBase{
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ){ 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){ if(!world.isRemote){
TileEntity tile = world.getTileEntity(x, y, z); TileEntity tile = world.getTileEntity(x, y, z);
if(tile != null){ if(tile != null){

View file

@ -12,14 +12,12 @@ package ellpeck.actuallyadditions.blocks.base;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import ellpeck.actuallyadditions.creative.CreativeTab; import ellpeck.actuallyadditions.creative.CreativeTab;
import ellpeck.actuallyadditions.tile.IEnergySaver; import ellpeck.actuallyadditions.tile.*;
import ellpeck.actuallyadditions.tile.IFluidSaver;
import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util; import ellpeck.actuallyadditions.util.Util;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -30,6 +28,7 @@ import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack; 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){ public void updateRedstoneState(World world, int x, int y, int z){
TileEntity tile = world.getTileEntity(x, y, z); TileEntity tile = world.getTileEntity(x, y, z);
boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z);
if(tile instanceof TileEntityBase){ if(tile instanceof TileEntityBase){
((TileEntityBase)tile).setRedstonePowered(world.isBlockIndirectlyGettingPowered(x, y, z)); ((TileEntityBase)tile).setRedstonePowered(powered);
tile.markDirty(); tile.markDirty();
} }
if(tile instanceof IRedstoneToggle){
if(((IRedstoneToggle)tile).isRightMode() && powered){
((IRedstoneToggle)tile).activateOnPulse();
}
}
} }
@Override @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 @Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); 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; import java.util.ArrayList;
public class TileEntityBreaker extends TileEntityInventoryBase{ public class TileEntityBreaker extends TileEntityInventoryBase implements IRedstoneToggle{
public boolean isPlacer; public boolean isPlacer;
private int currentTime; private int currentTime;
@ -51,10 +51,21 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!this.isRedstonePowered){ if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){
this.doWork();
}
}
else{
this.currentTime = 15;
}
}
}
}
private void doWork(){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0); WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
@ -81,13 +92,6 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
} }
} }
} }
}
else{
this.currentTime = 15;
}
}
}
}
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack){ public boolean isItemValidForSlot(int i, ItemStack stack){
@ -104,6 +108,23 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
return true; 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 static class TileEntityPlacer extends TileEntityBreaker{
public TileEntityPlacer(){ public TileEntityPlacer(){

View file

@ -24,7 +24,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList; 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 RANGE = 8;
public static final int ENERGY_USE = 5; public static final int ENERGY_USE = 5;
@ -41,11 +41,27 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!this.isRedstonePowered){ if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){ if(this.storage.getEnergyStored() >= ENERGY_USE*RANGE){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){
this.doWork();
}
}
else{
this.currentTime = 15;
}
}
}
if(this.storage.getEnergyStored() != this.lastEnergy && this.sendUpdateWithInterval()){
this.lastEnergy = this.storage.getEnergyStored();
}
}
}
private void doWork(){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
for(int i = 0; i < RANGE; i++){ for(int i = 0; i < RANGE; i++){
@ -68,18 +84,6 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
} }
} }
} }
}
else{
this.currentTime = 15;
}
}
}
if(this.storage.getEnergyStored() != this.lastEnergy && this.sendUpdateWithInterval()){
this.lastEnergy = this.storage.getEnergyStored();
}
}
}
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){ public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
@ -144,4 +148,21 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
public void setEnergy(int energy){ public void setEnergy(int energy){
this.storage.setEnergyStored(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.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDropper extends TileEntityInventoryBase{ public class TileEntityDropper extends TileEntityInventoryBase implements IRedstoneToggle{
private int currentTime; private int currentTime;
@ -40,15 +40,11 @@ public class TileEntityDropper extends TileEntityInventoryBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ if(!worldObj.isRemote){
if(!this.isRedstonePowered){ if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){ if(this.currentTime > 0){
this.currentTime--; this.currentTime--;
if(this.currentTime <= 0){ if(this.currentTime <= 0){
if(this.removeFromInventory(false) != null){ this.doWork();
ItemStack stack = this.removeFromInventory(true);
stack.stackSize = 1;
WorldUtil.dropItemAtSide(ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)), worldObj, xCoord, yCoord, zCoord, stack);
}
} }
} }
else{ 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){ public ItemStack removeFromInventory(boolean actuallyDo){
for(int i = 0; i < this.slots.length; i++){ for(int i = 0; i < this.slots.length; i++){
if(this.slots[i] != null){ if(this.slots[i] != null){
@ -89,4 +93,20 @@ public class TileEntityDropper extends TileEntityInventoryBase{
return true; 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.common.util.ForgeDirection;
import net.minecraftforge.fluids.*; 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 FluidTank tank = new FluidTank(8*FluidContainerRegistry.BUCKET_VOLUME);
public boolean isPlacer; public boolean isPlacer;
@ -32,6 +32,23 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
super(slots, name); 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(){ public TileEntityFluidCollector(){
super(2, "fluidCollector"); super(2, "fluidCollector");
this.isPlacer = false; this.isPlacer = false;
@ -76,15 +93,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
return new FluidTankInfo[]{this.tank.getInfo()}; return new FluidTankInfo[]{this.tank.getInfo()};
} }
@Override private void doWork(){
@SuppressWarnings("unchecked")
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0); WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
@ -123,6 +132,18 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
} }
} }
} }
@Override
@SuppressWarnings("unchecked")
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
this.doWork();
}
} }
else{ else{
this.currentTime = 15; this.currentTime = 15;

View file

@ -25,7 +25,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList; 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 static final int RANGE = 3;
public WorldPos boundPosition; public WorldPos boundPosition;
@ -42,21 +42,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
this.isBreaker = false; this.isBreaker = false;
} }
@Override private void doWork(){
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
this.range = TileEntityPhantomface.upgradeRange(RANGE, worldObj, xCoord, yCoord, zCoord);
if(!this.hasBoundPosition()){
this.boundPosition = null;
}
if(this.isBoundThingInRange()){
if(!this.isRedstonePowered){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
if(this.isBreaker){ if(this.isBreaker){
Block blockToBreak = boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()); 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){ if(blockToBreak != null && blockToBreak.getBlockHardness(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) > -1.0F){
@ -82,6 +68,24 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
} }
} }
} }
@Override
public void updateEntity(){
super.updateEntity();
if(!worldObj.isRemote){
this.range = TileEntityPhantomface.upgradeRange(RANGE, worldObj, xCoord, yCoord, zCoord);
if(!this.hasBoundPosition()){
this.boundPosition = null;
}
if(this.isBoundThingInRange()){
if(!this.isRedstonePowered && !this.activateOnceWithSignal){
if(this.currentTime > 0){
this.currentTime--;
if(this.currentTime <= 0){
this.doWork();
}
} }
else{ else{
this.currentTime = 30; this.currentTime = 30;
@ -191,6 +195,23 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
return this.isBreaker; 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 static class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
public TileEntityPhantomBreaker(){ public TileEntityPhantomBreaker(){