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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -29,69 +28,59 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.items.materials.MaterialType;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack> {
|
||||
|
||||
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack>
|
||||
{
|
||||
protected final int perType;
|
||||
protected final double idleDrain;
|
||||
|
||||
protected final int perType;
|
||||
protected final double idleDrain;
|
||||
public BasicItemStorageCell(Properties props, final MaterialType whichCell, final int kilobytes) {
|
||||
super(props, whichCell, kilobytes);
|
||||
switch (whichCell) {
|
||||
case ITEM_1K_CELL_COMPONENT:
|
||||
this.idleDrain = 0.5;
|
||||
this.perType = 8;
|
||||
break;
|
||||
case ITEM_4K_CELL_COMPONENT:
|
||||
this.idleDrain = 1.0;
|
||||
this.perType = 32;
|
||||
break;
|
||||
case ITEM_16K_CELL_COMPONENT:
|
||||
this.idleDrain = 1.5;
|
||||
this.perType = 128;
|
||||
break;
|
||||
case ITEM_64K_CELL_COMPONENT:
|
||||
this.idleDrain = 2.0;
|
||||
this.perType = 512;
|
||||
break;
|
||||
default:
|
||||
this.idleDrain = 0.0;
|
||||
this.perType = 8;
|
||||
}
|
||||
|
||||
public BasicItemStorageCell( Properties props, final MaterialType whichCell, final int kilobytes )
|
||||
{
|
||||
super( props, whichCell, kilobytes );
|
||||
switch( whichCell )
|
||||
{
|
||||
case ITEM_1K_CELL_COMPONENT:
|
||||
this.idleDrain = 0.5;
|
||||
this.perType = 8;
|
||||
break;
|
||||
case ITEM_4K_CELL_COMPONENT:
|
||||
this.idleDrain = 1.0;
|
||||
this.perType = 32;
|
||||
break;
|
||||
case ITEM_16K_CELL_COMPONENT:
|
||||
this.idleDrain = 1.5;
|
||||
this.perType = 128;
|
||||
break;
|
||||
case ITEM_64K_CELL_COMPONENT:
|
||||
this.idleDrain = 2.0;
|
||||
this.perType = 512;
|
||||
break;
|
||||
default:
|
||||
this.idleDrain = 0.0;
|
||||
this.perType = 8;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int getBytesPerType(ItemStack cellItem) {
|
||||
return this.perType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType( ItemStack cellItem )
|
||||
{
|
||||
return this.perType;
|
||||
}
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return this.idleDrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return this.idleDrain;
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dropEmptyStorageCellCase( final InventoryAdaptor ia, final PlayerEntity player )
|
||||
{
|
||||
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is ->
|
||||
{
|
||||
final ItemStack extraA = ia.addItems( is );
|
||||
if( !extraA.isEmpty() )
|
||||
{
|
||||
player.dropItem( extraA, false );
|
||||
}
|
||||
} );
|
||||
}
|
||||
@Override
|
||||
protected void dropEmptyStorageCellCase(final InventoryAdaptor ia, final PlayerEntity player) {
|
||||
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is -> {
|
||||
final ItemStack extraA = ia.addItems(is);
|
||||
if (!extraA.isEmpty()) {
|
||||
player.dropItem(extraA, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
@@ -38,66 +37,52 @@ import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.contents.CellConfig;
|
||||
|
||||
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem {
|
||||
|
||||
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
{
|
||||
public ItemCreativeStorageCell(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public ItemCreativeStorageCell(Properties props)
|
||||
{
|
||||
super(props);
|
||||
}
|
||||
@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 null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@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) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode( final ItemStack is )
|
||||
{
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
@Override
|
||||
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode( final ItemStack is, final FuzzyMode fzMode )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell().getCellInventory(stack, null,
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final IMEInventoryHandler<?> inventory = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( stack, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if (inventory instanceof ICellInventoryHandler) {
|
||||
final CellConfig cc = new CellConfig(stack);
|
||||
|
||||
if( inventory instanceof ICellInventoryHandler )
|
||||
{
|
||||
final CellConfig cc = new CellConfig( stack );
|
||||
|
||||
for( final ItemStack is : cc )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
lines.add( is.getDisplayName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : cc) {
|
||||
if (!is.isEmpty()) {
|
||||
lines.add(is.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,8 @@
|
||||
|
||||
package appeng.items.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.spatial.SpatialDimensionManager;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.spatial.StorageHelper;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -41,130 +33,120 @@ import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.spatial.SpatialDimensionManager;
|
||||
import appeng.spatial.StorageHelper;
|
||||
|
||||
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell {
|
||||
private static final String TAG_DIMENSION_ID = "dimension_id";
|
||||
|
||||
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
|
||||
{
|
||||
private static final String TAG_DIMENSION_ID = "dimension_id";
|
||||
private final int maxRegion;
|
||||
|
||||
private final int maxRegion;
|
||||
public ItemSpatialStorageCell(Properties props, final int spatialScale) {
|
||||
super(props);
|
||||
this.maxRegion = spatialScale;
|
||||
}
|
||||
|
||||
public ItemSpatialStorageCell( Properties props, final int spatialScale )
|
||||
{
|
||||
super(props);
|
||||
this.maxRegion = spatialScale;
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
|
||||
final ITooltipFlag advancedTooltips) {
|
||||
final DimensionType dimType = this.getStoredDimension(stack);
|
||||
if (dimType == null) {
|
||||
lines.add(GuiText.Unformatted.textComponent().applyTextStyle(TextFormatting.ITALIC));
|
||||
lines.add(GuiText.SpatialCapacity.textComponent(maxRegion, maxRegion, maxRegion));
|
||||
} else {
|
||||
SpatialDimensionManager.INSTANCE.addCellDimensionTooltip(dimType, lines);
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final DimensionType dimType = this.getStoredDimension(stack);
|
||||
if (dimType == null) {
|
||||
lines.add(GuiText.Unformatted.textComponent().applyTextStyle(TextFormatting.ITALIC));
|
||||
lines.add( GuiText.SpatialCapacity.textComponent(maxRegion, maxRegion, maxRegion));
|
||||
} else {
|
||||
SpatialDimensionManager.INSTANCE.addCellDimensionTooltip(dimType, lines);
|
||||
}
|
||||
if (advancedTooltips.isAdvanced()) {
|
||||
if (dimType != null && dimType.getRegistryName() != null) {
|
||||
lines.add(new StringTextComponent("Dimension: " + dimType.getRegistryName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (advancedTooltips.isAdvanced()) {
|
||||
if (dimType != null && dimType.getRegistryName() != null) {
|
||||
lines.add(new StringTextComponent("Dimension: " + dimType.getRegistryName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isSpatialStorage(final ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpatialStorage( final ItemStack is )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int getMaxStoredDim(final ItemStack is) {
|
||||
return this.maxRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStoredDim( final ItemStack is )
|
||||
{
|
||||
return this.maxRegion;
|
||||
}
|
||||
@Override
|
||||
public DimensionType getStoredDimension(final ItemStack is) {
|
||||
final CompoundNBT c = is.getTag();
|
||||
if (c != null && c.contains(TAG_DIMENSION_ID)) {
|
||||
try {
|
||||
ResourceLocation dimTypeId = new ResourceLocation(c.getString(TAG_DIMENSION_ID));
|
||||
return DimensionType.byName(dimTypeId);
|
||||
} catch (Exception e) {
|
||||
AELog.warn("Failed to retrieve storage cell dimension.", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionType getStoredDimension(final ItemStack is )
|
||||
{
|
||||
final CompoundNBT c = is.getTag();
|
||||
if( c != null && c.contains(TAG_DIMENSION_ID) )
|
||||
{
|
||||
try {
|
||||
ResourceLocation dimTypeId = new ResourceLocation(c.getString(TAG_DIMENSION_ID) );
|
||||
return DimensionType.byName(dimTypeId);
|
||||
} catch (Exception e) {
|
||||
AELog.warn("Failed to retrieve storage cell dimension.", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public TransitionResult doSpatialTransition(final ItemStack is, final World w, final WorldCoord min,
|
||||
final WorldCoord max, int playerId) {
|
||||
final int targetX = max.x - min.x - 1;
|
||||
final int targetY = max.y - min.y - 1;
|
||||
final int targetZ = max.z - min.z - 1;
|
||||
final int maxSize = this.getMaxStoredDim(is);
|
||||
|
||||
@Override
|
||||
public TransitionResult doSpatialTransition( final ItemStack is, final World w, final WorldCoord min, final WorldCoord max, int playerId )
|
||||
{
|
||||
final int targetX = max.x - min.x - 1;
|
||||
final int targetY = max.y - min.y - 1;
|
||||
final int targetZ = max.z - min.z - 1;
|
||||
final int maxSize = this.getMaxStoredDim( is );
|
||||
final BlockPos targetSize = new BlockPos(targetX, targetY, targetZ);
|
||||
|
||||
final BlockPos targetSize = new BlockPos( targetX, targetY, targetZ );
|
||||
ISpatialDimension manager = SpatialDimensionManager.INSTANCE;
|
||||
|
||||
ISpatialDimension manager = SpatialDimensionManager.INSTANCE;
|
||||
DimensionType storedDim = this.getStoredDimension(is);
|
||||
if (storedDim == null) {
|
||||
storedDim = manager.createNewCellDimension(targetSize);
|
||||
}
|
||||
|
||||
DimensionType storedDim = this.getStoredDimension( is );
|
||||
if( storedDim == null )
|
||||
{
|
||||
storedDim = manager.createNewCellDimension( targetSize);
|
||||
}
|
||||
if (storedDim == null) {
|
||||
// Failed to create the dimension
|
||||
return new TransitionResult(false, 0);
|
||||
}
|
||||
|
||||
if (storedDim == null) {
|
||||
// Failed to create the dimension
|
||||
return new TransitionResult(false, 0);
|
||||
}
|
||||
try {
|
||||
if (manager.isCellDimension(storedDim)) {
|
||||
World cellWorld = manager.getWorld(storedDim);
|
||||
|
||||
try
|
||||
{
|
||||
if( manager.isCellDimension( storedDim ) )
|
||||
{
|
||||
World cellWorld = manager.getWorld(storedDim);
|
||||
BlockPos scale = manager.getCellDimensionSize(storedDim);
|
||||
|
||||
BlockPos scale = manager.getCellDimensionSize( storedDim );
|
||||
if (scale.equals(targetSize)) {
|
||||
if (targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize) {
|
||||
BlockPos offset = manager.getCellDimensionOrigin(storedDim);
|
||||
|
||||
if( scale.equals( targetSize ) )
|
||||
{
|
||||
if( targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize )
|
||||
{
|
||||
BlockPos offset = manager.getCellDimensionOrigin( storedDim );
|
||||
this.setStoredDimension(is, storedDim);
|
||||
StorageHelper.getInstance().swapRegions(w, min.x + 1, min.y + 1, min.z + 1, cellWorld,
|
||||
offset.getX(), offset.getY(), offset.getZ(), targetX - 1, targetY - 1, targetZ - 1);
|
||||
|
||||
this.setStoredDimension( is, storedDim);
|
||||
StorageHelper.getInstance()
|
||||
.swapRegions( w, min.x + 1, min.y + 1, min.z + 1, cellWorld, offset.getX(), offset.getY(),
|
||||
offset.getZ(), targetX - 1, targetY - 1,
|
||||
targetZ - 1 );
|
||||
return new TransitionResult(true, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TransitionResult(false, 0);
|
||||
} finally {
|
||||
// clean up newly created dimensions that failed transfer
|
||||
if (manager.isCellDimension(storedDim) && this.getStoredDimension(is) == null) {
|
||||
manager.deleteCellDimension(storedDim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new TransitionResult( true, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TransitionResult( false, 0 );
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clean up newly created dimensions that failed transfer
|
||||
if( manager.isCellDimension( storedDim ) && this.getStoredDimension( is ) == null )
|
||||
{
|
||||
manager.deleteCellDimension( storedDim );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setStoredDimension(final ItemStack is, DimensionType dim)
|
||||
{
|
||||
private void setStoredDimension(final ItemStack is, DimensionType dim) {
|
||||
final CompoundNBT c = is.getOrCreateTag();
|
||||
c.putString(TAG_DIMENSION_ID, dim.getRegistryName().toString() );
|
||||
}
|
||||
c.putString(TAG_DIMENSION_ID, dim.getRegistryName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
@@ -40,124 +39,101 @@ import appeng.util.prioritylist.IPartitionList;
|
||||
import appeng.util.prioritylist.MergedPriorityList;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem {
|
||||
|
||||
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
{
|
||||
public ItemViewCell(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
public ItemViewCell(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
public static IPartitionList<IAEItemStack> createFilter(final ItemStack[] list) {
|
||||
IPartitionList<IAEItemStack> myPartitionList = null;
|
||||
|
||||
public static IPartitionList<IAEItemStack> createFilter(final ItemStack[] list )
|
||||
{
|
||||
IPartitionList<IAEItemStack> myPartitionList = null;
|
||||
final MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<>();
|
||||
|
||||
final MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<>();
|
||||
for (final ItemStack currentViewCell : list) {
|
||||
if (currentViewCell == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( final ItemStack currentViewCell : list )
|
||||
{
|
||||
if( currentViewCell == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ((currentViewCell.getItem() instanceof ItemViewCell)) {
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
if( ( currentViewCell.getItem() instanceof ItemViewCell ) )
|
||||
{
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
|
||||
final IItemHandler upgrades = vc.getUpgradesInventory(currentViewCell);
|
||||
final IItemHandler config = vc.getConfigInventory(currentViewCell);
|
||||
final FuzzyMode fzMode = vc.getFuzzyMode(currentViewCell);
|
||||
|
||||
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
|
||||
final IItemHandler upgrades = vc.getUpgradesInventory( currentViewCell );
|
||||
final IItemHandler config = vc.getConfigInventory( currentViewCell );
|
||||
final FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
|
||||
boolean hasInverter = false;
|
||||
boolean hasFuzzy = false;
|
||||
|
||||
boolean hasInverter = false;
|
||||
boolean hasFuzzy = false;
|
||||
for (int x = 0; x < upgrades.getSlots(); x++) {
|
||||
final ItemStack is = upgrades.getStackInSlot(x);
|
||||
if (!is.isEmpty() && is.getItem() instanceof IUpgradeModule) {
|
||||
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
|
||||
if (u != null) {
|
||||
switch (u) {
|
||||
case FUZZY:
|
||||
hasFuzzy = true;
|
||||
break;
|
||||
case INVERTER:
|
||||
hasInverter = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < upgrades.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = upgrades.getStackInSlot( x );
|
||||
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
final Upgrades u = ( (IUpgradeModule) is.getItem() ).getType( is );
|
||||
if( u != null )
|
||||
{
|
||||
switch( u )
|
||||
{
|
||||
case FUZZY:
|
||||
hasFuzzy = true;
|
||||
break;
|
||||
case INVERTER:
|
||||
hasInverter = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < config.getSlots(); x++) {
|
||||
final ItemStack is = config.getStackInSlot(x);
|
||||
if (!is.isEmpty()) {
|
||||
priorityList.add(AEItemStack.fromItemStack(is));
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < config.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = config.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
priorityList.add( AEItemStack.fromItemStack( is ) );
|
||||
}
|
||||
}
|
||||
if (!priorityList.isEmpty()) {
|
||||
if (hasFuzzy) {
|
||||
myMergedList.addNewList(new FuzzyPriorityList<>(priorityList, fzMode), !hasInverter);
|
||||
} else {
|
||||
myMergedList.addNewList(new PrecisePriorityList<>(priorityList), !hasInverter);
|
||||
}
|
||||
|
||||
if( !priorityList.isEmpty() )
|
||||
{
|
||||
if( hasFuzzy )
|
||||
{
|
||||
myMergedList.addNewList( new FuzzyPriorityList<>( priorityList, fzMode ), !hasInverter );
|
||||
}
|
||||
else
|
||||
{
|
||||
myMergedList.addNewList( new PrecisePriorityList<>( priorityList ), !hasInverter );
|
||||
}
|
||||
myPartitionList = myMergedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myPartitionList = myMergedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
return myPartitionList;
|
||||
}
|
||||
|
||||
return myPartitionList;
|
||||
}
|
||||
@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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user