mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Use the new item handler system for inserting and extracting
Might fix #249?
This commit is contained in:
parent
7d28a500f4
commit
80d044bb48
2 changed files with 37 additions and 3 deletions
|
@ -31,10 +31,14 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
|
||||||
this.slots = new ItemStack[slots];
|
this.slots = new ItemStack[slots];
|
||||||
|
|
||||||
if(this.hasInvWrapperCapabilities()){
|
if(this.hasInvWrapperCapabilities()){
|
||||||
for(int i = 0; i < this.invWrappers.length; i++){
|
this.getInvWrappers(this.invWrappers);
|
||||||
this.invWrappers[i] = new SidedInvWrapper(this, EnumFacing.values()[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void getInvWrappers(SidedInvWrapper[] wrappers){
|
||||||
|
for(int i = 0; i < wrappers.length; i++){
|
||||||
|
wrappers[i] = new SidedInvWrapper(this, EnumFacing.values()[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveSlots(ItemStack[] slots, NBTTagCompound compound){
|
public static void saveSlots(ItemStack[] slots, NBTTagCompound compound){
|
||||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -36,6 +37,35 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getInvWrappers(SidedInvWrapper[] wrappers){
|
||||||
|
for(int i = 0; i < wrappers.length; i++){
|
||||||
|
wrappers[i] = new SidedInvWrapper(this, EnumFacing.values()[i]){
|
||||||
|
@Override
|
||||||
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
|
||||||
|
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
|
if(info != null){
|
||||||
|
return info.handler.insertItem(info.switchedIndex, stack, simulate);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return super.insertItem(slot, stack, simulate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack extractItem(int slot, int amount, boolean simulate){
|
||||||
|
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
|
if(info != null){
|
||||||
|
return info.handler.extractItem(info.switchedIndex, amount, simulate);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return super.extractItem(slot, amount, simulate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||||
TileEntityLaserRelayItem relay = this.connectedRelay;
|
TileEntityLaserRelayItem relay = this.connectedRelay;
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
|
|
Loading…
Reference in a new issue