diff --git a/src/api/java/appeng/api/config/Upgrades.java b/src/api/java/appeng/api/config/Upgrades.java index 4b2d5dd28..8f4eb8b13 100644 --- a/src/api/java/appeng/api/config/Upgrades.java +++ b/src/api/java/appeng/api/config/Upgrades.java @@ -23,12 +23,17 @@ package appeng.api.config; -import java.util.HashMap; -import java.util.Map; +import java.util.*; -import net.minecraft.item.ItemStack; +import javax.annotation.Nullable; -import appeng.api.definitions.IItemDefinition; +import com.google.common.base.Preconditions; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.IItemProvider; +import net.minecraft.util.text.ITextComponent; public enum Upgrades { /** @@ -42,7 +47,8 @@ public enum Upgrades { FUZZY(1), SPEED(1), INVERTER(1); private final int tier; - private final Map supportedMax = new HashMap<>(); + private final List supported = new ArrayList<>(); + private List supportedTooltipLines; Upgrades(final int tier) { this.tier = tier; @@ -52,8 +58,12 @@ public enum Upgrades { * @return list of Items/Blocks that support this upgrade, and how many it * supports. */ - public Map getSupported() { - return this.supportedMax; + public List getSupported() { + return this.supported; + } + + public void registerItem(final IItemProvider item, final int maxSupported) { + this.registerItem(item, maxSupported, null); } /** @@ -61,24 +71,93 @@ public enum Upgrades { * * @param item machine in which this upgrade can be installed * @param maxSupported amount how many upgrades can be installed + * @param tooltipGroup If more than one item of the same group are supported, + * the tooltip will show this group name instead. If the + * items have different maxSupported values, the highest + * will be shown. */ - public void registerItem(final IItemDefinition item, final int maxSupported) { - item.maybeStack(1).ifPresent(is -> this.registerItem(is, maxSupported)); + public void registerItem(final IItemProvider item, final int maxSupported, @Nullable ITextComponent tooltipGroup) { + Preconditions.checkNotNull(item); + this.supported.add(new Supported(item.asItem(), maxSupported, tooltipGroup)); + supportedTooltipLines = null; // Reset tooltip } - /** - * Registers a specific amount of this upgrade into a specific machine - * - * @param stack machine in which this upgrade can be installed - * @param maxSupported amount how many upgrades can be installed - */ - public void registerItem(final ItemStack stack, final int maxSupported) { - if (stack != null) { - this.supportedMax.put(stack, maxSupported); + public List getTooltipLines() { + if (supportedTooltipLines == null) { + supported.sort(Comparator.comparingInt(o -> o.maxCount)); + supportedTooltipLines = new ArrayList<>(supported.size()); + + // Use a separate set because the final text will include numbers + Set namesAdded = new HashSet<>(); + + for (int i = 0; i < supported.size(); i++) { + Supported supported = this.supported.get(i); + ITextComponent name = supported.item.getName(); + + // If the group was already added by a previous item, skip this + if (supported.tooltipGroup != null && namesAdded.contains(supported.tooltipGroup)) { + continue; + } + + // If any of the following items would be of the same group, use the group name + // instead + if (supported.tooltipGroup != null) { + for (int j = i + 1; j < this.supported.size(); j++) { + ITextComponent otherGroup = this.supported.get(j).tooltipGroup; + if (supported.tooltipGroup.equals(otherGroup)) { + name = supported.tooltipGroup; + break; + } + } + } + + if (namesAdded.add(name)) { + // append the supported count only if its > 1 + if (supported.maxCount > 1) { + name = name.deepCopy().appendText(" (" + supported.maxCount + ")"); + } + supportedTooltipLines.add(name); + } + } } + + return supportedTooltipLines; } public int getTier() { return this.tier; } + + public static class Supported { + private final Item item; + private final Block block; + private final int maxCount; + @Nullable + private final ITextComponent tooltipGroup; + + public Supported(Item item, int maxCount, @Nullable ITextComponent tooltipGroup) { + this.item = item; + if (item.getItem() instanceof BlockItem) { + this.block = ((BlockItem) item.getItem()).getBlock(); + } else { + this.block = null; + } + this.maxCount = maxCount; + this.tooltipGroup = tooltipGroup; + } + + public int getMaxCount() { + return maxCount; + } + + public boolean isSupported(Block block) { + return block != null && this.block == block; + } + + public boolean isSupported(Item item) { + return item != null && this.item == item; + } + + } + } diff --git a/src/api/java/appeng/api/definitions/IItemDefinition.java b/src/api/java/appeng/api/definitions/IItemDefinition.java index c66503599..058109c8a 100644 --- a/src/api/java/appeng/api/definitions/IItemDefinition.java +++ b/src/api/java/appeng/api/definitions/IItemDefinition.java @@ -30,10 +30,11 @@ import javax.annotation.Nonnull; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.IItemProvider; import appeng.api.features.AEFeature; -public interface IItemDefinition extends IComparableDefinition { +public interface IItemDefinition extends IComparableDefinition, IItemProvider { /** * @return the unique name of the definition which will be used to register the * underlying structure. Will never be null @@ -63,4 +64,10 @@ public interface IItemDefinition extends IComparableDefinition { * @return an immutable set of the features of this item */ Set features(); + + @Override + default Item asItem() { + return item(); + } + } diff --git a/src/api/java/appeng/api/implementations/items/IItemGroup.java b/src/api/java/appeng/api/implementations/items/IItemGroup.java deleted file mode 100644 index c9263a905..000000000 --- a/src/api/java/appeng/api/implementations/items/IItemGroup.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.implementations.items; - -import java.util.Set; - -import net.minecraft.item.ItemStack; - -/** - * Lets you specify the name of the group of items this falls under. - */ -public interface IItemGroup { - - /** - * returning null, is the same as not implementing the interface at all. - * - * @param is item - * - * @return an unlocalized string to use for the items group name. - */ - String getUnlocalizedGroupName(Set otherItems, ItemStack is); -} diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index d29bcae6e..34e8c66bd 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -31,6 +31,7 @@ import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.particles.ParticleType; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; import net.minecraft.world.biome.Biome; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.GenerationStage; @@ -91,6 +92,7 @@ import appeng.core.features.registries.PartModels; import appeng.core.features.registries.cell.BasicCellHandler; import appeng.core.features.registries.cell.BasicItemCellGuiHandler; import appeng.core.features.registries.cell.CreativeCellHandler; +import appeng.core.localization.GuiText; import appeng.core.stats.AdvancementTriggers; import appeng.core.stats.AeStats; import appeng.fluids.client.gui.*; @@ -379,12 +381,19 @@ final class Registration { final IBlocks blocks = definitions.blocks(); final IItems items = definitions.items(); + // Block and part interface have different translation keys, but support the + // same upgrades + ITextComponent interfaceGroup = parts.iface().asItem().getName(); + ITextComponent itemIoBusGroup = GuiText.IOBuses.textComponent(); + ITextComponent fluidIoBusGroup = GuiText.IOBusesFluids.textComponent(); + ITextComponent storageCellGroup = GuiText.IOBusesFluids.textComponent(); + // default settings.. ((P2PTunnelRegistry) registries.p2pTunnel()).configure(); // Interface - Upgrades.CRAFTING.registerItem(parts.iface(), 1); - Upgrades.CRAFTING.registerItem(blocks.iface(), 1); + Upgrades.CRAFTING.registerItem(parts.iface(), 1, interfaceGroup); + Upgrades.CRAFTING.registerItem(blocks.iface(), 1, interfaceGroup); // IO Port! Upgrades.SPEED.registerItem(blocks.iOPort(), 3); @@ -395,43 +404,43 @@ final class Registration { Upgrades.CRAFTING.registerItem(parts.levelEmitter(), 1); // Import Bus - Upgrades.FUZZY.registerItem(parts.importBus(), 1); - Upgrades.REDSTONE.registerItem(parts.importBus(), 1); - Upgrades.CAPACITY.registerItem(parts.importBus(), 2); - Upgrades.SPEED.registerItem(parts.importBus(), 4); + Upgrades.FUZZY.registerItem(parts.importBus(), 1, itemIoBusGroup); + Upgrades.REDSTONE.registerItem(parts.importBus(), 1, itemIoBusGroup); + Upgrades.CAPACITY.registerItem(parts.importBus(), 2, itemIoBusGroup); + Upgrades.SPEED.registerItem(parts.importBus(), 4, itemIoBusGroup); // Fluid Import Bus - Upgrades.CAPACITY.registerItem(parts.fluidImportBus(), 2); - Upgrades.REDSTONE.registerItem(parts.fluidImportBus(), 1); - Upgrades.SPEED.registerItem(parts.fluidImportBus(), 4); + Upgrades.CAPACITY.registerItem(parts.fluidImportBus(), 2, fluidIoBusGroup); + Upgrades.REDSTONE.registerItem(parts.fluidImportBus(), 1, fluidIoBusGroup); + Upgrades.SPEED.registerItem(parts.fluidImportBus(), 4, fluidIoBusGroup); // Export Bus - Upgrades.FUZZY.registerItem(parts.exportBus(), 1); - Upgrades.REDSTONE.registerItem(parts.exportBus(), 1); - Upgrades.CAPACITY.registerItem(parts.exportBus(), 2); - Upgrades.SPEED.registerItem(parts.exportBus(), 4); - Upgrades.CRAFTING.registerItem(parts.exportBus(), 1); + Upgrades.FUZZY.registerItem(parts.exportBus(), 1, itemIoBusGroup); + Upgrades.REDSTONE.registerItem(parts.exportBus(), 1, itemIoBusGroup); + Upgrades.CAPACITY.registerItem(parts.exportBus(), 2, itemIoBusGroup); + Upgrades.SPEED.registerItem(parts.exportBus(), 4, itemIoBusGroup); + Upgrades.CRAFTING.registerItem(parts.exportBus(), 1, itemIoBusGroup); // Fluid Export Bus - Upgrades.CAPACITY.registerItem(parts.fluidExportBus(), 2); - Upgrades.REDSTONE.registerItem(parts.fluidExportBus(), 1); - Upgrades.SPEED.registerItem(parts.fluidExportBus(), 4); + Upgrades.CAPACITY.registerItem(parts.fluidExportBus(), 2, fluidIoBusGroup); + Upgrades.REDSTONE.registerItem(parts.fluidExportBus(), 1, fluidIoBusGroup); + Upgrades.SPEED.registerItem(parts.fluidExportBus(), 4, fluidIoBusGroup); // Storage Cells - Upgrades.FUZZY.registerItem(items.cell1k(), 1); - Upgrades.INVERTER.registerItem(items.cell1k(), 1); + Upgrades.FUZZY.registerItem(items.cell1k(), 1, storageCellGroup); + Upgrades.INVERTER.registerItem(items.cell1k(), 1, storageCellGroup); - Upgrades.FUZZY.registerItem(items.cell4k(), 1); - Upgrades.INVERTER.registerItem(items.cell4k(), 1); + Upgrades.FUZZY.registerItem(items.cell4k(), 1, storageCellGroup); + Upgrades.INVERTER.registerItem(items.cell4k(), 1, storageCellGroup); - Upgrades.FUZZY.registerItem(items.cell16k(), 1); - Upgrades.INVERTER.registerItem(items.cell16k(), 1); + Upgrades.FUZZY.registerItem(items.cell16k(), 1, storageCellGroup); + Upgrades.INVERTER.registerItem(items.cell16k(), 1, storageCellGroup); - Upgrades.FUZZY.registerItem(items.cell64k(), 1); - Upgrades.INVERTER.registerItem(items.cell64k(), 1); + Upgrades.FUZZY.registerItem(items.cell64k(), 1, storageCellGroup); + Upgrades.INVERTER.registerItem(items.cell64k(), 1, storageCellGroup); - Upgrades.FUZZY.registerItem(items.portableCell(), 1); - Upgrades.INVERTER.registerItem(items.portableCell(), 1); + Upgrades.FUZZY.registerItem(items.portableCell(), 1, storageCellGroup); + Upgrades.INVERTER.registerItem(items.portableCell(), 1, storageCellGroup); Upgrades.FUZZY.registerItem(items.viewCell(), 1); Upgrades.INVERTER.registerItem(items.viewCell(), 1); diff --git a/src/main/java/appeng/core/api/definitions/ApiParts.java b/src/main/java/appeng/core/api/definitions/ApiParts.java index d750a8962..edc579962 100644 --- a/src/main/java/appeng/core/api/definitions/ApiParts.java +++ b/src/main/java/appeng/core/api/definitions/ApiParts.java @@ -46,7 +46,6 @@ import appeng.fluids.parts.FluidTerminalPart; import appeng.items.parts.ColoredPartItem; import appeng.items.parts.PartItem; import appeng.items.parts.PartItemRendering; -import appeng.items.parts.PartType; import appeng.parts.automation.AnnihilationPlanePart; import appeng.parts.automation.ExportBusPart; import appeng.parts.automation.FormationPlanePart; @@ -129,73 +128,50 @@ public final class ApiParts implements IParts { public ApiParts(FeatureFactory registry, PartModels partModels) { registerPartModels(partModels); - this.cableSmart = constructColoredDefinition(registry, "smart_cable", PartType.CABLE_SMART, - SmartCablePart::new); - this.cableCovered = constructColoredDefinition(registry, "covered_cable", PartType.CABLE_COVERED, - CoveredCablePart::new); - this.cableGlass = constructColoredDefinition(registry, "glass_cable", PartType.CABLE_GLASS, - GlassCablePart::new); + this.cableSmart = constructColoredDefinition(registry, "smart_cable", SmartCablePart::new); + this.cableCovered = constructColoredDefinition(registry, "covered_cable", CoveredCablePart::new); + this.cableGlass = constructColoredDefinition(registry, "glass_cable", GlassCablePart::new); this.cableDenseCovered = constructColoredDefinition(registry, "covered_dense_cable", - PartType.CABLE_DENSE_COVERED, CoveredDenseCablePart::new); - this.cableDenseSmart = constructColoredDefinition(registry, "smart_dense_cable", PartType.CABLE_DENSE_SMART, - SmartDenseCablePart::new); - this.quartzFiber = createPart(registry, "quartz_fiber", PartType.QUARTZ_FIBER, QuartzFiberPart::new); - this.toggleBus = createPart(registry, "toggle_bus", PartType.TOGGLE_BUS, ToggleBusPart::new); - this.invertedToggleBus = createPart(registry, "inverted_toggle_bus", PartType.INVERTED_TOGGLE_BUS, - InvertedToggleBusPart::new); - this.cableAnchor = createPart(registry, "cable_anchor", PartType.CABLE_ANCHOR, CableAnchorPart::new); - this.monitor = createPart(registry, "monitor", PartType.MONITOR, PanelPart::new); - this.semiDarkMonitor = createPart(registry, "semi_dark_monitor", PartType.SEMI_DARK_MONITOR, - SemiDarkPanelPart::new); - this.darkMonitor = createPart(registry, "dark_monitor", PartType.DARK_MONITOR, DarkPanelPart::new); - this.storageBus = createPart(registry, "storage_bus", PartType.STORAGE_BUS, StorageBusPart::new); - this.fluidStorageBus = createPart(registry, "fluid_storage_bus", PartType.FLUID_STORAGE_BUS, - FluidStorageBusPart::new); - this.importBus = createPart(registry, "import_bus", PartType.IMPORT_BUS, ImportBusPart::new); - this.fluidImportBus = createPart(registry, "fluid_import_bus", PartType.FLUID_IMPORT_BUS, - FluidImportBusPart::new); - this.exportBus = createPart(registry, "export_bus", PartType.EXPORT_BUS, ExportBusPart::new); - this.fluidExportBus = createPart(registry, "fluid_export_bus", PartType.FLUID_EXPORT_BUS, - FluidExportBusPart::new); - this.levelEmitter = createPart(registry, "level_emitter", PartType.LEVEL_EMITTER, LevelEmitterPart::new); - this.fluidLevelEmitter = createPart(registry, "fluid_level_emitter", PartType.FLUID_LEVEL_EMITTER, - FluidLevelEmitterPart::new); - this.annihilationPlane = createPart(registry, "annihilation_plane", PartType.ANNIHILATION_PLANE, - AnnihilationPlanePart::new); + CoveredDenseCablePart::new); + this.cableDenseSmart = constructColoredDefinition(registry, "smart_dense_cable", SmartDenseCablePart::new); + this.quartzFiber = createPart(registry, "quartz_fiber", QuartzFiberPart::new); + this.toggleBus = createPart(registry, "toggle_bus", ToggleBusPart::new); + this.invertedToggleBus = createPart(registry, "inverted_toggle_bus", InvertedToggleBusPart::new); + this.cableAnchor = createPart(registry, "cable_anchor", CableAnchorPart::new); + this.monitor = createPart(registry, "monitor", PanelPart::new); + this.semiDarkMonitor = createPart(registry, "semi_dark_monitor", SemiDarkPanelPart::new); + this.darkMonitor = createPart(registry, "dark_monitor", DarkPanelPart::new); + this.storageBus = createPart(registry, "storage_bus", StorageBusPart::new); + this.fluidStorageBus = createPart(registry, "fluid_storage_bus", FluidStorageBusPart::new); + this.importBus = createPart(registry, "import_bus", ImportBusPart::new); + this.fluidImportBus = createPart(registry, "fluid_import_bus", FluidImportBusPart::new); + this.exportBus = createPart(registry, "export_bus", ExportBusPart::new); + this.fluidExportBus = createPart(registry, "fluid_export_bus", FluidExportBusPart::new); + this.levelEmitter = createPart(registry, "level_emitter", LevelEmitterPart::new); + this.fluidLevelEmitter = createPart(registry, "fluid_level_emitter", FluidLevelEmitterPart::new); + this.annihilationPlane = createPart(registry, "annihilation_plane", AnnihilationPlanePart::new); this.identityAnnihilationPlane = createPart(registry, "identity_annihilation_plane", - PartType.IDENTITY_ANNIHILATION_PLANE, IdentityAnnihilationPlanePart::new); - this.fluidAnnihilationPlane = createPart(registry, "fluid_annihilation_plane", - PartType.FLUID_ANNIHILATION_PLANE, FluidAnnihilationPlanePart::new); - this.formationPlane = createPart(registry, "formation_plane", PartType.FORMATION_PLANE, - FormationPlanePart::new); - this.fluidFormationPlane = createPart(registry, "fluid_formation_plane", PartType.FLUID_FORMATION_PLANE, - FluidFormationPlanePart::new); - this.patternTerminal = createPart(registry, "pattern_terminal", PartType.PATTERN_TERMINAL, - PatternTerminalPart::new); - this.craftingTerminal = createPart(registry, "crafting_terminal", PartType.CRAFTING_TERMINAL, - CraftingTerminalPart::new); - this.terminal = createPart(registry, "terminal", PartType.TERMINAL, TerminalPart::new); - this.storageMonitor = createPart(registry, "storage_monitor", PartType.STORAGE_MONITOR, - StorageMonitorPart::new); - this.conversionMonitor = createPart(registry, "conversion_monitor", PartType.CONVERSION_MONITOR, - ConversionMonitorPart::new); - this.iface = createPart(registry, "cable_interface", PartType.INTERFACE, InterfacePart::new); - this.fluidIface = createPart(registry, "cable_fluid_interface", PartType.FLUID_INTERFACE, - FluidInterfacePart::new); - this.p2PTunnelME = createPart(registry, "me_p2p_tunnel", PartType.P2P_TUNNEL_ME, MEP2PTunnelPart::new); - this.p2PTunnelRedstone = createPart(registry, "redstone_p2p_tunnel", PartType.P2P_TUNNEL_REDSTONE, - RedstoneP2PTunnelPart::new); - this.p2PTunnelItems = createPart(registry, "item_p2p_tunnel", PartType.P2P_TUNNEL_ITEM, ItemP2PTunnelPart::new); - this.p2PTunnelFluids = createPart(registry, "fluid_p2p_tunnel", PartType.P2P_TUNNEL_FLUID, - FluidP2PTunnelPart::new); + IdentityAnnihilationPlanePart::new); + this.fluidAnnihilationPlane = createPart(registry, "fluid_annihilation_plane", FluidAnnihilationPlanePart::new); + this.formationPlane = createPart(registry, "formation_plane", FormationPlanePart::new); + this.fluidFormationPlane = createPart(registry, "fluid_formation_plane", FluidFormationPlanePart::new); + this.patternTerminal = createPart(registry, "pattern_terminal", PatternTerminalPart::new); + this.craftingTerminal = createPart(registry, "crafting_terminal", CraftingTerminalPart::new); + this.terminal = createPart(registry, "terminal", TerminalPart::new); + this.storageMonitor = createPart(registry, "storage_monitor", StorageMonitorPart::new); + this.conversionMonitor = createPart(registry, "conversion_monitor", ConversionMonitorPart::new); + this.iface = createPart(registry, "cable_interface", InterfacePart::new); + this.fluidIface = createPart(registry, "cable_fluid_interface", FluidInterfacePart::new); + this.p2PTunnelME = createPart(registry, "me_p2p_tunnel", MEP2PTunnelPart::new); + this.p2PTunnelRedstone = createPart(registry, "redstone_p2p_tunnel", RedstoneP2PTunnelPart::new); + this.p2PTunnelItems = createPart(registry, "item_p2p_tunnel", ItemP2PTunnelPart::new); + this.p2PTunnelFluids = createPart(registry, "fluid_p2p_tunnel", FluidP2PTunnelPart::new); this.p2PTunnelEU = null; // FIXME createPart( "ic2_p2p_tunnel", PartType.P2P_TUNNEL_IC2, // PartP2PIC2Power::new); - this.p2PTunnelFE = createPart(registry, "fe_p2p_tunnel", PartType.P2P_TUNNEL_FE, FEP2PTunnelPart::new); - this.p2PTunnelLight = createPart(registry, "light_p2p_tunnel", PartType.P2P_TUNNEL_LIGHT, - LightP2PTunnelPart::new); - this.interfaceTerminal = createPart(registry, "interface_terminal", PartType.INTERFACE_TERMINAL, - InterfaceTerminalPart::new); - this.fluidTerminal = createPart(registry, "fluid_terminal", PartType.FLUID_TERMINAL, FluidTerminalPart::new); + this.p2PTunnelFE = createPart(registry, "fe_p2p_tunnel", FEP2PTunnelPart::new); + this.p2PTunnelLight = createPart(registry, "light_p2p_tunnel", LightP2PTunnelPart::new); + this.interfaceTerminal = createPart(registry, "interface_terminal", InterfaceTerminalPart::new); + this.fluidTerminal = createPart(registry, "fluid_terminal", FluidTerminalPart::new); } private void registerPartModels(PartModels partModels) { @@ -212,20 +188,20 @@ public final class ApiParts implements IParts { } } - private IItemDefinition createPart(FeatureFactory registry, String id, PartType type, + private IItemDefinition createPart(FeatureFactory registry, String id, Function factory) { - return registry.item(id, props -> new PartItem<>(props, type, factory)).itemGroup(CreativeTab.INSTANCE) + return registry.item(id, props -> new PartItem<>(props, factory)).itemGroup(CreativeTab.INSTANCE) .rendering(new PartItemRendering()).build(); } private AEColoredItemDefinition constructColoredDefinition(FeatureFactory registry, - String idSuffix, PartType type, Function factory) { + String idSuffix, Function factory) { final ColoredItemDefinition definition = new ColoredItemDefinition(); for (final AEColor color : AEColor.values()) { String id = color.registryPrefix + '_' + idSuffix; - IItemDefinition itemDef = registry.item(id, props -> new ColoredPartItem<>(props, type, factory, color)) + IItemDefinition itemDef = registry.item(id, props -> new ColoredPartItem<>(props, factory, color)) .itemGroup(CreativeTab.INSTANCE).rendering(new PartItemRendering(color)).build(); definition.add(color, new ItemStackSrc(itemDef.item(), ActivityState.Enabled)); diff --git a/src/main/java/appeng/core/api/definitions/PartType.java b/src/main/java/appeng/core/api/definitions/PartType.java new file mode 100644 index 000000000..abd152f7f --- /dev/null +++ b/src/main/java/appeng/core/api/definitions/PartType.java @@ -0,0 +1,159 @@ +package appeng.core.api.definitions; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.util.ResourceLocation; + +import appeng.api.features.AEFeature; +import appeng.api.parts.IPart; +import appeng.fluids.parts.*; +import appeng.items.parts.PartModelsHelper; +import appeng.parts.automation.*; +import appeng.parts.misc.*; +import appeng.parts.networking.*; +import appeng.parts.p2p.*; +import appeng.parts.reporting.*; + +enum PartType { + INVALID_TYPE(EnumSet.of(AEFeature.CORE), null), + + CABLE_GLASS(EnumSet.of(AEFeature.GLASS_CABLES), GlassCablePart.class) { + @Override + public boolean isCable() { + return true; + } + }, + + CABLE_COVERED(EnumSet.of(AEFeature.COVERED_CABLES), CoveredCablePart.class) { + @Override + public boolean isCable() { + return true; + } + }, + + CABLE_SMART(EnumSet.of(AEFeature.CHANNELS, AEFeature.SMART_CABLES), SmartCablePart.class) { + @Override + public boolean isCable() { + return true; + } + }, + + CABLE_DENSE_SMART(EnumSet.of(AEFeature.CHANNELS, AEFeature.DENSE_CABLES), SmartDenseCablePart.class) { + @Override + public boolean isCable() { + return true; + } + }, + + CABLE_DENSE_COVERED(EnumSet.of(AEFeature.CHANNELS, AEFeature.DENSE_CABLES), CoveredDenseCablePart.class) { + @Override + public boolean isCable() { + return true; + } + }, + + TOGGLE_BUS(EnumSet.of(AEFeature.TOGGLE_BUS), ToggleBusPart.class), + + INVERTED_TOGGLE_BUS(EnumSet.of(AEFeature.TOGGLE_BUS), InvertedToggleBusPart.class), + + CABLE_ANCHOR(EnumSet.of(AEFeature.CABLE_ANCHOR), CableAnchorPart.class), + + QUARTZ_FIBER(EnumSet.of(AEFeature.QUARTZ_FIBER), QuartzFiberPart.class), + + MONITOR(EnumSet.of(AEFeature.PANELS), PanelPart.class), + + SEMI_DARK_MONITOR(EnumSet.of(AEFeature.PANELS), SemiDarkPanelPart.class), + + DARK_MONITOR(EnumSet.of(AEFeature.PANELS), DarkPanelPart.class), + + STORAGE_BUS(EnumSet.of(AEFeature.STORAGE_BUS), StorageBusPart.class), + FLUID_STORAGE_BUS(EnumSet.of(AEFeature.FLUID_STORAGE_BUS), FluidStorageBusPart.class), + + IMPORT_BUS(EnumSet.of(AEFeature.IMPORT_BUS), ImportBusPart.class), + + FLUID_IMPORT_BUS(EnumSet.of(AEFeature.FLUID_IMPORT_BUS), FluidImportBusPart.class), + + EXPORT_BUS(EnumSet.of(AEFeature.EXPORT_BUS), ExportBusPart.class), + + FLUID_EXPORT_BUS(EnumSet.of(AEFeature.FLUID_EXPORT_BUS), FluidExportBusPart.class), + + LEVEL_EMITTER(EnumSet.of(AEFeature.LEVEL_EMITTER), LevelEmitterPart.class), + FLUID_LEVEL_EMITTER(EnumSet.of(AEFeature.FLUID_LEVEL_EMITTER), FluidLevelEmitterPart.class), + + ANNIHILATION_PLANE(EnumSet.of(AEFeature.ANNIHILATION_PLANE), AnnihilationPlanePart.class), + + IDENTITY_ANNIHILATION_PLANE(EnumSet.of(AEFeature.ANNIHILATION_PLANE, AEFeature.IDENTITY_ANNIHILATION_PLANE), + IdentityAnnihilationPlanePart.class), + + FLUID_ANNIHILATION_PLANE(EnumSet.of(AEFeature.FLUID_ANNIHILATION_PLANE), FluidAnnihilationPlanePart.class), + + FORMATION_PLANE(EnumSet.of(AEFeature.FORMATION_PLANE), FormationPlanePart.class), + + FLUID_FORMATION_PLANE(EnumSet.of(AEFeature.FLUID_FORMATION_PLANE), FluidFormationPlanePart.class), + + PATTERN_TERMINAL(EnumSet.of(AEFeature.PATTERNS), PatternTerminalPart.class), + + CRAFTING_TERMINAL(EnumSet.of(AEFeature.CRAFTING_TERMINAL), CraftingTerminalPart.class), + + TERMINAL(EnumSet.of(AEFeature.TERMINAL), TerminalPart.class), + + STORAGE_MONITOR(EnumSet.of(AEFeature.STORAGE_MONITOR), StorageMonitorPart.class), + + CONVERSION_MONITOR(EnumSet.of(AEFeature.PART_CONVERSION_MONITOR), ConversionMonitorPart.class), + + INTERFACE(EnumSet.of(AEFeature.INTERFACE), InterfacePart.class), + FLUID_INTERFACE(EnumSet.of(AEFeature.FLUID_INTERFACE), FluidInterfacePart.class), + + P2P_TUNNEL_ME(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ME), MEP2PTunnelPart.class), + + P2P_TUNNEL_REDSTONE(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_REDSTONE), RedstoneP2PTunnelPart.class), + + P2P_TUNNEL_ITEM(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ITEMS), ItemP2PTunnelPart.class), + + P2P_TUNNEL_FLUID(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FLUIDS), FluidP2PTunnelPart.class), + +//FIXME P2P_TUNNEL_IC2( 465, "p2p_tunnel_ic2", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_EU ), EnumSet +//FIXME .of( IntegrationType.IC2 ), PartP2PIC2Power.class ), + + P2P_TUNNEL_LIGHT(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_LIGHT), LightP2PTunnelPart.class), + + P2P_TUNNEL_FE(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FE), FEP2PTunnelPart.class), + + // P2PTunnelOpenComputers( 468, EnumSet.of( AEFeature.P2PTunnel, + // AEFeature.P2PTunnelOpenComputers ), EnumSet.of( + // IntegrationType.OpenComputers ), PartP2POpenComputers.class, GuiText.OCTunnel + // ), + + INTERFACE_TERMINAL(EnumSet.of(AEFeature.INTERFACE_TERMINAL), InterfaceTerminalPart.class), + + FLUID_TERMINAL(EnumSet.of(AEFeature.FLUID_TERMINAL), FluidTerminalPart.class); + + private final Set features; + private final Set models; + + PartType(final Set features, final Class c) { + this.features = Collections.unmodifiableSet(features); + + if (c != null) { + this.models = new HashSet<>(PartModelsHelper.createModels(c)); + } else { + this.models = Collections.emptySet(); + } + } + + public boolean isCable() { + return false; + } + + public Set getFeature() { + return this.features; + } + + public Set getModels() { + return this.models; + } + +} diff --git a/src/main/java/appeng/items/materials/MaterialItem.java b/src/main/java/appeng/items/materials/MaterialItem.java index 8bd4add1f..d45d0f146 100644 --- a/src/main/java/appeng/items/materials/MaterialItem.java +++ b/src/main/java/appeng/items/materials/MaterialItem.java @@ -18,12 +18,7 @@ package appeng.items.materials; -import java.util.ArrayList; -import java.util.Comparator; import java.util.List; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; @@ -37,7 +32,6 @@ import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -45,7 +39,6 @@ import net.minecraftforge.items.IItemHandler; import appeng.api.config.Upgrades; import appeng.api.implementations.IUpgradeableHost; -import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IStorageComponent; import appeng.api.implementations.items.IUpgradeModule; import appeng.api.implementations.tiles.ISegmentedInventory; @@ -86,34 +79,7 @@ public final class MaterialItem extends AEBaseItem implements IStorageComponent, final Upgrades u = this.getType(stack); if (u != null) { - final List textList = new ArrayList<>(); - for (final Entry j : u.getSupported().entrySet()) { - ITextComponent name = null; - - final int limit = j.getValue(); - - if (j.getKey().getItem() instanceof IItemGroup) { - final IItemGroup ig = (IItemGroup) j.getKey().getItem(); - final String str = ig.getUnlocalizedGroupName(u.getSupported().keySet(), j.getKey()); - if (str != null) { - name = new TranslationTextComponent(str).appendText(limit > 1 ? " (" + limit + ')' : ""); - } - } - - if (name == null) { - name = j.getKey().getDisplayName().appendText((limit > 1 ? " (" + limit + ')' : "")); - } - - if (!textList.contains(name)) { - textList.add(name); - } - } - - final Pattern p = Pattern.compile("(\\d+)[^\\d]"); - // FIXME This comparison is not great... - final SlightlyBetterSort s = new SlightlyBetterSort(p); - textList.sort(s); - lines.addAll(textList); + lines.addAll(u.getTooltipLines()); } } @@ -229,27 +195,4 @@ public final class MaterialItem extends AEBaseItem implements IStorageComponent, return false; } - private static class SlightlyBetterSort implements Comparator { - private final Pattern pattern; - - public SlightlyBetterSort(final Pattern pattern) { - this.pattern = pattern; - } - - @Override - public int compare(final ITextComponent o1, final ITextComponent o2) { - try { - final Matcher a = this.pattern.matcher(o1.getString()); - final Matcher b = this.pattern.matcher(o2.getString()); - if (a.find() && b.find()) { - final int ia = Integer.parseInt(a.group(1)); - final int ib = Integer.parseInt(b.group(1)); - return Integer.compare(ia, ib); - } - } catch (final Throwable t) { - // ek! - } - return o1.getString().compareTo(o2.getString()); - } - } } diff --git a/src/main/java/appeng/items/parts/ColoredPartItem.java b/src/main/java/appeng/items/parts/ColoredPartItem.java index 149ed47bc..4e2fbba7a 100644 --- a/src/main/java/appeng/items/parts/ColoredPartItem.java +++ b/src/main/java/appeng/items/parts/ColoredPartItem.java @@ -11,8 +11,8 @@ public class ColoredPartItem extends PartItem { private final AEColor color; - public ColoredPartItem(Properties properties, PartType type, Function factory, AEColor color) { - super(properties, type, factory); + public ColoredPartItem(Properties properties, Function factory, AEColor color) { + super(properties, factory); this.color = color; } diff --git a/src/main/java/appeng/items/parts/PartItem.java b/src/main/java/appeng/items/parts/PartItem.java index 6af3ba4ef..0e33ebb7d 100644 --- a/src/main/java/appeng/items/parts/PartItem.java +++ b/src/main/java/appeng/items/parts/PartItem.java @@ -18,31 +18,24 @@ package appeng.items.parts; -import java.util.Set; import java.util.function.Function; -import javax.annotation.Nullable; - import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResultType; import appeng.api.AEApi; -import appeng.api.implementations.items.IItemGroup; import appeng.api.parts.IPart; import appeng.api.parts.IPartItem; -import appeng.core.localization.GuiText; import appeng.items.AEBaseItem; -public class PartItem extends AEBaseItem implements IPartItem, IItemGroup { - private final PartType type; +public class PartItem extends AEBaseItem implements IPartItem { private final Function factory; - public PartItem(Properties properties, PartType type, Function factory) { + public PartItem(Properties properties, Function factory) { super(properties); - this.type = type; this.factory = factory; } @@ -58,75 +51,9 @@ public class PartItem extends AEBaseItem implements IPartItem) is.getItem()).getType(); - } - return PartType.INVALID_TYPE; - } - - @Nullable - @Override - public String getUnlocalizedGroupName(final Set others, final ItemStack is) { - boolean importBus = false; - boolean importBusFluids = false; - boolean exportBus = false; - boolean exportBusFluids = false; - boolean group = false; - - final PartType u = getTypeByStack(is); - - for (final ItemStack stack : others) { - if (stack.getItem() == this) { - final PartType pt = getTypeByStack(stack); - switch (pt) { - case IMPORT_BUS: - importBus = true; - if (u == pt) { - group = true; - } - break; - case FLUID_IMPORT_BUS: - importBusFluids = true; - if (u == pt) { - group = true; - } - break; - case EXPORT_BUS: - exportBus = true; - if (u == pt) { - group = true; - } - break; - case FLUID_EXPORT_BUS: - exportBusFluids = true; - if (u == pt) { - group = true; - } - break; - default: - } - } - } - - if (group && importBus && exportBus && (u == PartType.IMPORT_BUS || u == PartType.EXPORT_BUS)) { - return GuiText.IOBuses.getTranslationKey(); - } - if (group && importBusFluids && exportBusFluids - && (u == PartType.FLUID_IMPORT_BUS || u == PartType.FLUID_EXPORT_BUS)) { - return GuiText.IOBusesFluids.getTranslationKey(); - } - - return null; - } - } diff --git a/src/main/java/appeng/items/parts/PartModelsHelper.java b/src/main/java/appeng/items/parts/PartModelsHelper.java index 81532144d..cff06101e 100644 --- a/src/main/java/appeng/items/parts/PartModelsHelper.java +++ b/src/main/java/appeng/items/parts/PartModelsHelper.java @@ -18,9 +18,9 @@ import appeng.core.AELog; * Helps with the reflection magic needed to gather all models for AE2 cable bus * parts. */ -class PartModelsHelper { +public class PartModelsHelper { - static List createModels(Class clazz) { + public static List createModels(Class clazz) { List locations = new ArrayList<>(); // Check all static fields for used models @@ -78,7 +78,7 @@ class PartModelsHelper { continue; } - Object value = null; + Object value; try { method.setAccessible(true); value = method.invoke(null); @@ -108,7 +108,7 @@ class PartModelsHelper { locations.addAll(((IPartModel) value).getModels()); } else if (value instanceof Collection) { // Check that each object is an IPartModel - Collection values = (Collection) value; + Collection values = (Collection) value; for (Object candidate : values) { if (!(candidate instanceof IPartModel)) { AELog.error("List of locations obtained from {} contains a non resource location: {}", source, diff --git a/src/main/java/appeng/items/parts/PartType.java b/src/main/java/appeng/items/parts/PartType.java deleted file mode 100644 index 12ca93c3e..000000000 --- a/src/main/java/appeng/items/parts/PartType.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * 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 . - */ - -package appeng.items.parts; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.Set; - -import net.minecraft.util.ResourceLocation; - -import appeng.api.features.AEFeature; -import appeng.api.parts.IPart; -import appeng.fluids.parts.FluidAnnihilationPlanePart; -import appeng.fluids.parts.FluidExportBusPart; -import appeng.fluids.parts.FluidFormationPlanePart; -import appeng.fluids.parts.FluidImportBusPart; -import appeng.fluids.parts.FluidInterfacePart; -import appeng.fluids.parts.FluidLevelEmitterPart; -import appeng.fluids.parts.FluidStorageBusPart; -import appeng.fluids.parts.FluidTerminalPart; -import appeng.parts.automation.AnnihilationPlanePart; -import appeng.parts.automation.ExportBusPart; -import appeng.parts.automation.FormationPlanePart; -import appeng.parts.automation.IdentityAnnihilationPlanePart; -import appeng.parts.automation.ImportBusPart; -import appeng.parts.automation.LevelEmitterPart; -import appeng.parts.misc.CableAnchorPart; -import appeng.parts.misc.InterfacePart; -import appeng.parts.misc.InvertedToggleBusPart; -import appeng.parts.misc.StorageBusPart; -import appeng.parts.misc.ToggleBusPart; -import appeng.parts.networking.CoveredCablePart; -import appeng.parts.networking.CoveredDenseCablePart; -import appeng.parts.networking.GlassCablePart; -import appeng.parts.networking.QuartzFiberPart; -import appeng.parts.networking.SmartCablePart; -import appeng.parts.networking.SmartDenseCablePart; -import appeng.parts.p2p.FEP2PTunnelPart; -import appeng.parts.p2p.FluidP2PTunnelPart; -import appeng.parts.p2p.ItemP2PTunnelPart; -import appeng.parts.p2p.LightP2PTunnelPart; -import appeng.parts.p2p.MEP2PTunnelPart; -import appeng.parts.p2p.RedstoneP2PTunnelPart; -import appeng.parts.reporting.ConversionMonitorPart; -import appeng.parts.reporting.CraftingTerminalPart; -import appeng.parts.reporting.DarkPanelPart; -import appeng.parts.reporting.InterfaceTerminalPart; -import appeng.parts.reporting.PanelPart; -import appeng.parts.reporting.PatternTerminalPart; -import appeng.parts.reporting.SemiDarkPanelPart; -import appeng.parts.reporting.StorageMonitorPart; -import appeng.parts.reporting.TerminalPart; - -public enum PartType { - INVALID_TYPE(EnumSet.of(AEFeature.CORE), EnumSet.noneOf(IntegrationType.class), null), - - CABLE_GLASS(EnumSet.of(AEFeature.GLASS_CABLES), EnumSet.noneOf(IntegrationType.class), GlassCablePart.class) { - @Override - public boolean isCable() { - return true; - } - }, - - CABLE_COVERED(EnumSet.of(AEFeature.COVERED_CABLES), EnumSet.noneOf(IntegrationType.class), CoveredCablePart.class) { - @Override - public boolean isCable() { - return true; - } - }, - - CABLE_SMART(EnumSet.of(AEFeature.CHANNELS, AEFeature.SMART_CABLES), EnumSet.noneOf(IntegrationType.class), - SmartCablePart.class) { - @Override - public boolean isCable() { - return true; - } - }, - - CABLE_DENSE_SMART(EnumSet.of(AEFeature.CHANNELS, AEFeature.DENSE_CABLES), EnumSet.noneOf(IntegrationType.class), - SmartDenseCablePart.class) { - @Override - public boolean isCable() { - return true; - } - }, - - CABLE_DENSE_COVERED(EnumSet.of(AEFeature.CHANNELS, AEFeature.DENSE_CABLES), EnumSet.noneOf(IntegrationType.class), - CoveredDenseCablePart.class) { - @Override - public boolean isCable() { - return true; - } - }, - - TOGGLE_BUS(EnumSet.of(AEFeature.TOGGLE_BUS), EnumSet.noneOf(IntegrationType.class), ToggleBusPart.class), - - INVERTED_TOGGLE_BUS(EnumSet.of(AEFeature.TOGGLE_BUS), EnumSet.noneOf(IntegrationType.class), - InvertedToggleBusPart.class), - - CABLE_ANCHOR(EnumSet.of(AEFeature.CABLE_ANCHOR), EnumSet.noneOf(IntegrationType.class), CableAnchorPart.class), - - QUARTZ_FIBER(EnumSet.of(AEFeature.QUARTZ_FIBER), EnumSet.noneOf(IntegrationType.class), QuartzFiberPart.class), - - MONITOR(EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), PanelPart.class), - - SEMI_DARK_MONITOR(EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), SemiDarkPanelPart.class), - - DARK_MONITOR(EnumSet.of(AEFeature.PANELS), EnumSet.noneOf(IntegrationType.class), DarkPanelPart.class), - - STORAGE_BUS(EnumSet.of(AEFeature.STORAGE_BUS), EnumSet.noneOf(IntegrationType.class), StorageBusPart.class), - FLUID_STORAGE_BUS(EnumSet.of(AEFeature.FLUID_STORAGE_BUS), EnumSet.noneOf(IntegrationType.class), - FluidStorageBusPart.class), - - IMPORT_BUS(EnumSet.of(AEFeature.IMPORT_BUS), EnumSet.noneOf(IntegrationType.class), ImportBusPart.class), - - FLUID_IMPORT_BUS(EnumSet.of(AEFeature.FLUID_IMPORT_BUS), EnumSet.noneOf(IntegrationType.class), - FluidImportBusPart.class), - - EXPORT_BUS(EnumSet.of(AEFeature.EXPORT_BUS), EnumSet.noneOf(IntegrationType.class), ExportBusPart.class), - - FLUID_EXPORT_BUS(EnumSet.of(AEFeature.FLUID_EXPORT_BUS), EnumSet.noneOf(IntegrationType.class), - FluidExportBusPart.class), - - LEVEL_EMITTER(EnumSet.of(AEFeature.LEVEL_EMITTER), EnumSet.noneOf(IntegrationType.class), LevelEmitterPart.class), - FLUID_LEVEL_EMITTER(EnumSet.of(AEFeature.FLUID_LEVEL_EMITTER), EnumSet.noneOf(IntegrationType.class), - FluidLevelEmitterPart.class), - - ANNIHILATION_PLANE(EnumSet.of(AEFeature.ANNIHILATION_PLANE), EnumSet.noneOf(IntegrationType.class), - AnnihilationPlanePart.class), - - IDENTITY_ANNIHILATION_PLANE(EnumSet.of(AEFeature.ANNIHILATION_PLANE, AEFeature.IDENTITY_ANNIHILATION_PLANE), - EnumSet.noneOf(IntegrationType.class), IdentityAnnihilationPlanePart.class), - - FLUID_ANNIHILATION_PLANE(EnumSet.of(AEFeature.FLUID_ANNIHILATION_PLANE), EnumSet.noneOf(IntegrationType.class), - FluidAnnihilationPlanePart.class), - - FORMATION_PLANE(EnumSet.of(AEFeature.FORMATION_PLANE), EnumSet.noneOf(IntegrationType.class), - FormationPlanePart.class), - - FLUID_FORMATION_PLANE(EnumSet.of(AEFeature.FLUID_FORMATION_PLANE), EnumSet.noneOf(IntegrationType.class), - FluidFormationPlanePart.class), - - PATTERN_TERMINAL(EnumSet.of(AEFeature.PATTERNS), EnumSet.noneOf(IntegrationType.class), PatternTerminalPart.class), - - CRAFTING_TERMINAL(EnumSet.of(AEFeature.CRAFTING_TERMINAL), EnumSet.noneOf(IntegrationType.class), - CraftingTerminalPart.class), - - TERMINAL(EnumSet.of(AEFeature.TERMINAL), EnumSet.noneOf(IntegrationType.class), TerminalPart.class), - - STORAGE_MONITOR(EnumSet.of(AEFeature.STORAGE_MONITOR), EnumSet.noneOf(IntegrationType.class), - StorageMonitorPart.class), - - CONVERSION_MONITOR(EnumSet.of(AEFeature.PART_CONVERSION_MONITOR), EnumSet.noneOf(IntegrationType.class), - ConversionMonitorPart.class), - - INTERFACE(EnumSet.of(AEFeature.INTERFACE), EnumSet.noneOf(IntegrationType.class), InterfacePart.class), - FLUID_INTERFACE(EnumSet.of(AEFeature.FLUID_INTERFACE), EnumSet.noneOf(IntegrationType.class), - FluidInterfacePart.class), - - P2P_TUNNEL_ME(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ME), EnumSet.noneOf(IntegrationType.class), - MEP2PTunnelPart.class), - - P2P_TUNNEL_REDSTONE(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_REDSTONE), - EnumSet.noneOf(IntegrationType.class), RedstoneP2PTunnelPart.class), - - P2P_TUNNEL_ITEM(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_ITEMS), EnumSet.noneOf(IntegrationType.class), - ItemP2PTunnelPart.class), - - P2P_TUNNEL_FLUID(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FLUIDS), - EnumSet.noneOf(IntegrationType.class), FluidP2PTunnelPart.class), - -//FIXME P2P_TUNNEL_IC2( 465, "p2p_tunnel_ic2", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_EU ), EnumSet -//FIXME .of( IntegrationType.IC2 ), PartP2PIC2Power.class ), - - P2P_TUNNEL_LIGHT(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_LIGHT), - EnumSet.noneOf(IntegrationType.class), LightP2PTunnelPart.class), - - P2P_TUNNEL_FE(EnumSet.of(AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FE), EnumSet.noneOf(IntegrationType.class), - FEP2PTunnelPart.class), - - // P2PTunnelOpenComputers( 468, EnumSet.of( AEFeature.P2PTunnel, - // AEFeature.P2PTunnelOpenComputers ), EnumSet.of( - // IntegrationType.OpenComputers ), PartP2POpenComputers.class, GuiText.OCTunnel - // ), - - INTERFACE_TERMINAL(EnumSet.of(AEFeature.INTERFACE_TERMINAL), EnumSet.noneOf(IntegrationType.class), - InterfaceTerminalPart.class), - - FLUID_TERMINAL(EnumSet.of(AEFeature.FLUID_TERMINAL), EnumSet.noneOf(IntegrationType.class), - FluidTerminalPart.class); - - private final Set features; - private final Set integrations; - private final Set models; - - PartType(final Set features, final Set integrations, final Class c) { - this.features = Collections.unmodifiableSet(features); - this.integrations = Collections.unmodifiableSet(integrations); - - if (c != null) { - this.models = new HashSet<>(PartModelsHelper.createModels(c)); - } else { - this.models = Collections.emptySet(); - } - } - - public boolean isCable() { - return false; - } - - public Set getFeature() { - return this.features; - } - - Set getIntegrations() { - return this.integrations; - } - - public Set getModels() { - return this.models; - } - -} - -enum IntegrationType { -} \ No newline at end of file diff --git a/src/main/java/appeng/items/storage/AbstractStorageCell.java b/src/main/java/appeng/items/storage/AbstractStorageCell.java index 4a1f65dbf..0123770a4 100644 --- a/src/main/java/appeng/items/storage/AbstractStorageCell.java +++ b/src/main/java/appeng/items/storage/AbstractStorageCell.java @@ -39,7 +39,6 @@ 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; import appeng.api.storage.IMEInventoryHandler; @@ -60,8 +59,7 @@ import appeng.util.Platform; * @version rv6 - 2018-01-17 * @since rv6 2018-01-17 */ -public abstract class AbstractStorageCell> extends AEBaseItem - implements IStorageCell, IItemGroup { +public abstract class AbstractStorageCell> extends AEBaseItem implements IStorageCell { protected final MaterialType component; protected final int totalBytes; @@ -104,11 +102,6 @@ public abstract class AbstractStorageCell> extends AEBaseI return true; } - @Override - public String getUnlocalizedGroupName(final Set others, final ItemStack is) { - return GuiText.StorageCells.getTranslationKey(); - } - @Override public boolean isEditable(final ItemStack is) { return true; diff --git a/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java b/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java index 915ae12ec..7380ce220 100644 --- a/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java +++ b/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java @@ -52,7 +52,6 @@ import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; -import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IStorageCell; import appeng.api.implementations.tiles.IColorableTile; import appeng.api.storage.IMEInventory; @@ -80,7 +79,7 @@ import appeng.util.Platform; import appeng.util.item.AEItemStack; public class ColorApplicatorItem extends AEBasePoweredItem - implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem { + implements IStorageCell, IBlockTool, IMouseWheelItem { private static final Map TAG_TO_COLOR = ImmutableMap.builder() .put(new ResourceLocation("forge:dyes/black"), AEColor.BLACK) @@ -409,11 +408,6 @@ public class ColorApplicatorItem extends AEBasePoweredItem return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); } - @Override - public String getUnlocalizedGroupName(final Set others, final ItemStack is) { - return GuiText.StorageCells.getTranslationKey(); - } - @Override public boolean isEditable(final ItemStack is) { return true; diff --git a/src/main/java/appeng/items/tools/powered/PortableCellItem.java b/src/main/java/appeng/items/tools/powered/PortableCellItem.java index 305e8d1b6..3f0ce0360 100644 --- a/src/main/java/appeng/items/tools/powered/PortableCellItem.java +++ b/src/main/java/appeng/items/tools/powered/PortableCellItem.java @@ -39,7 +39,6 @@ import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItemObject; -import appeng.api.implementations.items.IItemGroup; import appeng.api.implementations.items.IStorageCell; import appeng.api.storage.IStorageChannel; import appeng.api.storage.cells.ICellInventoryHandler; @@ -55,7 +54,7 @@ import appeng.items.contents.CellUpgrades; import appeng.items.contents.PortableCellViewer; import appeng.items.tools.powered.powersink.AEBasePoweredItem; -public class PortableCellItem extends AEBasePoweredItem implements IStorageCell, IGuiItem, IItemGroup { +public class PortableCellItem extends AEBasePoweredItem implements IStorageCell, IGuiItem { public PortableCellItem(Item.Properties props) { super(AEConfig.instance().getPortableCellBattery(), props); } @@ -118,11 +117,6 @@ public class PortableCellItem extends AEBasePoweredItem implements IStorageCell< return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); } - @Override - public String getUnlocalizedGroupName(final Set others, final ItemStack is) { - return GuiText.StorageCells.getTranslationKey(); - } - @Override public boolean isEditable(final ItemStack is) { return true; diff --git a/src/main/java/appeng/parts/AEBasePart.java b/src/main/java/appeng/parts/AEBasePart.java index 08a835301..f08e72ca6 100644 --- a/src/main/java/appeng/parts/AEBasePart.java +++ b/src/main/java/appeng/parts/AEBasePart.java @@ -31,7 +31,6 @@ import net.minecraft.crash.CrashReportCategory; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; @@ -67,8 +66,6 @@ import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.helpers.ICustomNameObject; import appeng.helpers.IPriorityHost; -import appeng.items.parts.PartItem; -import appeng.items.parts.PartType; import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; import appeng.parts.networking.CablePart; @@ -96,15 +93,6 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, return this.host; } - public PartType getType() { - Item item = this.is.getItem(); - if (!(item instanceof PartItem)) { - return PartType.INVALID_TYPE; - } - - return ((PartItem) item).getType(); - } - @Override public IGridNode getGridNode(final AEPartLocation dir) { return this.proxy.getNode(); diff --git a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java index dffc3827a..d7e662ad2 100644 --- a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java @@ -36,17 +36,12 @@ public class BlockUpgradeInventory extends UpgradeInventory { @Override public int getMaxInstalled(final Upgrades upgrades) { - int max = 0; - - for (final ItemStack is : upgrades.getSupported().keySet()) { - final Item encodedItem = is.getItem(); - - if (encodedItem instanceof BlockItem && Block.getBlockFromItem(encodedItem) == this.block) { - max = upgrades.getSupported().get(is); - break; + for (final Upgrades.Supported supported : upgrades.getSupported()) { + if (supported.isSupported(block)) { + return supported.getMaxCount(); } } - return max; + return 0; } } diff --git a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java index 6d706b61f..3b6ad729e 100644 --- a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java @@ -35,15 +35,12 @@ public final class DefinitionUpgradeInventory extends UpgradeInventory { @Override public int getMaxInstalled(final Upgrades upgrades) { - int max = 0; - - for (final ItemStack stack : upgrades.getSupported().keySet()) { - if (this.definition.isSameAs(stack)) { - max = upgrades.getSupported().get(stack); - break; + for (final Upgrades.Supported supported : upgrades.getSupported()) { + if (supported.isSupported(definition.item())) { + return supported.getMaxCount(); } } - return max; + return 0; } } diff --git a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java index 4dfea0de3..7d6136a80 100644 --- a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java @@ -33,15 +33,12 @@ public class StackUpgradeInventory extends UpgradeInventory { @Override public int getMaxInstalled(final Upgrades upgrades) { - int max = 0; - - for (final ItemStack is : upgrades.getSupported().keySet()) { - if (ItemStack.areItemsEqual(this.stack, is)) { - max = upgrades.getSupported().get(is); - break; + for (final Upgrades.Supported supported : upgrades.getSupported()) { + if (supported.isSupported(stack.getItem())) { + return supported.getMaxCount(); } } - return max; + return 0; } }