reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
@@ -19,23 +19,6 @@
package appeng.items.storage;
import java.util.List;
import java.util.Set;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.exceptions.MissingDefinitionException;
@@ -55,6 +38,22 @@ import appeng.items.contents.CellUpgrades;
import appeng.items.materials.MaterialType;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import java.util.Set;
/**
@@ -62,183 +61,153 @@ import appeng.util.Platform;
* @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( final MaterialType whichCell, final int kilobytes )
{
this.setMaxStackSize( 1 );
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
}
public AbstractStorageCell(final MaterialType whichCell, final int kilobytes) {
this.setMaxStackSize(1);
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
AEApi.instance()
.client()
.addCellInformation( AEApi.instance().registries().cell().getCellInventory( stack, null, this.getChannel() ), lines );
}
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> 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.getUnlocalized();
}
@Override
public String getUnlocalizedGroupName(final Set<ItemStack> others, final ItemStack is) {
return GuiText.StorageCells.getUnlocalized();
}
@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 = Platform.openNbtData( is ).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 = Platform.openNbtData(is).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 )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public ActionResult<ItemStack> onItemRightClick( final World world, final EntityPlayer player, final EnumHand hand )
{
this.disassembleDrive( player.getHeldItem( hand ), world, player );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World world, final EntityPlayer player, final EnumHand hand) {
this.disassembleDrive(player.getHeldItem(hand), world, player);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
private boolean disassembleDrive( final ItemStack stack, final World world, final EntityPlayer player )
{
if( player.isSneaking() )
{
if( Platform.isClient() )
{
return false;
}
private boolean disassembleDrive(final ItemStack stack, final World world, final EntityPlayer player) {
if (player.isSneaking()) {
if (Platform.isClient()) {
return false;
}
final InventoryPlayer 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 InventoryPlayer 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.inventoryContainer != null )
{
player.inventoryContainer.detectAndSendChanges();
}
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
}
}
}
return false;
}
return true;
}
}
}
return false;
}
protected abstract void dropEmptyStorageCellCase( final InventoryAdaptor ia, final EntityPlayer player );
protected abstract void dropEmptyStorageCellCase(final InventoryAdaptor ia, final EntityPlayer player);
@Override
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
{
return this.disassembleDrive( player.getHeldItem( hand ), world, player ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
return this.disassembleDrive(player.getHeldItem(hand), world, player) ? EnumActionResult.SUCCESS : EnumActionResult.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 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 boolean hasContainerItem(final ItemStack stack) {
return AEConfig.instance().isFeatureEnabled(AEFeature.ENABLE_DISASSEMBLY_CRAFTING);
}
}
@@ -19,79 +19,70 @@
package appeng.items.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.items.materials.MaterialType;
import appeng.util.InventoryAdaptor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
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( final MaterialType whichCell, final int kilobytes )
{
super( whichCell, kilobytes );
switch( whichCell )
{
case CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case CELL64K_PART:
this.idleDrain = 2.0;
this.perType = 512;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
public BasicItemStorageCell(final MaterialType whichCell, final int kilobytes) {
super(whichCell, kilobytes);
switch (whichCell) {
case CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case CELL64K_PART:
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 EntityPlayer 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 EntityPlayer player) {
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is ->
{
final ItemStack extraA = ia.addItems(is);
if (!extraA.isEmpty()) {
player.dropItem(extraA, false);
}
});
}
}
@@ -19,15 +19,6 @@
package appeng.items.storage;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.ICellInventoryHandler;
@@ -36,67 +27,64 @@ import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem
{
public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenchItem {
public ItemCreativeStorageCell()
{
this.setMaxStackSize( 1 );
}
public ItemCreativeStorageCell() {
this.setMaxStackSize(1);
}
@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) {
}
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final IMEInventoryHandler<?> inventory = AEApi.instance()
.registries()
.cell()
.getCellInventory( stack, null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> 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());
}
}
}
}
}
@@ -19,17 +19,6 @@
package appeng.items.storage;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.TransitionResult;
import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.storage.ISpatialDimension;
@@ -40,151 +29,137 @@ import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.spatial.StorageHelper;
import appeng.util.Platform;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
{
private static final String NBT_CELL_ID_KEY = "StorageCellID";
private static final String NBT_SIZE_X_KEY = "sizeX";
private static final String NBT_SIZE_Y_KEY = "sizeY";
private static final String NBT_SIZE_Z_KEY = "sizeZ";
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell {
private static final String NBT_CELL_ID_KEY = "StorageCellID";
private static final String NBT_SIZE_X_KEY = "sizeX";
private static final String NBT_SIZE_Y_KEY = "sizeY";
private static final String NBT_SIZE_Z_KEY = "sizeZ";
private final int maxRegion;
private final int maxRegion;
public ItemSpatialStorageCell( final int spatialScale )
{
this.setMaxStackSize( 1 );
this.maxRegion = spatialScale;
}
public ItemSpatialStorageCell(final int spatialScale) {
this.setMaxStackSize(1);
this.maxRegion = spatialScale;
}
@SideOnly( Side.CLIENT )
@Override
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
{
final int id = this.getStoredDimensionID( stack );
if( id >= 0 )
{
lines.add( GuiText.CellId.getLocal() + ": " + id );
}
@SideOnly(Side.CLIENT)
@Override
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
final int id = this.getStoredDimensionID(stack);
if (id >= 0) {
lines.add(GuiText.CellId.getLocal() + ": " + id);
}
final WorldCoord wc = this.getStoredSize( stack );
if( wc.x > 0 )
{
lines.add( GuiText.StoredSize.getLocal() + ": " + wc.x + " x " + wc.y + " x " + wc.z );
}
}
final WorldCoord wc = this.getStoredSize(stack);
if (wc.x > 0) {
lines.add(GuiText.StoredSize.getLocal() + ": " + wc.x + " x " + wc.y + " x " + wc.z);
}
}
@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 ISpatialDimension getSpatialDimension()
{
final int id = AppEng.instance().getStorageDimensionID();
World w = DimensionManager.getWorld( id );
if( w == null )
{
DimensionManager.initDimension( id );
w = DimensionManager.getWorld( id );
}
@Override
public ISpatialDimension getSpatialDimension() {
final int id = AppEng.instance().getStorageDimensionID();
World w = DimensionManager.getWorld(id);
if (w == null) {
DimensionManager.initDimension(id);
w = DimensionManager.getWorld(id);
}
if( w != null && w.hasCapability( Capabilities.SPATIAL_DIMENSION, null ) )
{
return w.getCapability( Capabilities.SPATIAL_DIMENSION, null );
}
return null;
}
if (w != null && w.hasCapability(Capabilities.SPATIAL_DIMENSION, null)) {
return w.getCapability(Capabilities.SPATIAL_DIMENSION, null);
}
return null;
}
@Override
public WorldCoord getStoredSize( final ItemStack is )
{
if( is.hasTagCompound() )
{
final NBTTagCompound c = is.getTagCompound();
return new WorldCoord( c.getInteger( NBT_SIZE_X_KEY ), c.getInteger( NBT_SIZE_Y_KEY ), c.getInteger( NBT_SIZE_Z_KEY ) );
}
return new WorldCoord( 0, 0, 0 );
}
@Override
public WorldCoord getStoredSize(final ItemStack is) {
if (is.hasTagCompound()) {
final NBTTagCompound c = is.getTagCompound();
return new WorldCoord(c.getInteger(NBT_SIZE_X_KEY), c.getInteger(NBT_SIZE_Y_KEY), c.getInteger(NBT_SIZE_Z_KEY));
}
return new WorldCoord(0, 0, 0);
}
@Override
public int getStoredDimensionID( final ItemStack is )
{
if( is.hasTagCompound() )
{
final NBTTagCompound c = is.getTagCompound();
return c.getInteger( NBT_CELL_ID_KEY );
}
return -1;
}
@Override
public int getStoredDimensionID(final ItemStack is) {
if (is.hasTagCompound()) {
final NBTTagCompound c = is.getTagCompound();
return c.getInteger(NBT_CELL_ID_KEY);
}
return -1;
}
@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 = this.getSpatialDimension();
ISpatialDimension manager = this.getSpatialDimension();
int cellid = this.getStoredDimensionID( is );
if( cellid < 0 )
{
cellid = manager.createNewCellDimension( targetSize, playerId );
}
int cellid = this.getStoredDimensionID(is);
if (cellid < 0) {
cellid = manager.createNewCellDimension(targetSize, playerId);
}
try
{
if( manager.isCellDimension( cellid ) )
{
BlockPos scale = manager.getCellContentSize( cellid );
try {
if (manager.isCellDimension(cellid)) {
BlockPos scale = manager.getCellContentSize(cellid);
if( scale.equals( targetSize ) )
{
if( targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize )
{
BlockPos offset = manager.getCellDimensionOrigin( cellid );
if (scale.equals(targetSize)) {
if (targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize) {
BlockPos offset = manager.getCellDimensionOrigin(cellid);
this.setStorageCell( is, cellid, targetSize );
StorageHelper.getInstance()
.swapRegions( w, min.x + 1, min.y + 1, min.z + 1, manager.getWorld(), offset.getX(), offset.getY(),
offset.getZ(), targetX - 1, targetY - 1,
targetZ - 1 );
this.setStorageCell(is, cellid, targetSize);
StorageHelper.getInstance()
.swapRegions(w, min.x + 1, min.y + 1, min.z + 1, manager.getWorld(), 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( cellid ) && this.getStoredDimensionID( is ) < 0 )
{
manager.deleteCellDimension( cellid );
}
}
}
return new TransitionResult(true, 0);
}
}
}
return new TransitionResult(false, 0);
} finally {
// clean up newly created dimensions that failed transfer
if (manager.isCellDimension(cellid) && this.getStoredDimensionID(is) < 0) {
manager.deleteCellDimension(cellid);
}
}
}
private void setStorageCell( final ItemStack is, int id, BlockPos size )
{
final NBTTagCompound c = Platform.openNbtData( is );
private void setStorageCell(final ItemStack is, int id, BlockPos size) {
final NBTTagCompound c = Platform.openNbtData(is);
c.setInteger( NBT_CELL_ID_KEY, id );
c.setInteger( NBT_SIZE_X_KEY, size.getX() );
c.setInteger( NBT_SIZE_Y_KEY, size.getY() );
c.setInteger( NBT_SIZE_Z_KEY, size.getZ() );
}
c.setInteger(NBT_CELL_ID_KEY, id);
c.setInteger(NBT_SIZE_X_KEY, size.getX());
c.setInteger(NBT_SIZE_Y_KEY, size.getY());
c.setInteger(NBT_SIZE_Z_KEY, size.getZ());
}
}
@@ -19,9 +19,6 @@
package appeng.items.storage;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Upgrades;
@@ -39,125 +36,103 @@ import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.IPartitionList;
import appeng.util.prioritylist.MergedPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
{
public ItemViewCell()
{
this.setMaxStackSize( 1 );
}
public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem {
public ItemViewCell() {
this.setMaxStackSize(1);
}
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 = Platform.openNbtData( is ).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 = Platform.openNbtData(is).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 )
{
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
}
@Override
public void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
}