Files
Applied-Energistics-2/src/main/java/appeng/tile/crafting/CraftingStorageTileEntity.java
T
yueh 0d43ca15be Removed AEApi
Moved all internal access to the internal `Api` class using a new static
getter.
2020-07-11 19:40:34 +02:00

96 lines
2.9 KiB
Java

/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.tile.crafting;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityType;
import appeng.api.definitions.IBlocks;
import appeng.block.crafting.AbstractCraftingUnitBlock;
import appeng.core.Api;
public class CraftingStorageTileEntity extends CraftingTileEntity {
private static final int KILO_SCALAR = 1024;
public CraftingStorageTileEntity(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@Override
protected ItemStack getItemFromTile(final Object obj) {
final IBlocks blocks = Api.instance().definitions().blocks();
final int storage = ((CraftingTileEntity) obj).getStorageBytes() / KILO_SCALAR;
Optional<ItemStack> is;
switch (storage) {
case 1:
is = blocks.craftingStorage1k().maybeStack(1);
break;
case 4:
is = blocks.craftingStorage4k().maybeStack(1);
break;
case 16:
is = blocks.craftingStorage16k().maybeStack(1);
break;
case 64:
is = blocks.craftingStorage64k().maybeStack(1);
break;
default:
is = Optional.empty();
break;
}
return is.orElseGet(() -> super.getItemFromTile(obj));
}
@Override
public boolean isAccelerator() {
return false;
}
@Override
public boolean isStorage() {
return true;
}
@Override
public int getStorageBytes() {
if (this.world == null || this.notLoaded() || this.isRemoved()) {
return 0;
}
final AbstractCraftingUnitBlock unit = (AbstractCraftingUnitBlock) this.world.getBlockState(this.pos)
.getBlock();
switch (unit.type) {
default:
case STORAGE_1K:
return 1024;
case STORAGE_4K:
return 4 * 1024;
case STORAGE_16K:
return 16 * 1024;
case STORAGE_64K:
return 64 * 1024;
}
}
}