mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Added a Redstone Pulse Responding Mode to some machines
This commit is contained in:
parent
69bf0c36d3
commit
5082bf62eb
12 changed files with 291 additions and 127 deletions
|
@ -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){
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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,10 +51,21 @@ 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){
|
||||
this.doWork();
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.currentTime = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doWork(){
|
||||
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
|
||||
WorldPos coordsBlock = WorldUtil.getCoordsFromSide(sideToManipulate, worldObj, xCoord, yCoord, zCoord, 0);
|
||||
|
@ -81,13 +92,6 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.currentTime = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack){
|
||||
|
@ -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(){
|
||||
|
|
|
@ -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,11 +41,27 @@ 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){
|
||||
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));
|
||||
|
||||
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
|
||||
public void writeSyncableNBT(NBTTagCompound compound, boolean 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,15 +93,7 @@ public class TileEntityFluidCollector extends TileEntityInventoryBase implements
|
|||
return new FluidTankInfo[]{this.tank.getInfo()};
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
if(!worldObj.isRemote){
|
||||
if(!this.isRedstonePowered){
|
||||
if(this.currentTime > 0){
|
||||
this.currentTime--;
|
||||
if(this.currentTime <= 0){
|
||||
private void doWork(){
|
||||
ForgeDirection sideToManipulate = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
|
||||
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{
|
||||
this.currentTime = 15;
|
||||
|
|
|
@ -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,21 +42,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
|||
this.isBreaker = false;
|
||||
}
|
||||
|
||||
@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){
|
||||
if(this.currentTime > 0){
|
||||
this.currentTime--;
|
||||
if(this.currentTime <= 0){
|
||||
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){
|
||||
|
@ -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{
|
||||
this.currentTime = 30;
|
||||
|
@ -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(){
|
||||
|
|
Loading…
Reference in a new issue