pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -29,7 +28,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -42,6 +40,7 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.exceptions.MissingDefinitionException;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
@@ -50,7 +49,6 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
@@ -59,191 +57,159 @@ import appeng.items.materials.MaterialType;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* @author DrummerMC
|
||||
* @version rv6 - 2018-01-17
|
||||
* @since rv6 2018-01-17
|
||||
*/
|
||||
public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseItem implements IStorageCell<T>, IItemGroup
|
||||
{
|
||||
protected final MaterialType component;
|
||||
protected final int totalBytes;
|
||||
public abstract class AbstractStorageCell<T extends IAEStack<T>> extends AEBaseItem
|
||||
implements IStorageCell<T>, IItemGroup {
|
||||
protected final MaterialType component;
|
||||
protected final int totalBytes;
|
||||
|
||||
public AbstractStorageCell(Properties properties, final MaterialType whichCell, final int kilobytes ) {
|
||||
super(properties);
|
||||
this.totalBytes = kilobytes * 1024;
|
||||
this.component = whichCell;
|
||||
}
|
||||
public AbstractStorageCell(Properties properties, final MaterialType whichCell, final int kilobytes) {
|
||||
super(properties);
|
||||
this.totalBytes = kilobytes * 1024;
|
||||
this.component = whichCell;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
AEApi.instance()
|
||||
.client()
|
||||
.addCellInformation( AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() ), lines );
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
AEApi.instance().client().addCellInformation(
|
||||
AEApi.instance().registries().cell().getCellInventory(stack, null, this.getChannel()), lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes( final ItemStack cellItem )
|
||||
{
|
||||
return this.totalBytes;
|
||||
}
|
||||
@Override
|
||||
public int getBytes(final ItemStack cellItem) {
|
||||
return this.totalBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes( final ItemStack cellItem )
|
||||
{
|
||||
return 63;
|
||||
}
|
||||
@Override
|
||||
public int getTotalTypes(final ItemStack cellItem) {
|
||||
return 63;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed( final ItemStack cellItem, final T requestedAddition )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isBlackListed(final ItemStack cellItem, final T requestedAddition) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell( final ItemStack i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isStorageCell(final ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedGroupName( final Set<ItemStack> others, final ItemStack is )
|
||||
{
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
@Override
|
||||
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
|
||||
return GuiText.StorageCells.getTranslationKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable( final ItemStack is )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEditable(final ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory(final ItemStack is) {
|
||||
return new CellUpgrades(is, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getConfigInventory(final ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode( final ItemStack is )
|
||||
{
|
||||
final String fz = is.getOrCreateTag().getString( "FuzzyMode" );
|
||||
try
|
||||
{
|
||||
return FuzzyMode.valueOf( fz );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(final ItemStack is) {
|
||||
final String fz = is.getOrCreateTag().getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
|
||||
{
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
is.getOrCreateTag().putString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World world, final PlayerEntity player, final Hand hand )
|
||||
{
|
||||
this.disassembleDrive( player.getHeldItem( hand ), world, player );
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
|
||||
}
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World world, final PlayerEntity player, final Hand hand) {
|
||||
this.disassembleDrive(player.getHeldItem(hand), world, player);
|
||||
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
private boolean disassembleDrive( final ItemStack stack, final World world, final PlayerEntity player )
|
||||
{
|
||||
if( player.isCrouching() )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private boolean disassembleDrive(final ItemStack stack, final World world, final PlayerEntity player) {
|
||||
if (player.isCrouching()) {
|
||||
if (Platform.isClient()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PlayerInventory playerInventory = player.inventory;
|
||||
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() );
|
||||
if( inv != null && playerInventory.getCurrentItem() == stack )
|
||||
{
|
||||
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
|
||||
final IItemList<IAEItemStack> list = inv.getAvailableItems( this.getChannel().createList() );
|
||||
if( list.isEmpty() && ia != null )
|
||||
{
|
||||
playerInventory.setInventorySlotContents( playerInventory.currentItem, ItemStack.EMPTY );
|
||||
final PlayerInventory playerInventory = player.inventory;
|
||||
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory(stack, null,
|
||||
this.getChannel());
|
||||
if (inv != null && playerInventory.getCurrentItem() == stack) {
|
||||
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor(player);
|
||||
final IItemList<IAEItemStack> list = inv.getAvailableItems(this.getChannel().createList());
|
||||
if (list.isEmpty() && ia != null) {
|
||||
playerInventory.setInventorySlotContents(playerInventory.currentItem, ItemStack.EMPTY);
|
||||
|
||||
// drop core
|
||||
final ItemStack extraB = ia.addItems( this.component.stack( 1 ) );
|
||||
if( !extraB.isEmpty() )
|
||||
{
|
||||
player.dropItem( extraB, false );
|
||||
}
|
||||
// drop core
|
||||
final ItemStack extraB = ia.addItems(this.component.stack(1));
|
||||
if (!extraB.isEmpty()) {
|
||||
player.dropItem(extraB, false);
|
||||
}
|
||||
|
||||
// drop upgrades
|
||||
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
|
||||
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )
|
||||
{
|
||||
final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex );
|
||||
final ItemStack leftStack = ia.addItems( upgradeStack );
|
||||
if( !leftStack.isEmpty() && upgradeStack.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
player.dropItem( upgradeStack, false );
|
||||
}
|
||||
}
|
||||
// drop upgrades
|
||||
final IItemHandler upgradesInventory = this.getUpgradesInventory(stack);
|
||||
for (int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++) {
|
||||
final ItemStack upgradeStack = upgradesInventory.getStackInSlot(upgradeIndex);
|
||||
final ItemStack leftStack = ia.addItems(upgradeStack);
|
||||
if (!leftStack.isEmpty() && upgradeStack.getItem() instanceof IUpgradeModule) {
|
||||
player.dropItem(upgradeStack, false);
|
||||
}
|
||||
}
|
||||
|
||||
// drop empty storage cell case
|
||||
this.dropEmptyStorageCellCase( ia, player );
|
||||
// drop empty storage cell case
|
||||
this.dropEmptyStorageCellCase(ia, player);
|
||||
|
||||
if( player.container != null )
|
||||
{
|
||||
player.container.detectAndSendChanges();
|
||||
}
|
||||
if (player.container != null) {
|
||||
player.container.detectAndSendChanges();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract void dropEmptyStorageCellCase( final InventoryAdaptor ia, final PlayerEntity player );
|
||||
protected abstract void dropEmptyStorageCellCase(final InventoryAdaptor ia, final PlayerEntity player);
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUseFirst( ItemStack stack, ItemUseContext context )
|
||||
{
|
||||
return this.disassembleDrive( stack, context.getWorld(), context.getPlayer() ) ? ActionResultType.SUCCESS : ActionResultType.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem( final ItemStack itemStack )
|
||||
{
|
||||
return AEApi.instance()
|
||||
.definitions()
|
||||
.materials()
|
||||
.emptyStorageCell()
|
||||
.maybeStack( 1 )
|
||||
.orElseThrow( () -> new MissingDefinitionException( "Tried to use empty storage cells while basic storage cells are defined." ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainerItem( final ItemStack stack )
|
||||
{
|
||||
return AEConfig.instance().isFeatureEnabled( AEFeature.ENABLE_DISASSEMBLY_CRAFTING );
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
|
||||
return this.disassembleDrive(stack, context.getWorld(), context.getPlayer()) ? ActionResultType.SUCCESS
|
||||
: ActionResultType.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem(final ItemStack itemStack) {
|
||||
return AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1)
|
||||
.orElseThrow(() -> new MissingDefinitionException(
|
||||
"Tried to use empty storage cells while basic storage cells are defined."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainerItem(final ItemStack stack) {
|
||||
return AEConfig.instance().isFeatureEnabled(AEFeature.ENABLE_DISASSEMBLY_CRAFTING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user