More stuff ingame and showing up.
This commit is contained in:
@@ -22,17 +22,15 @@ package appeng.tile;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
@@ -45,17 +43,21 @@ import appeng.util.inv.InvOperation;
|
||||
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
public AEBaseInvTile(TileEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
public void read(final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
super.read( data );
|
||||
final IItemHandler inv = this.getInternalInventory();
|
||||
if( inv != EmptyHandler.INSTANCE )
|
||||
{
|
||||
final CompoundNBT opt = data.getCompoundTag( "inv" );
|
||||
final CompoundNBT opt = data.getCompound( "inv" );
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
final CompoundNBT item = opt.getCompoundTag( "item" + x );
|
||||
final CompoundNBT item = opt.getCompound( "item" + x );
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.read(item) );
|
||||
}
|
||||
}
|
||||
@@ -64,9 +66,9 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
|
||||
public abstract @Nonnull IItemHandler getInternalInventory();
|
||||
|
||||
@Override
|
||||
public CompoundNBT writeToNBT( final CompoundNBT data )
|
||||
public CompoundNBT write(final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
super.write( data );
|
||||
final IItemHandler inv = this.getInternalInventory();
|
||||
if( inv != EmptyHandler.INSTANCE )
|
||||
{
|
||||
@@ -79,9 +81,9 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
|
||||
{
|
||||
is.write(item);
|
||||
}
|
||||
opt.setTag( "item" + x, item );
|
||||
opt.put( "item" + x, item );
|
||||
}
|
||||
data.setTag( "inv", opt );
|
||||
data.put( "inv", opt );
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -104,51 +106,23 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
|
||||
@Override
|
||||
public abstract void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
if( this.hasCustomInventoryName() )
|
||||
{
|
||||
return new TextComponentString( this.getCustomInventoryName() );
|
||||
}
|
||||
return new TextComponentTranslation( this.getBlockType().getTranslationKey() );
|
||||
}
|
||||
|
||||
protected @Nonnull IItemHandler getItemHandlerForSide( @Nonnull Direction side )
|
||||
{
|
||||
return this.getInternalInventory();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capability, Direction facing )
|
||||
{
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, Direction facing) {
|
||||
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
if( facing == null )
|
||||
{
|
||||
return this.getInternalInventory() != EmptyHandler.INSTANCE;
|
||||
return (LazyOptional<T>) LazyOptional.of(this::getInternalInventory);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.getItemHandlerForSide( facing ) != EmptyHandler.INSTANCE;
|
||||
}
|
||||
}
|
||||
return super.hasCapability( capability, facing );
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capability, @Nullable Direction facing )
|
||||
{
|
||||
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
if( facing == null )
|
||||
{
|
||||
return (T) this.getInternalInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T) this.getItemHandlerForSide( facing );
|
||||
return (LazyOptional<T>) LazyOptional.of(() -> getItemHandlerForSide( facing ));
|
||||
}
|
||||
}
|
||||
return super.getCapability( capability, facing );
|
||||
|
||||
Reference in New Issue
Block a user