This commit is contained in:
asdflj committed 2023-02-12 15:54:35 +08:00
1 parent a28bbe6e34
commit f7001d205e
11 files changed
+329 -240

No files matched your search

@@ -0,0 +1,249 @@
package com.glodblock.github.common.item;
import java.text.NumberFormat;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import com.google.common.base.Optional;
public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluidCell {
protected final CellType component;
protected final long totalBytes;
protected final int perType;
protected final double idleDrain;
private final ReadableNumberConverter format = ReadableNumberConverter.INSTANCE;
@SuppressWarnings("Guava")
public FCBaseItemCell(long bytes, int perType, double drain) {
super(Optional.of(bytes / 1024 + "k"));
this.setFeature(EnumSet.of(AEFeature.StorageCells));
this.setMaxStackSize(1);
this.totalBytes = bytes;
this.perType = perType;
this.idleDrain = drain;
this.component = null;
}
@SuppressWarnings("Guava")
public FCBaseItemCell(final CellType whichCell, final long kilobytes) {
super(Optional.of(kilobytes + "k"));
this.setFeature(EnumSet.of(AEFeature.StorageCells));
this.setMaxStackSize(1);
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
switch (this.component) {
case Cell1kPart:
this.idleDrain = 0.5;
this.perType = 8;
break;
case Cell4kPart:
this.idleDrain = 1.0;
this.perType = 8;
break;
case Cell16kPart:
this.idleDrain = 1.5;
this.perType = 8;
break;
case Cell64kPart:
this.idleDrain = 2.0;
this.perType = 8;
break;
case Cell256kPart:
this.idleDrain = 2.5;
this.perType = 8;
break;
case Cell1024kPart:
this.idleDrain = 3.0;
this.perType = 8;
break;
case Cell4096kPart:
this.idleDrain = 3.5;
this.perType = 8;
break;
case Cell16384kPart:
this.idleDrain = 4.0;
this.perType = 8;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
}
@Override
public long getBytes(ItemStack cellItem) {
return this.totalBytes;
}
@Override
public int getBytesPerType(ItemStack cellItem) {
return this.perType;
}
@Override
public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) {
if (Config.blacklistEssentiaGas && ModAndClassUtil.ThE && requestedAddition != null) {
return ModAndClassUtil.essentiaGas.isInstance(requestedAddition.getFluid());
}
return false;
}
@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines,
final boolean displayMoreInfo) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.FLUIDS);
if (inventory instanceof IFluidCellInventoryHandler) {
final IFluidCellInventoryHandler handler = (IFluidCellInventoryHandler) inventory;
final IFluidCellInventory cellInventory = handler.getCellInv();
if (cellInventory != null) {
lines.add(
EnumChatFormatting.WHITE + String.valueOf(cellInventory.getUsedBytes())
+ EnumChatFormatting.GRAY
+ " "
+ GuiText.Of.getLocal()
+ " "
+ EnumChatFormatting.DARK_GREEN
+ NumberFormat.getInstance().format(cellInventory.getTotalBytes())
+ " "
+ EnumChatFormatting.GRAY
+ GuiText.BytesUsed.getLocal());
lines.add(
EnumChatFormatting.WHITE + String.valueOf(cellInventory.getStoredFluidTypes())
+ EnumChatFormatting.GRAY
+ " "
+ GuiText.Of.getLocal()
+ " "
+ EnumChatFormatting.DARK_GREEN
+ cellInventory.getTotalFluidTypes()
+ " "
+ EnumChatFormatting.GRAY
+ GuiText.Types.getLocal());
if (GuiScreen.isCtrlKeyDown()) {
if (cellInventory.getStoredFluidTypes() > 0) {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS));
for (IAEFluidStack fluid : cellInventory.getContents()) {
if (fluid != null) {
lines.add(
String.format(
" %s x%s mB",
fluid.getFluidStack().getLocalizedName(),
format.toWideReadableForm(fluid.getStackSize())));
}
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY));
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE));
}
if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
: GuiText.Excluded).getLocal();
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());
if (GuiScreen.isShiftKeyDown()) {
lines.add(GuiText.Filter.getLocal() + ": ");
for (IAEFluidStack aeFluidStack : handler.getPartitionInv()) {
if (aeFluidStack != null) lines.add(" " + aeFluidStack.getFluidStack().getLocalizedName());
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_SHIFT_FOR_MORE));
}
}
}
}
}
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell(ItemStack i) {
return true;
}
@Override
public double getIdleDrain() {
return this.idleDrain;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 1;
}
@Override
public boolean isEditable(ItemStack is) {
return true;
}
@Override
public IInventory getUpgradesInventory(ItemStack is) {
return new CellUpgrades(is, 0);
}
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
}
@Override
public FuzzyMode getFuzzyMode(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(ItemStack is, FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
public ItemStack stack(int size) {
return new ItemStack(this, size);
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -1,11 +1,7 @@
package com.glodblock.github.common.item;
import java.text.NumberFormat;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -19,8 +15,6 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.exceptions.MissingDefinition;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.storage.IMEInventoryHandler;
@@ -29,94 +23,29 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import com.google.common.base.Optional;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBasicFluidStorageCell extends AEBaseItem
public class ItemBasicFluidStorageCell extends FCBaseItemCell
implements IStorageFluidCell, IRegister<ItemBasicFluidStorageCell> {
private final CellType component;
private final long totalBytes;
private final int perType;
private final double idleDrain;
private final ReadableNumberConverter format = ReadableNumberConverter.INSTANCE;
private static final HashMap<Integer, IIcon> icon = new HashMap<>();
@SuppressWarnings("Guava")
public ItemBasicFluidStorageCell(final CellType whichCell, final long kilobytes) {
super(Optional.of(kilobytes + "k"));
super(whichCell, kilobytes);
setUnlocalizedName(NameConst.ITEM_FLUID_STORAGE + kilobytes);
this.setFeature(EnumSet.of(AEFeature.StorageCells));
this.setMaxStackSize(1);
this.totalBytes = kilobytes * 1024;
this.component = whichCell;
switch (this.component) {
case Cell1kPart:
this.idleDrain = 0.5;
this.perType = 8;
break;
case Cell4kPart:
this.idleDrain = 1.0;
this.perType = 8;
break;
case Cell16kPart:
this.idleDrain = 1.5;
this.perType = 8;
break;
case Cell64kPart:
this.idleDrain = 2.0;
this.perType = 8;
break;
case Cell256kPart:
this.idleDrain = 2.5;
this.perType = 8;
break;
case Cell1024kPart:
this.idleDrain = 3.0;
this.perType = 8;
break;
case Cell4096kPart:
this.idleDrain = 3.5;
this.perType = 8;
break;
case Cell16384kPart:
this.idleDrain = 4.0;
this.perType = 8;
break;
case Cell131072kPart:
this.idleDrain = 4.5;
this.perType = 8;
break;
case Cell554160890921312kPart:
this.idleDrain = 5.0;
this.perType = 8;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
}
public ItemStack getComponent() {
@@ -147,145 +76,6 @@ public class ItemBasicFluidStorageCell extends AEBaseItem
return icon.get(id);
}
@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines,
final boolean displayMoreInfo) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.FLUIDS);
if (inventory instanceof IFluidCellInventoryHandler) {
final IFluidCellInventoryHandler handler = (IFluidCellInventoryHandler) inventory;
final IFluidCellInventory cellInventory = handler.getCellInv();
if (cellInventory != null) {
lines.add(
EnumChatFormatting.WHITE + String.valueOf(cellInventory.getUsedBytes())
+ EnumChatFormatting.GRAY
+ " "
+ GuiText.Of.getLocal()
+ " "
+ EnumChatFormatting.DARK_GREEN
+ NumberFormat.getInstance().format(cellInventory.getTotalBytes())
+ " "
+ EnumChatFormatting.GRAY
+ GuiText.BytesUsed.getLocal());
lines.add(
EnumChatFormatting.WHITE + String.valueOf(cellInventory.getStoredFluidTypes())
+ EnumChatFormatting.GRAY
+ " "
+ GuiText.Of.getLocal()
+ " "
+ EnumChatFormatting.DARK_GREEN
+ cellInventory.getTotalFluidTypes()
+ " "
+ EnumChatFormatting.GRAY
+ GuiText.Types.getLocal());
if (GuiScreen.isCtrlKeyDown()) {
if (cellInventory.getStoredFluidTypes() > 0) {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS));
for (IAEFluidStack fluid : cellInventory.getContents()) {
if (fluid != null) {
lines.add(
String.format(
" %s x%s mB",
fluid.getFluidStack().getLocalizedName(),
format.toWideReadableForm(fluid.getStackSize())));
}
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY));
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE));
}
if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
: GuiText.Excluded).getLocal();
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());
if (GuiScreen.isShiftKeyDown()) {
lines.add(GuiText.Filter.getLocal() + ": ");
for (IAEFluidStack aeFluidStack : handler.getPartitionInv()) {
if (aeFluidStack != null) lines.add(" " + aeFluidStack.getFluidStack().getLocalizedName());
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_SHIFT_FOR_MORE));
}
}
}
}
}
@Override
public long getBytes(final ItemStack cellItem) {
return this.totalBytes;
}
@Override
public int getBytesPerType(final ItemStack cellItem) {
return this.perType;
}
@Override
public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) {
if (Config.blacklistEssentiaGas && ModAndClassUtil.ThE && requestedAddition != null) {
return ModAndClassUtil.essentiaGas.isInstance(requestedAddition.getFluid());
}
return false;
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 1;
}
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell(final ItemStack i) {
return true;
}
@Override
public double getIdleDrain() {
return this.idleDrain;
}
@Override
public boolean isEditable(final ItemStack is) {
return true;
}
@Override
public IInventory getUpgradesInventory(final ItemStack is) {
return new CellUpgrades(is, 0);
}
@Override
public IInventory 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 void setFuzzyMode(final ItemStack is, final FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}
@Override
public ItemStack onItemRightClick(final ItemStack stack, final World world, final EntityPlayer player) {
this.disassembleDrive(stack, world, player);
@@ -369,12 +159,4 @@ public class ItemBasicFluidStorageCell extends AEBaseItem
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
public ItemStack stack(int size) {
return new ItemStack(this, size);
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -0,0 +1,55 @@
package com.glodblock.github.common.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.loader.IRegister;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemFluidExtremeStorageCell extends FCBaseItemCell
implements IStorageFluidCell, IRegister<ItemFluidExtremeStorageCell> {
private final String name;
public ItemFluidExtremeStorageCell(String name, long bytes, int perType, double drain) {
super(bytes, perType, drain);
setUnlocalizedName(name);
this.name = name;
setTextureName(FluidCraft.resource(name).toString());
}
@Override
public ItemStack onItemRightClick(final ItemStack stack, final World world, final EntityPlayer player) {
return stack;
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
float hitX, float hitY, float hitZ) {
return false;
}
@Override
public ItemStack getContainerItem(final ItemStack itemStack) {
return null;
}
@Override
public boolean hasContainerItem(final ItemStack stack) {
return false;
}
@Override
public ItemFluidExtremeStorageCell register() {
if (!Config.fluidCells) return null;
GameRegistry.registerItem(this, this.name, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
}
@@ -17,9 +17,7 @@ public enum CellType {
Cell256kPart(4, AEFeature.StorageCells),
Cell1024kPart(5, AEFeature.StorageCells),
Cell4096kPart(6, AEFeature.StorageCells),
Cell16384kPart(7, AEFeature.StorageCells),
Cell131072kPart(8, AEFeature.StorageCells),
Cell554160890921312kPart(9, AEFeature.StorageCells);
Cell16384kPart(7, AEFeature.StorageCells);
private final EnumSet<AEFeature> features;
private int damageValue;
@@ -76,10 +74,6 @@ public enum CellType {
return EnumChatFormatting.RED;
case Cell16384kPart:
return EnumChatFormatting.DARK_PURPLE;
case Cell131072kPart:
return EnumChatFormatting.DARK_GRAY;
case Cell554160890921312kPart:
return EnumChatFormatting.DARK_RED;
}
return EnumChatFormatting.WHITE;
}
@@ -1,9 +1,12 @@
package com.glodblock.github.loader;
import static com.glodblock.github.common.storage.FluidCellInventory.singleByteAmount;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.block.*;
import com.glodblock.github.common.item.*;
import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.util.NameConst;
public class ItemAndBlockHolder {
@@ -52,12 +55,16 @@ public class ItemAndBlockHolder {
.register();
public static ItemBasicFluidStorageCell CELL16384K = new ItemBasicFluidStorageCell(CellType.Cell16384kPart, 16384)
.register();
public static ItemBasicFluidStorageCell CELL131072K = new ItemBasicFluidStorageCell(
CellType.Cell131072kPart,
131072).register();
public static ItemBasicFluidStorageCell CELL554160890921312K = new ItemBasicFluidStorageCell(
CellType.Cell554160890921312kPart,
554160890921312L).register();
public static ItemFluidExtremeStorageCell QUANTUM_CELL = new ItemFluidExtremeStorageCell(
NameConst.ITEM_QUANTUM_FLUID_STORAGE,
Integer.MAX_VALUE / 16,
8,
4.5).register();
public static ItemFluidExtremeStorageCell SINGULARITY_CELL = new ItemFluidExtremeStorageCell(
NameConst.ITEM_SINGULARITY_FLUID_STORAGE,
Long.MAX_VALUE / (singleByteAmount * 2),
8,
5).register();
public static ItemCreativeFluidStorageCell CREATIVE_CELL = new ItemCreativeFluidStorageCell().register();
public static ItemBasicFluidStoragePart CELL_PART = new ItemBasicFluidStoragePart().register();
@@ -401,7 +401,7 @@ public class RecipeLoader implements Runnable {
CELL256K, CELL1024K, CELL4096K, CELL16384K };
GameRegistry.addRecipe(
new ShapedOreRecipe(
CELL131072K.stack(),
QUANTUM_CELL.stack(),
"RCR",
"CEC",
"RCR",
@@ -413,12 +413,12 @@ public class RecipeLoader implements Runnable {
AE2_QUANTUM_RING));
GameRegistry.addRecipe(
new ShapedOreRecipe(
CELL554160890921312K.stack(),
SINGULARITY_CELL.stack(),
"CCC",
"CMC",
"CCC",
'C',
CELL131072K,
QUANTUM_CELL,
'M',
AE2_MATTER_CONDENSER));
for (ItemBasicFluidStorageCell cell : cells) {
@@ -35,6 +35,8 @@ public class NameConst {
public static final String ITEM_PART_FLUID_LEVEL_EMITTER = "part_fluid_level_emitter";
public static final String ITEM_FLUID_PACKET = "fluid_packet";
public static final String ITEM_FLUID_STORAGE = "fluid_storage";
public static final String ITEM_QUANTUM_FLUID_STORAGE = ITEM_FLUID_STORAGE + ".quantum";
public static final String ITEM_SINGULARITY_FLUID_STORAGE = ITEM_FLUID_STORAGE + ".singularity";
public static final String ITEM_CREATIVE_FLUID_STORAGE = "creative_" + ITEM_FLUID_STORAGE;
public static final String ITEM_FLUID_PORTABLE_CELL = "portable_fluid_cell";
public static final String ITEM_WIRELESS_FLUID_TERMINAL = "wireless_fluid_terminal";