mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
parent
c31424944d
commit
e9955348d8
6 changed files with 108 additions and 30 deletions
|
@ -32,6 +32,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockInputter extends BlockContainerBase{
|
||||
|
@ -91,16 +92,14 @@ public class BlockInputter extends BlockContainerBase{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
|
||||
super.neighborChanged(state, world, pos, block);
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityInputter){
|
||||
((TileEntityInputter)tile).initVars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends ItemBlockBase{
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.item.EnumRarity;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockItemViewer extends BlockContainerBase{
|
||||
|
@ -34,16 +35,14 @@ public class BlockItemViewer extends BlockContainerBase{
|
|||
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
|
||||
super.neighborChanged(state, world, pos, block);
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityItemViewer){
|
||||
((TileEntityItemViewer)tile).saveConnectedRelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta){
|
||||
|
|
|
@ -114,16 +114,14 @@ public class BlockLaserRelay extends BlockContainerBase{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
|
||||
super.neighborChanged(state, world, pos, block);
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityLaserRelay){
|
||||
((TileEntityLaserRelay)tile).saveAllHandlersAround();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int i){
|
||||
|
|
|
@ -154,10 +154,22 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
|
|||
}
|
||||
}
|
||||
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
this.updateRedstoneState(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn){
|
||||
super.neighborChanged(state, worldIn, pos, blockIn);
|
||||
this.updateRedstoneState(worldIn, pos);
|
||||
this.neighborsChangedCustom(worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor){
|
||||
super.onNeighborChange(world, pos, neighbor);
|
||||
if(world instanceof World){
|
||||
this.neighborsChangedCustom((World)world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRedstoneState(World world, BlockPos pos){
|
||||
|
|
|
@ -21,6 +21,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor{
|
||||
|
||||
|
@ -80,10 +83,46 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
this.markDirty();
|
||||
}
|
||||
|
||||
private boolean newPulling(){
|
||||
for(EnumFacing side : EnumFacing.values()){
|
||||
if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){
|
||||
IItemHandler cap = this.placeToPull.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
|
||||
if(cap != null){
|
||||
for(int i = Math.max(this.slotToPullStart, 0); i < Math.min(this.slotToPullEnd, cap.getSlots()); i++){
|
||||
if(WorldUtil.doItemInteraction(i, 0, this.placeToPull, this, side, null)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean newPutting(){
|
||||
for(EnumFacing side : EnumFacing.values()){
|
||||
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){
|
||||
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
|
||||
if(cap != null){
|
||||
for(int i = Math.max(this.slotToPutStart, 0); i < Math.min(this.slotToPutEnd, cap.getSlots()); i++){
|
||||
if(WorldUtil.doItemInteraction(0, i, this, this.placeToPut, null, side)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls Items from the specified Slots on the specified Side
|
||||
*/
|
||||
private void pull(){
|
||||
if(this.newPulling()){
|
||||
return;
|
||||
}
|
||||
|
||||
//The Inventory to pull from
|
||||
IInventory theInventory = (IInventory)this.placeToPull;
|
||||
//Does the Inventory even have Slots!?
|
||||
|
@ -183,6 +222,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
* (Check pull() for Description, similar to this)
|
||||
*/
|
||||
private void put(){
|
||||
if(this.newPutting()){
|
||||
return;
|
||||
}
|
||||
|
||||
IInventory theInventory = (IInventory)this.placeToPut;
|
||||
if(theInventory.getSizeInventory() > 0){
|
||||
int theSlotToPut = this.slotToPutStart;
|
||||
|
@ -281,20 +324,22 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
*/
|
||||
public void initVars(){
|
||||
if(this.sideToPull != -1){
|
||||
this.placeToPull = this.worldObj.getTileEntity(this.pos.offset(WorldUtil.getDirectionBySidesInOrder(this.sideToPull)));
|
||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
||||
this.placeToPull = this.worldObj.getTileEntity(this.pos.offset(side));
|
||||
|
||||
if(this.slotToPullEnd <= 0 && this.placeToPull != null){
|
||||
if(this.placeToPull instanceof IInventory){
|
||||
if(this.slotToPullEnd <= 0){
|
||||
this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.sideToPut != -1){
|
||||
this.placeToPut = this.worldObj.getTileEntity(this.pos.offset(WorldUtil.getDirectionBySidesInOrder(this.sideToPut)));
|
||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
|
||||
this.placeToPut = this.worldObj.getTileEntity(this.pos.offset(side));
|
||||
|
||||
if(this.slotToPutEnd <= 0 && this.placeToPut != null){
|
||||
if(this.placeToPut instanceof IInventory){
|
||||
if(this.slotToPutEnd <= 0){
|
||||
this.slotToPutEnd = ((IInventory)this.placeToPut).getSizeInventory();
|
||||
}
|
||||
}
|
||||
|
@ -395,10 +440,10 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
//Is Block not powered by Redstone?
|
||||
if(!this.isRedstonePowered){
|
||||
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
|
||||
if(this.sideToPull != -1 && this.placeToPull instanceof IInventory){
|
||||
if(this.sideToPull != -1 && this.placeToPull != null){
|
||||
this.pull();
|
||||
}
|
||||
if(this.sideToPut != -1 && this.placeToPut instanceof IInventory){
|
||||
if(this.slots[0] != null && this.sideToPut != -1 && this.placeToPut != null){
|
||||
this.put();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,12 +49,37 @@ import net.minecraftforge.fluids.IFluidBlock;
|
|||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class WorldUtil{
|
||||
|
||||
//This is probably hideous. Just saying.
|
||||
public static boolean doItemInteraction(int slotExtract, int slotInsert, TileEntity extract, TileEntity insert, EnumFacing extractSide, EnumFacing insertSide){
|
||||
if(extract.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide) && insert.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide)){
|
||||
IItemHandler extractCap = extract.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, extractSide);
|
||||
IItemHandler insertCap = insert.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, insertSide);
|
||||
|
||||
if(extractCap != null && insertCap != null){
|
||||
ItemStack theoreticalExtract = extractCap.extractItem(slotExtract, Integer.MAX_VALUE, true);
|
||||
if(theoreticalExtract != null){
|
||||
ItemStack remaining = insertCap.insertItem(slotInsert, theoreticalExtract, false);
|
||||
|
||||
if(!ItemStack.areItemStacksEqual(remaining, theoreticalExtract)){
|
||||
int toExtract = remaining == null ? theoreticalExtract.stackSize : theoreticalExtract.stackSize-remaining.stackSize;
|
||||
extractCap.extractItem(slotExtract, toExtract, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void doEnergyInteraction(TileEntity tile){
|
||||
for(EnumFacing side : EnumFacing.values()){
|
||||
TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side));
|
||||
|
|
Loading…
Reference in a new issue