diff --git a/botany/src/main/java/binnie/botany/Botany.java b/botany/src/main/java/binnie/botany/Botany.java index da673d233..70fc506b6 100644 --- a/botany/src/main/java/binnie/botany/Botany.java +++ b/botany/src/main/java/binnie/botany/Botany.java @@ -82,11 +82,6 @@ public IBinnieGUID[] getGUIDs() { return BotanyGUI.values(); } - @Override - public Class[] getConfigs() { - return new Class[0]; - } - @Override public IPacketID[] getPacketIDs() { return PacketID.values(); diff --git a/botany/src/main/java/binnie/botany/genetics/FlowerRoot.java b/botany/src/main/java/binnie/botany/genetics/FlowerRoot.java index 10806694b..47214e149 100644 --- a/botany/src/main/java/binnie/botany/genetics/FlowerRoot.java +++ b/botany/src/main/java/binnie/botany/genetics/FlowerRoot.java @@ -209,11 +209,6 @@ public IAllele[] getDefaultTemplate() { return alleles; } - @Override - public IAllele[] getRandomTemplate(Random rand) { - return speciesTemplates.values().toArray(new IAllele[0][])[rand.nextInt(speciesTemplates.values().size())]; - } - @Override public ArrayList getMutations(boolean shuffle) { if (shuffle) { diff --git a/core/src/main/java/binnie/core/AbstractMod.java b/core/src/main/java/binnie/core/AbstractMod.java index 56be5ca6e..3acdbb19a 100644 --- a/core/src/main/java/binnie/core/AbstractMod.java +++ b/core/src/main/java/binnie/core/AbstractMod.java @@ -19,6 +19,7 @@ import binnie.core.network.IPacketProvider; import binnie.core.network.packet.MessageBinnie; import binnie.core.proxy.IProxyCore; +import binnie.core.util.EmptyHelper; public abstract class AbstractMod implements IPacketProvider, IInitializable { protected final List modules; @@ -40,15 +41,15 @@ public AbstractMod() { @Override public IPacketID[] getPacketIDs() { - return new IPacketID[0]; + return EmptyHelper.PACKET_IDS_EMPTY; } public IBinnieGUID[] getGUIDs() { - return new IBinnieGUID[0]; + return EmptyHelper.BINNIE_GUIDS_EMPTY; } public Class[] getConfigs() { - return new Class[0]; + return EmptyHelper.CLASS_ARRAY_EMPTY; } public abstract IProxyCore getProxy(); diff --git a/core/src/main/java/binnie/core/block/BlockMetadata.java b/core/src/main/java/binnie/core/block/BlockMetadata.java index 212e0c55c..b3bc26963 100644 --- a/core/src/main/java/binnie/core/block/BlockMetadata.java +++ b/core/src/main/java/binnie/core/block/BlockMetadata.java @@ -1,7 +1,6 @@ package binnie.core.block; import javax.annotation.Nullable; -import java.util.ArrayList; import java.util.List; import net.minecraft.block.Block; @@ -40,20 +39,18 @@ public static void getDrops(NonNullList drops, IBlockMetadata block, } public static boolean breakBlock(IBlockMetadata blockMetadata, @Nullable EntityPlayer player, World world, BlockPos pos) { - List drops = new ArrayList<>(); + List drops = null; Block block = (Block) blockMetadata; TileEntityMetadata tile = TileEntityMetadata.getTile(world, pos); if (tile != null && !tile.hasDroppedBlock()) { drops = block.getDrops(world, pos, world.getBlockState(pos), 0); } boolean hasBeenBroken = world.setBlockToAir(pos); - if (hasBeenBroken && !world.isRemote && drops.size() > 0 && (player == null || !player.capabilities.isCreativeMode)) { + if (hasBeenBroken && !world.isRemote && drops != null && (player == null || !player.capabilities.isCreativeMode)) { for (ItemStack drop : drops) { spawnAsEntity(world, pos, drop); } - if (tile != null) { - tile.dropBlock(); - } + tile.dropBlock(); } return hasBeenBroken; } diff --git a/core/src/main/java/binnie/core/block/TileEntityMetadata.java b/core/src/main/java/binnie/core/block/TileEntityMetadata.java index 9be053ee6..df8c4f3e1 100644 --- a/core/src/main/java/binnie/core/block/TileEntityMetadata.java +++ b/core/src/main/java/binnie/core/block/TileEntityMetadata.java @@ -40,8 +40,10 @@ public static ItemStack getItemStack(final Block block, final int damage) { return itemStack; } + private static final int MAX_ITEM_DAMAGE = 16387; + public static void setItemDamage(final ItemStack item, final int i) { - item.setItemDamage((i < 16387) ? i : 16387); + item.setItemDamage((i < MAX_ITEM_DAMAGE) ? i : MAX_ITEM_DAMAGE); final NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("meta", i); item.setTagCompound(tag); @@ -76,7 +78,7 @@ public NBTTagCompound getUpdateTag() { @Override public void readFromNBT(final NBTTagCompound nbt) { super.readFromNBT(nbt); - if(world!=null) + if (world != null) setTileMetadata(nbt.getInteger("meta"), world.isRemote); else this.meta = nbt.getInteger("meta"); diff --git a/core/src/main/java/binnie/core/circuits/BinnieCircuit.java b/core/src/main/java/binnie/core/circuits/BinnieCircuit.java index 174868d77..e244c6323 100644 --- a/core/src/main/java/binnie/core/circuits/BinnieCircuit.java +++ b/core/src/main/java/binnie/core/circuits/BinnieCircuit.java @@ -14,8 +14,10 @@ public class BinnieCircuit implements ICircuit { private final int limit; private final List tooltips; + private static final int TOOLTIPS_ARRAY_CAPACITY = 8; + public BinnieCircuit(final String uid, final int limit, final ICircuitLayout layout, final ItemStack itemStack) { - this.tooltips = new ArrayList<>(); + this.tooltips = new ArrayList<>(TOOLTIPS_ARRAY_CAPACITY); this.uid = "for.binnie.circuit." + uid; this.limit = limit; ChipsetManager.circuitRegistry.registerCircuit(this); diff --git a/core/src/main/java/binnie/core/config/ConfigProperty.java b/core/src/main/java/binnie/core/config/ConfigProperty.java index 918e5c24a..6e3d92be2 100644 --- a/core/src/main/java/binnie/core/config/ConfigProperty.java +++ b/core/src/main/java/binnie/core/config/ConfigProperty.java @@ -5,12 +5,14 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.apache.commons.lang3.StringUtils; + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) public @interface ConfigProperty { String key(); - String category() default ""; + String category() default StringUtils.EMPTY; String[] comment() default {}; diff --git a/core/src/main/java/binnie/core/genetics/AlleleHelper.java b/core/src/main/java/binnie/core/genetics/AlleleHelper.java index afd341ad8..bb8a8613b 100644 --- a/core/src/main/java/binnie/core/genetics/AlleleHelper.java +++ b/core/src/main/java/binnie/core/genetics/AlleleHelper.java @@ -3,7 +3,7 @@ import java.util.Locale; import java.util.regex.Pattern; -import binnie.core.util.EmptyHelper; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import forestry.api.core.EnumHumidity; @@ -205,12 +205,12 @@ private static String getUid(String key, String valueName, boolean needCapitaliz if (needCapitalize) { valueName = WordUtils.capitalize(valueName.toLowerCase(Locale.ENGLISH)); } - valueName = PATTERN_REPLACEMENT.matcher(valueName).replaceAll(EmptyHelper.EMPTY_STRING); + valueName = PATTERN_REPLACEMENT.matcher(valueName).replaceAll(StringUtils.EMPTY); return "forestry." + key + valueName; } private static String toAlleleDisplay(@Nullable String key, String valueName) { - String name = PATTERN_REPLACEMENT.matcher(valueName.toLowerCase()).replaceAll(EmptyHelper.EMPTY_STRING); + String name = PATTERN_REPLACEMENT.matcher(valueName.toLowerCase()).replaceAll(StringUtils.EMPTY); if (key == null) { return I18N.localise("forestry.allele." + name); } diff --git a/core/src/main/java/binnie/core/genetics/BreedingSystem.java b/core/src/main/java/binnie/core/genetics/BreedingSystem.java index 09cc31616..eebede49f 100644 --- a/core/src/main/java/binnie/core/genetics/BreedingSystem.java +++ b/core/src/main/java/binnie/core/genetics/BreedingSystem.java @@ -52,11 +52,10 @@ public abstract class BreedingSystem implements IBreedingSystem, IItemStackRepre private int discoveredBranchCount; protected BinnieSprite iconUndiscovered; protected BinnieSprite iconDiscovered; - protected List allActiveSpecies; - protected String currentEpithet; - private List allBranches; - private List allSpecies; - private List allMutations; + protected final List allActiveSpecies; + private final List allBranches; + private final List allSpecies; + private final List allMutations; private final ListMultiMap resultantMutations; private final ListMultiMap furtherMutations; private final ListMultiMap allResultantMutations; @@ -88,10 +87,8 @@ public String getChromosomeShortName(final IChromosomeType chromo) { @Override public final String getEpitome(final float discoveredPercentage) { - int i = 0; - if (discoveredPercentage == 1.0f) { - i = 6; - } else if (discoveredPercentage < 0.1f) { + int i; + if (discoveredPercentage < 0.1f) { i = 0; } else if (discoveredPercentage < 0.3f) { i = 1; @@ -103,6 +100,8 @@ public final String getEpitome(final float discoveredPercentage) { i = 4; } else if (discoveredPercentage < 1.0f) { i = 5; + } else { + i = 6; } return I18N.localise("binniecore." + this.getSpeciesRoot().getUID() + ".epitome." + i); } @@ -135,8 +134,8 @@ public void calculateArrays() { @Override public void calculateAlleles(ISpeciesRoot speciesRoot) { - this.allSpecies = new ArrayList<>(); - this.allActiveSpecies = new ArrayList<>(); + this.allSpecies.clear(); + this.allActiveSpecies.clear(); this.resultantMutations.clear(); this.furtherMutations.clear(); this.allResultantMutations.clear(); @@ -159,51 +158,48 @@ public void calculateAlleles(ISpeciesRoot speciesRoot) { @Override public void calculateBranches(ISpeciesRoot speciesRoot) { Collection allRegBranches = AlleleManager.alleleRegistry.getRegisteredClassifications().values(); - this.allBranches = new ArrayList<>(); + this.allBranches.clear(); for (IClassification branch : allRegBranches) { IAlleleSpecies[] species = branch.getMemberSpecies(); - if (species.length <= 0) { + if (species.length == 0) { continue; } IAlleleSpecies firstSpecies = species[0]; IAllele[] template = speciesRoot.getTemplate(firstSpecies.getUID()); if (template != null) { - boolean possible = false; - for (IAlleleSpecies species2 : branch.getMemberSpecies()) { + for (final IAlleleSpecies species2 : branch.getMemberSpecies()) { if (allActiveSpecies.contains(species2)) { - possible = true; + this.allBranches.add(branch); + break; } } - if (!possible) { - continue; - } - this.allBranches.add(branch); } } } @Override public void calculateMutations(ISpeciesRoot speciesRoot) { - this.allMutations = new ArrayList<>(); + this.allMutations.clear(); List speciesMutations = speciesRoot.getMutations(false); - if (!speciesMutations.isEmpty()) { - final Set mutations = new LinkedHashSet<>(speciesMutations); - for (final IMutation mutation : mutations) { - this.allMutations.add(mutation); - final Set participatingSpecies = new LinkedHashSet<>(); - participatingSpecies.add(mutation.getAllele0()); - participatingSpecies.add(mutation.getAllele1()); - for (final IAlleleSpecies species : participatingSpecies) { - this.allFurtherMutations.put(species, mutation); - if (this.allActiveSpecies.contains(species)) { - this.furtherMutations.put(species, mutation); - } + if (speciesMutations.isEmpty()) { + return; + } + Set mutations = new LinkedHashSet<>(speciesMutations); + for (IMutation mutation : mutations) { + this.allMutations.add(mutation); + Set participatingSpecies = new LinkedHashSet<>(); + participatingSpecies.add(mutation.getAllele0()); + participatingSpecies.add(mutation.getAllele1()); + for (IAlleleSpecies species : participatingSpecies) { + this.allFurtherMutations.put(species, mutation); + if (this.allActiveSpecies.contains(species)) { + this.furtherMutations.put(species, mutation); } - IAllele[] template = mutation.getTemplate(); - IAlleleSpecies speciesAllele = (IAlleleSpecies) template[0]; - this.allResultantMutations.put(speciesAllele, mutation); - this.resultantMutations.put(speciesAllele, mutation); } + IAllele[] template = mutation.getTemplate(); + IAlleleSpecies speciesAllele = (IAlleleSpecies) template[0]; + this.allResultantMutations.put(speciesAllele, mutation); + this.resultantMutations.put(speciesAllele, mutation); } } @@ -266,16 +262,13 @@ public final boolean isSecret(final IClassification branch) { @Override public final Collection getDiscoveredBranches(final World world, final GameProfile player) { final List branches = new ArrayList<>(); - for (final IClassification branch : this.getAllBranches()) { - boolean discovered = false; + for (IClassification branch : this.allBranches) { for (final IAlleleSpecies species : branch.getMemberSpecies()) { if (this.isSpeciesDiscovered(species, world, player)) { - discovered = true; + branches.add(branch); + break; } } - if (discovered) { - branches.add(branch); - } } return branches; } @@ -283,16 +276,13 @@ public final Collection getDiscoveredBranches(final World world @Override public final Collection getDiscoveredBranches(final IBreedingTracker tracker) { final List branches = new ArrayList<>(); - for (final IClassification branch : this.getAllBranches()) { - boolean discovered = false; + for (IClassification branch : this.allBranches) { for (final IAlleleSpecies species : branch.getMemberSpecies()) { if (this.isSpeciesDiscovered(species, tracker)) { - discovered = true; + branches.add(branch); + break; } } - if (discovered) { - branches.add(branch); - } } return branches; } @@ -300,7 +290,7 @@ public final Collection getDiscoveredBranches(final IBreedingTr @Override public final Collection getDiscoveredSpecies(final World world, final GameProfile player) { final List speciesList = new ArrayList<>(); - for (final IAlleleSpecies species : this.getAllSpecies()) { + for (final IAlleleSpecies species : this.allActiveSpecies) { if (this.isSpeciesDiscovered(species, world, player)) { speciesList.add(species); } @@ -311,7 +301,7 @@ public final Collection getDiscoveredSpecies(final World world, @Override public final Collection getDiscoveredSpecies(final IBreedingTracker tracker) { final List speciesList = new ArrayList<>(); - for (final IAlleleSpecies species : this.getAllSpecies()) { + for (final IAlleleSpecies species : this.allActiveSpecies) { if (this.isSpeciesDiscovered(species, tracker)) { speciesList.add(species); } @@ -321,7 +311,7 @@ public final Collection getDiscoveredSpecies(final IBreedingTrac public final List getDiscoveredMutations(final World world, final GameProfile player) { final List speciesList = new ArrayList<>(); - for (final IMutation species : this.getAllMutations()) { + for (final IMutation species : this.allMutations) { if (this.isMutationDiscovered(species, world, player)) { speciesList.add(species); } @@ -365,17 +355,17 @@ public final void syncTracker(final IBreedingTracker tracker) { this.totalSecretCount = 0; this.discoveredSecretCount = 0; final Collection discoveredSpecies = this.getDiscoveredSpecies(tracker); - final Collection allSpecies = this.getAllSpecies(); + final Collection allSpecies = this.allActiveSpecies; for (final IAlleleSpecies species : allSpecies) { if (!this.isSecret(species)) { ++this.totalSpeciesCount; - if (!this.isSpeciesDiscovered(species, tracker)) { + if (!discoveredSpecies.contains(species)) { continue; } ++this.discoveredSpeciesCount; } else { ++this.totalSecretCount; - if (!this.isSpeciesDiscovered(species, tracker)) { + if (!discoveredSpecies.contains(species)) { continue; } ++this.discoveredSecretCount; @@ -385,7 +375,7 @@ public final void syncTracker(final IBreedingTracker tracker) { this.totalBranchCount = 0; this.discoveredBranchCount = 0; final Collection discoveredBranches = this.getDiscoveredBranches(tracker); - final Collection allBranches = this.getAllBranches(); + final Collection allBranches = this.allBranches; for (final IClassification branch : allBranches) { if (!this.isSecret(branch)) { ++this.totalBranchCount; @@ -403,8 +393,6 @@ public final void syncTracker(final IBreedingTracker tracker) { } this.discoveredSpeciesPercentage = this.discoveredSpeciesCount / this.totalSpeciesCount; this.discoveredBranchPercentage = this.discoveredBranchCount / this.totalBranchCount; - final String epithet = this.getEpitome(); - this.onSyncBreedingTracker(tracker); } @Override @@ -448,8 +436,9 @@ public String getName() { @Override public ItemStack getItemStackRepresentitive() { - final IIndividual first = this.getSpeciesRoot().getIndividualTemplates().get(0); - return this.getSpeciesRoot().getMemberStack(first, this.getDefaultType()); + ISpeciesRoot root = this.getSpeciesRoot(); + IIndividual first = root.getIndividualTemplates().get(0); + return root.getMemberStack(first, this.getDefaultType()); } @Override @@ -465,7 +454,8 @@ public IIndividual getConversion(final ItemStack stack) { @Override public final IIndividual getDefaultIndividual() { - return this.getSpeciesRoot().templateAsIndividual(this.getSpeciesRoot().getDefaultTemplate()); + ISpeciesRoot root = this.getSpeciesRoot(); + return root.templateAsIndividual(root.getDefaultTemplate()); } @Override @@ -506,11 +496,12 @@ public ItemStack getDefaultMember(final String uid) { @Override @Nullable public IIndividual getIndividual(String uid) { - IAllele[] template = this.getSpeciesRoot().getTemplate(uid); + ISpeciesRoot root = this.getSpeciesRoot(); + IAllele[] template = root.getTemplate(uid); if (template == null) { return null; } - return this.getSpeciesRoot().templateAsIndividual(template); + return root.templateAsIndividual(template); } @Override diff --git a/core/src/main/java/binnie/core/genetics/ManagerGenetics.java b/core/src/main/java/binnie/core/genetics/ManagerGenetics.java index 5cb1aac08..e92d94684 100644 --- a/core/src/main/java/binnie/core/genetics/ManagerGenetics.java +++ b/core/src/main/java/binnie/core/genetics/ManagerGenetics.java @@ -70,7 +70,6 @@ public static ItemStack analyse(ItemStack stack, World world, GameProfile userna if (!conv.isEmpty()) { conv.setCount(stack.getCount()); stack = conv; - } ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack); if (root != null) { @@ -179,11 +178,12 @@ private void refreshData() { private void loadAlleles() { this.invalidChromosomeTypes.clear(); + final ComparatorAllele comparator = new ComparatorAllele(); for (IBreedingSystem system : BREEDING_SYSTEMS.values()) { ISpeciesRoot root = system.getSpeciesRoot(); Map> chromosomeMap = new LinkedHashMap<>(); for (IChromosomeType chromosome : root.getKaryotype()) { - TreeSet alleles = new TreeSet<>(new ComparatorAllele()); + TreeSet alleles = new TreeSet<>(comparator); for (IIndividual individual : root.getIndividualTemplates()) { IGenome genome = individual.getGenome(); IAllele activeAllele = genome.getActiveAllele(chromosome); diff --git a/core/src/main/java/binnie/core/genetics/Tolerance.java b/core/src/main/java/binnie/core/genetics/Tolerance.java index 2aa771f55..f791a1e43 100644 --- a/core/src/main/java/binnie/core/genetics/Tolerance.java +++ b/core/src/main/java/binnie/core/genetics/Tolerance.java @@ -1,12 +1,16 @@ package binnie.core.genetics; import java.util.Locale; +import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; +import javax.annotation.Nullable; + public enum Tolerance { NONE(0, 0), BOTH_1(-1, 1), BOTH_2(-2, 2), BOTH_3(-3, 3), BOTH_4(-4, 4), BOTH_5(-5, 5), @@ -29,9 +33,19 @@ public static > boolean canTolerate(final T base, final T test return get(tol).canTolerate(base, test); } + @Nullable + private static Pattern PATTERN; + + private static Pattern getPattern() { + if (PATTERN == null) { + PATTERN = Pattern.compile("_", Pattern.LITERAL); + } + return PATTERN; + } + @Override public String toString() { - return super.toString().toLowerCase(Locale.ENGLISH).replace("_", ""); + return getPattern().matcher(super.toString().toLowerCase(Locale.ENGLISH)).replaceAll(StringUtils.EMPTY); } public String getUID() { diff --git a/core/src/main/java/binnie/core/gui/Widget.java b/core/src/main/java/binnie/core/gui/Widget.java index 813c5ec50..6d2fbc783 100644 --- a/core/src/main/java/binnie/core/gui/Widget.java +++ b/core/src/main/java/binnie/core/gui/Widget.java @@ -357,11 +357,9 @@ public final void render(int guiWidth, int guiHeight) { public void onRender(final RenderStage stage, int guiWidth, int guiHeight) { if (stage == RenderStage.PRE_CHILDREN) { this.onRenderBackground(guiWidth, guiHeight); - } - if (stage == RenderStage.POST_CHILDREN) { + } else if (stage == RenderStage.POST_CHILDREN) { this.onRenderForeground(guiWidth, guiHeight); - } - if (stage == RenderStage.POST_SIBLINGS) { + } else if (stage == RenderStage.POST_SIBLINGS) { this.onRenderOverlay(); } } @@ -452,9 +450,4 @@ public final void updateClient() { public final void delete() { this.getTopParent().widgetDeleted(this); } - - //TODO: Why not use "this" ? - public IWidget getWidget() { - return this; - } } diff --git a/core/src/main/java/binnie/core/gui/controls/ControlCheckbox.java b/core/src/main/java/binnie/core/gui/controls/ControlCheckbox.java index 427ec12f9..7ef6aad0f 100644 --- a/core/src/main/java/binnie/core/gui/controls/ControlCheckbox.java +++ b/core/src/main/java/binnie/core/gui/controls/ControlCheckbox.java @@ -46,15 +46,17 @@ public void setValue(final Boolean value) { } public void toggleValue() { - this.setValue(!this.getValue()); + this.setValue(!this.value); } @Override @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { - Object texture = this.getValue() ? CraftGUITexture.CHECKBOX_CHECKED : CraftGUITexture.CHECKBOX; + Object texture; if (this.isMouseOver()) { - texture = (this.getValue() ? CraftGUITexture.CHECKBOX_CHECKED_HIGHLIGHTED : CraftGUITexture.CHECKBOX_HIGHLIGHTED); + texture = (this.value ? CraftGUITexture.CHECKBOX_CHECKED_HIGHLIGHTED : CraftGUITexture.CHECKBOX_HIGHLIGHTED); + } else { + texture = this.value ? CraftGUITexture.CHECKBOX_CHECKED : CraftGUITexture.CHECKBOX; } CraftGUI.RENDER.texture(texture, Point.ZERO); } diff --git a/core/src/main/java/binnie/core/gui/controls/ControlTextEdit.java b/core/src/main/java/binnie/core/gui/controls/ControlTextEdit.java index 4adaadac1..13c6b53db 100644 --- a/core/src/main/java/binnie/core/gui/controls/ControlTextEdit.java +++ b/core/src/main/java/binnie/core/gui/controls/ControlTextEdit.java @@ -15,6 +15,7 @@ import binnie.core.gui.events.EventTextEdit; import binnie.core.gui.events.EventWidget; import binnie.core.gui.resource.textures.CraftGUITexture; +import org.apache.commons.lang3.StringUtils; @SideOnly(Side.CLIENT) public class ControlTextEdit extends Control implements IControlValue { @@ -23,7 +24,7 @@ public class ControlTextEdit extends Control implements IControlValue { public ControlTextEdit(final IWidget parent, final int x, final int y, final int width, final int height) { super(parent, x, y, width, height); - this.cachedValue = ""; + this.cachedValue = StringUtils.EMPTY; this.field = new GuiTextField(0, this.getWindow().getGui().getFontRenderer(), 0, 0, 10, 10); this.addAttribute(Attribute.CAN_FOCUS); this.addAttribute(Attribute.MOUSE_OVER); @@ -50,7 +51,7 @@ public ControlTextEdit(final IWidget parent, final int x, final int y, final int @Override public String getValue() { - return (this.field.getText() == null) ? "" : this.field.getText(); + return (this.field.getText() == null) ? StringUtils.EMPTY : this.field.getText(); } @Override diff --git a/core/src/main/java/binnie/core/gui/controls/ControlToleranceBar.java b/core/src/main/java/binnie/core/gui/controls/ControlToleranceBar.java index b1a547c5b..13e0139c1 100644 --- a/core/src/main/java/binnie/core/gui/controls/ControlToleranceBar.java +++ b/core/src/main/java/binnie/core/gui/controls/ControlToleranceBar.java @@ -19,6 +19,7 @@ import binnie.core.gui.geometry.Area; import binnie.core.gui.geometry.Border; import binnie.core.gui.renderer.RenderUtil; +import org.apache.commons.lang3.StringUtils; public abstract class ControlToleranceBar> extends Control implements ITooltip { private final EnumSet tolerated; @@ -42,7 +43,7 @@ public void getTooltip(Tooltip tooltip, ITooltipFlag tooltipFlag) { int type = getRelativeMousePosition().xPos() / (getSize().xPos() / types); for (T tol : fullSet) { if (tol.ordinal() - ((enumClass == EnumTemperature.class) ? 1 : 0) == type) { - tooltip.add((tolerated.contains(tol) ? "" : TextFormatting.DARK_GRAY) + getName(tol)); + tooltip.add((tolerated.contains(tol) ? StringUtils.EMPTY : TextFormatting.DARK_GRAY) + getName(tol)); } } } diff --git a/core/src/main/java/binnie/core/gui/controls/button/ControlButton.java b/core/src/main/java/binnie/core/gui/controls/button/ControlButton.java index 80f147248..6d322db18 100644 --- a/core/src/main/java/binnie/core/gui/controls/button/ControlButton.java +++ b/core/src/main/java/binnie/core/gui/controls/button/ControlButton.java @@ -25,7 +25,7 @@ public ControlButton(final IWidget parent, final int x, final int y, final int w super(parent, x, y, width, height); this.addAttribute(Attribute.MOUSE_OVER); this.addSelfEventHandler(EventMouse.Down.class, event -> { - ControlButton.this.callEvent(new EventButtonClicked(ControlButton.this.getWidget())); + ControlButton.this.callEvent(new EventButtonClicked(ControlButton.this)); ControlButton.this.onMouseClick(event); }); } @@ -57,11 +57,13 @@ public String getText() { @Override @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { - Object texture = CraftGUITexture.BUTTON_DISABLED; + final Object texture; if (this.isMouseOver()) { texture = CraftGUITexture.BUTTON_HIGHLIGHTED; } else if (this.isEnabled()) { texture = CraftGUITexture.BUTTON; + } else { + texture = CraftGUITexture.BUTTON_DISABLED; } CraftGUI.RENDER.texture(texture, this.getArea()); } diff --git a/core/src/main/java/binnie/core/gui/controls/scroll/ControlScrollBar.java b/core/src/main/java/binnie/core/gui/controls/scroll/ControlScrollBar.java index b23fb76e6..5105bc081 100644 --- a/core/src/main/java/binnie/core/gui/controls/scroll/ControlScrollBar.java +++ b/core/src/main/java/binnie/core/gui/controls/scroll/ControlScrollBar.java @@ -63,11 +63,13 @@ protected Area getRenderArea() { @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { final Area renderArea = this.getRenderArea(); - Object texture = CraftGUITexture.SCROLL_DISABLED; + Object texture; if (this.isMouseOver()) { texture = CraftGUITexture.SCROLL_HIGHLIGHTED; } else if (this.isEnabled()) { texture = CraftGUITexture.SCROLL; + } else { + texture = CraftGUITexture.SCROLL_DISABLED; } CraftGUI.RENDER.texture(texture, renderArea); } diff --git a/core/src/main/java/binnie/core/gui/controls/tab/ControlTab.java b/core/src/main/java/binnie/core/gui/controls/tab/ControlTab.java index 8dacdd97f..d452891b2 100644 --- a/core/src/main/java/binnie/core/gui/controls/tab/ControlTab.java +++ b/core/src/main/java/binnie/core/gui/controls/tab/ControlTab.java @@ -31,7 +31,7 @@ public ControlTab(final int x, final int y, final int w, final int h, final T va this.value = value; this.addAttribute(Attribute.MOUSE_OVER); this.addSelfEventHandler(EventMouse.Down.class, event -> { - ControlTab.this.callEvent(new EventValueChanged(ControlTab.this.getWidget(), ControlTab.this.getValue())); + ControlTab.this.callEvent(new EventValueChanged(ControlTab.this, ControlTab.this.getValue())); }); } @@ -77,11 +77,13 @@ public String getName() { @Override @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { - Object texture = CraftGUITexture.TAB_DISABLED; + Object texture; if (this.isMouseOver()) { texture = CraftGUITexture.TAB_HIGHLIGHTED; } else if (this.isCurrentSelection()) { texture = CraftGUITexture.TAB; + } else { + texture = CraftGUITexture.TAB_DISABLED; } final ITexture lTexture = CraftGUI.RENDER.getTexture(texture); final Alignment alignment = this.getTabPosition(); diff --git a/core/src/main/java/binnie/core/gui/database/PageBranchOverview.java b/core/src/main/java/binnie/core/gui/database/PageBranchOverview.java index 590db127e..4e297d2e5 100644 --- a/core/src/main/java/binnie/core/gui/database/PageBranchOverview.java +++ b/core/src/main/java/binnie/core/gui/database/PageBranchOverview.java @@ -1,8 +1,9 @@ package binnie.core.gui.database; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.List; -import java.util.Objects; import net.minecraft.util.text.TextFormatting; @@ -27,9 +28,9 @@ public class PageBranchOverview extends PageBranch { public PageBranchOverview(final IWidget parent, final DatabaseTab tab) { super(parent, tab); this.branchDescription = new ArrayList<>(); - this.branchName = new ControlTextCentered(this, 8, ""); - this.branchScientific = new ControlTextCentered(this, 32, ""); - this.branchAuthority = new ControlTextCentered(this, 44, ""); + this.branchName = new ControlTextCentered(this, 8, StringUtils.EMPTY); + this.branchScientific = new ControlTextCentered(this, 32, StringUtils.EMPTY); + this.branchAuthority = new ControlTextCentered(this, 44, StringUtils.EMPTY); } @Override @@ -42,7 +43,7 @@ public void onValueChanged(final IClassification branch) { } this.branchDescription.clear(); String desc = branch.getDescription(); - if (desc == null || Objects.equals(desc, "") || desc.contains("for.")) { + if (desc == null || StringUtils.isEmpty(desc) || desc.contains("for.")) { desc = I18N.localise(DatabaseConstants.BRANCH_KEY + ".noDesc"); } StringBuilder line = new StringBuilder(); @@ -50,7 +51,7 @@ public void onValueChanged(final IClassification branch) { for (final String str : desc.split(" ")) { if (RenderUtil.getTextWidth(line + " " + str) > 134) { descLines.add(TextFormatting.ITALIC + line.toString() + TextFormatting.RESET); - line = new StringBuilder(); + line.setLength(0); } line.append(' ').append(str); } diff --git a/core/src/main/java/binnie/core/gui/database/PageSpeciesClassification.java b/core/src/main/java/binnie/core/gui/database/PageSpeciesClassification.java index 1df916f43..e3ea39383 100644 --- a/core/src/main/java/binnie/core/gui/database/PageSpeciesClassification.java +++ b/core/src/main/java/binnie/core/gui/database/PageSpeciesClassification.java @@ -9,6 +9,7 @@ import binnie.core.api.gui.IWidget; import binnie.core.gui.controls.ControlText; import binnie.core.gui.controls.ControlTextCentered; +import org.apache.commons.lang3.StringUtils; public class PageSpeciesClassification extends PageSpecies { private final Map levels; @@ -19,12 +20,12 @@ public PageSpeciesClassification(final IWidget parent, final DatabaseTab tab) { this.levels = new LinkedHashMap<>(); int y = 16; for (final IClassification.EnumClassLevel level : IClassification.EnumClassLevel.values()) { - final ControlText text = new ControlTextCentered(this, y, ""); + final ControlText text = new ControlTextCentered(this, y, StringUtils.EMPTY); text.setColor(level.getColour()); this.levels.put(level, text); y += 12; } - (this.genus = new ControlTextCentered(this, y, "")).setColor(16759415); + (this.genus = new ControlTextCentered(this, y, StringUtils.EMPTY)).setColor(16759415); } @Override diff --git a/core/src/main/java/binnie/core/gui/database/PageSpeciesOverview.java b/core/src/main/java/binnie/core/gui/database/PageSpeciesOverview.java index 8445e802f..26ac73f0a 100644 --- a/core/src/main/java/binnie/core/gui/database/PageSpeciesOverview.java +++ b/core/src/main/java/binnie/core/gui/database/PageSpeciesOverview.java @@ -17,6 +17,9 @@ import binnie.core.gui.geometry.Point; import binnie.core.gui.geometry.TextJustification; import binnie.core.util.I18N; +import binnie.core.util.EmptyHelper; + +import org.apache.commons.lang3.StringUtils; @SideOnly(Side.CLIENT) public class PageSpeciesOverview extends PageSpecies { @@ -33,12 +36,12 @@ public PageSpeciesOverview(final IWidget parent, final DatabaseTab tab) { super(parent, tab); this.controlInd1 = new ControlIndividualDisplay(this, 5, 5); this.controlInd2 = new ControlIndividualDisplay(this, 123, 5); - this.controlName = new ControlTextCentered(this, 8, ""); - this.controlScientific = new ControlTextCentered(this, 32, ""); - this.controlAuthority = new ControlTextCentered(this, 44, ""); - this.controlComplexity = new ControlTextCentered(this, 68, ""); - this.controlDescription = new ControlText(this, new Area(8, 84, this.getSize().xPos() - 16, 0), "", TextJustification.MIDDLE_CENTER); - this.controlSignature = new ControlText(this, new Area(8, 84, this.getSize().xPos() - 16, 0), "", TextJustification.BOTTOM_RIGHT); + this.controlName = new ControlTextCentered(this, 8, StringUtils.EMPTY); + this.controlScientific = new ControlTextCentered(this, 32, StringUtils.EMPTY); + this.controlAuthority = new ControlTextCentered(this, 44, StringUtils.EMPTY); + this.controlComplexity = new ControlTextCentered(this, 68, StringUtils.EMPTY); + this.controlDescription = new ControlText(this, new Area(8, 84, this.getSize().xPos() - 16, 0), StringUtils.EMPTY, TextJustification.MIDDLE_CENTER); + this.controlSignature = new ControlText(this, new Area(8, 84, this.getSize().xPos() - 16, 0), StringUtils.EMPTY, TextJustification.BOTTOM_RIGHT); } @Override @@ -52,8 +55,8 @@ public void onValueChanged(final IAlleleSpecies species) { this.controlComplexity.setValue(I18N.localise(DatabaseConstants.KEY + ".overview.complexity") + ": " + species.getComplexity()); final String desc = species.getDescription(); StringBuilder descBody = new StringBuilder(TextFormatting.ITALIC.toString()); - String descSig = ""; - if (desc == null || Objects.equals(desc, "") || desc.contains("for.description") || desc.contains(".desc")) { + String descSig = StringUtils.EMPTY; + if (desc == null || desc.length() == 0 || desc.contains("for.description") || desc.contains(".desc")) { descBody.append(I18N.localise(DatabaseConstants.KEY + ".no.description")); } else { final String[] descStrings = desc.split("\\|"); diff --git a/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java b/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java index 4fed4fc84..1e80eea0e 100644 --- a/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java +++ b/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java @@ -37,6 +37,7 @@ import binnie.core.gui.minecraft.control.ControlHelp; import binnie.core.gui.window.Panel; import binnie.core.util.I18N; +import org.apache.commons.lang3.StringUtils; public abstract class WindowAbstractDatabase extends Window { private final boolean master; @@ -133,7 +134,7 @@ public void initialiseClient() { this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.DIRECT_CHILD, this, event -> { for (final ModeWidgets widgets : WindowAbstractDatabase.this.modes.values()) { widgets.getListBox().setValidator(object -> { - if (Objects.equals(event.getValue(), "")) { + if (Objects.equals(event.getValue(), StringUtils.EMPTY)) { return true; } ControlTextOption controlTextOption = (ControlTextOption) object; diff --git a/core/src/main/java/binnie/core/gui/fieldkit/ControlChromoPicker.java b/core/src/main/java/binnie/core/gui/fieldkit/ControlChromoPicker.java index c329cd01b..fa0e0cab2 100644 --- a/core/src/main/java/binnie/core/gui/fieldkit/ControlChromoPicker.java +++ b/core/src/main/java/binnie/core/gui/fieldkit/ControlChromoPicker.java @@ -33,10 +33,10 @@ public ControlChromoPicker(ControlChromosome parent, int x, int y, IChromosomeTy addAttribute(Attribute.MOUSE_OVER); this.parent = parent; addSelfEventHandler(EventWidget.StartMouseOver.class, event -> { - callEvent(new EventValueChanged(getWidget(), type)); + callEvent(new EventValueChanged(this, type)); }); addSelfEventHandler(EventWidget.EndMouseOver.class, event -> { - callEvent(new EventValueChanged<>(getWidget(), null)); + callEvent(new EventValueChanged<>(this, null)); }); } diff --git a/core/src/main/java/binnie/core/gui/fieldkit/ControlChromosome.java b/core/src/main/java/binnie/core/gui/fieldkit/ControlChromosome.java index 0f39807aa..521f6178e 100644 --- a/core/src/main/java/binnie/core/gui/fieldkit/ControlChromosome.java +++ b/core/src/main/java/binnie/core/gui/fieldkit/ControlChromosome.java @@ -40,7 +40,6 @@ public void setSystem(@Nullable IBreedingSystem breedingSystem) { if (breedingSystem != null) { IFieldKitPlugin fieldKitPlugin = breedingSystem.getFieldKitPlugin(); - fieldKitPlugin.getChromosomePickerPositions(); for (Map.Entry entry : fieldKitPlugin.getChromosomePickerPositions().entrySet()) { IChromosomeType chromosomeType = entry.getKey(); diff --git a/core/src/main/java/binnie/core/gui/fieldkit/WindowFieldKit.java b/core/src/main/java/binnie/core/gui/fieldkit/WindowFieldKit.java index e7c96b8be..ee07e31d2 100644 --- a/core/src/main/java/binnie/core/gui/fieldkit/WindowFieldKit.java +++ b/core/src/main/java/binnie/core/gui/fieldkit/WindowFieldKit.java @@ -45,6 +45,7 @@ import binnie.core.gui.resource.textures.StandardTexture; import binnie.core.texture.BinnieCoreTexture; import binnie.core.util.I18N; +import org.apache.commons.lang3.StringUtils; public class WindowFieldKit extends Window { public static final int INDIVIDUAL_SLOT = 0; @@ -106,7 +107,7 @@ public void initialiseClient() { new ControlSlot.Builder(this, handGlass.xPos() + 54, handGlass.yPos() + 26).assign(InventoryType.WINDOW, 0); new ControlSlot.Builder(this, 208, 8).assign(InventoryType.WINDOW, 1); (this.text = new ControlText(this, new Point(232, 13), I18N.localise("binniecore.gui.fieldkit.paper"))).setColor(2236962); - (this.text = new ControlText(this, new Area(0, 120, this.getWidth(), 24), "", TextJustification.MIDDLE_CENTER)).setColor(2236962); + (this.text = new ControlText(this, new Area(0, 120, this.getWidth(), 24), StringUtils.EMPTY, TextJustification.MIDDLE_CENTER)).setColor(2236962); this.chromo = new ControlChromosome(this, 150, 24); this.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, this.chromo, event -> { final IChromosomeType type = (IChromosomeType) event.getValue(); @@ -114,7 +115,7 @@ public void initialiseClient() { final String t = WindowFieldKit.this.info.get(type); WindowFieldKit.this.text.setValue(t); } else { - WindowFieldKit.this.text.setValue(""); + WindowFieldKit.this.text.setValue(StringUtils.EMPTY); } }); } @@ -209,10 +210,9 @@ public void onWindowInventoryChanged() { kit.setItemDamage(64 - size); } ((EntityPlayerMP) this.getPlayer()).updateHeldItem(); - } - if (this.isClient()) { + } else if (this.isClient()) { final ItemStack item = inventory.getStackInSlot(INDIVIDUAL_SLOT); - this.text.setValue(""); + this.text.setValue(StringUtils.EMPTY); if (!item.isEmpty() && !ManagerGenetics.isAnalysed(item)) { if (inventory.getStackInSlot(PAPER_SLOT).isEmpty()) { this.text.setValue(I18N.localise("binniecore.gui.fieldkit.paper.no")); diff --git a/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java b/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java index c423cb739..6bfd6d53c 100644 --- a/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java +++ b/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java @@ -41,6 +41,7 @@ import binnie.core.gui.minecraft.control.ControlTabIcon; import binnie.core.gui.window.Panel; import binnie.core.util.I18N; +import binnie.core.util.EmptyHelper; import binnie.core.gui.ControlGenesisOption; import net.minecraftforge.fml.relauncher.SideOnly; @@ -98,9 +99,9 @@ public void initialiseClient() { } Gene gene = (Gene) value; Map> map = Binnie.GENETICS.getChromosomeMap(root); - List options = new ArrayList<>(); IChromosomeType chromosomeType = gene.getChromosome(); List alleles = map.get(chromosomeType); + List options = new ArrayList<>(alleles.size()); for (IAllele allele : alleles) { options.add(new Gene(allele, chromosomeType, root)); } @@ -127,8 +128,8 @@ public void initialiseClient() { } private void refreshTemplate(@Nullable IChromosomeType selection) { - List genes = new ArrayList<>(); - IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]); + IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(EmptyHelper.CHROMOSOME_TYPES_EMPTY); + List genes = new ArrayList<>(chromosomeTypes.length); for (IChromosomeType type : chromosomeTypes) { IAllele allele = this.template[type.ordinal()]; if (allele == null) { @@ -170,11 +171,11 @@ public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, super.receiveGuiNBTOnServer(player, name, nbt); if (name.equals(ACTION_GENESIS)) { ItemStack stack = new ItemStack(nbt); - InventoryPlayer inventoryPlayer = player.inventory; - ItemStack playerStack = inventoryPlayer.getItemStack(); if (stack.isEmpty()) { return; } + InventoryPlayer inventoryPlayer = player.inventory; + ItemStack playerStack = inventoryPlayer.getItemStack(); if (playerStack.isEmpty()) { inventoryPlayer.setItemStack(stack); } else if (playerStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(playerStack, stack)) { diff --git a/core/src/main/java/binnie/core/gui/minecraft/ContainerCraftGUI.java b/core/src/main/java/binnie/core/gui/minecraft/ContainerCraftGUI.java index aad4e0a48..82fe1f3a6 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/ContainerCraftGUI.java +++ b/core/src/main/java/binnie/core/gui/minecraft/ContainerCraftGUI.java @@ -25,6 +25,7 @@ import binnie.core.machines.transfer.TransferRequest; import binnie.core.machines.transfer.TransferResult; import binnie.core.network.packet.MessageContainerUpdate; +import binnie.core.util.EmptyHelper; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import com.mojang.authlib.GameProfile; @@ -91,13 +92,14 @@ public void onContainerClosed(final EntityPlayer playerIn) { for (int i = 0; i < inventory.getSizeInventory(); ++i) { if (inventory.dispenseOnClose(i)) { ItemStack stack = inventory.getStackInSlot(i); - if (!stack.isEmpty()) { - TransferRequest transferRequest = new TransferRequest(stack, playerIn.inventory); - TransferResult transferResult = transferRequest.transfer(playerIn, true); - if (transferResult.isSuccess()) { - for (ItemStack result : transferResult.getRemaining()) { - playerIn.dropItem(result, false); - } + if (stack.isEmpty()) { + continue; + } + TransferRequest transferRequest = new TransferRequest(stack, playerIn.inventory); + TransferResult transferResult = transferRequest.transfer(playerIn, true); + if (transferResult.isSuccess()) { + for (ItemStack result : transferResult.getRemaining()) { + playerIn.dropItem(result, false); } } } @@ -166,7 +168,7 @@ private TransferRequest getShiftClickRequest(final EntityPlayer player, final in request = new TransferRequest(itemstack, fromPlayer).setOrigin(shiftClickedSlot.inventory); } else { final int[] target = new int[36]; - for (int i = 0; i < 36; ++i) { + for (int i = 0; i < target.length; ++i) { target[i] = i; } request = new TransferRequest(itemstack, playerInventory).setOrigin(shiftClickedSlot.inventory).setTargetSlots(target); @@ -244,7 +246,7 @@ public boolean handleNBTClient(final EntityPlayer player, final String name, fin @Override public void detectAndSendChanges() { super.detectAndSendChanges(); - if (crafters.size() <= 0) { + if (crafters.isEmpty()) { return; } sendTankChanges(); @@ -390,7 +392,7 @@ public CustomSlot[] getCustomSlots() { slots.add((CustomSlot) object); } } - return slots.toArray(new CustomSlot[0]); + return slots.toArray(EmptyHelper.CUSTOM_SLOTS_EMPTY); } @SideOnly(Side.CLIENT) diff --git a/core/src/main/java/binnie/core/gui/minecraft/CustomSlot.java b/core/src/main/java/binnie/core/gui/minecraft/CustomSlot.java index 44ca25c9c..05036fd9d 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/CustomSlot.java +++ b/core/src/main/java/binnie/core/gui/minecraft/CustomSlot.java @@ -40,14 +40,13 @@ public boolean handleClick() { public void onSlotClick(final ContainerCraftGUI container, final int dragType, final ClickType modifier, final EntityPlayer player) { InventoryPlayer inventory = player.inventory; ItemStack stack = inventory.getItemStack(); - ItemStack slotStack = getStack().copy(); //TODO modifier==mouseButton2? if (stack.isEmpty() || modifier == ClickType.PICKUP_ALL) { this.putStack(ItemStack.EMPTY); }else { - stack = stack.copy(); - stack.setCount(1); - this.putStack(stack); + ItemStack slotStack = stack.copy(); + slotStack.setCount(1); + this.putStack(slotStack); } } } diff --git a/core/src/main/java/binnie/core/gui/minecraft/GuiCraftGUI.java b/core/src/main/java/binnie/core/gui/minecraft/GuiCraftGUI.java index aec5a9fcb..6b9e2e4f7 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/GuiCraftGUI.java +++ b/core/src/main/java/binnie/core/gui/minecraft/GuiCraftGUI.java @@ -11,7 +11,6 @@ import binnie.core.gui.KeyBindings; import binnie.core.gui.geometry.Point; import binnie.core.util.Log; -import binnie.core.util.EmptyHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; @@ -29,6 +28,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; @@ -141,7 +141,7 @@ public void renderTooltip(final Point mousePosition, final MinecraftTooltip tool boolean containsItemRender = false; - List textLines = new ArrayList<>(); + List textLines = new ArrayList<>(tooltip.getList().size()); for (final String string : tooltip.getList()) { if (string != null) { if (!string.contains(Tooltip.NBT_SEPARATOR)) { @@ -156,7 +156,7 @@ public void renderTooltip(final Point mousePosition, final MinecraftTooltip tool for (String textLine : textLines) { int textLineWidth = font.getStringWidth(textLine); if (textLine.contains(Tooltip.NBT_SEPARATOR)) { - textLineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(EmptyHelper.EMPTY_STRING)); + textLineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(StringUtils.EMPTY)); } if (textLineWidth > tooltipTextWidth) { tooltipTextWidth = textLineWidth; @@ -200,7 +200,7 @@ private void drawHoveringText(@Nonnull ItemStack itemStack, List textLin if (needsWrap) { int wrappedTooltipWidth = 0; - List wrappedTextLines = new ArrayList<>(); + List wrappedTextLines = new ArrayList<>(textLines.size()); for (int i = 0; i < textLines.size(); i++) { String textLine = textLines.get(i); List wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); @@ -211,7 +211,7 @@ private void drawHoveringText(@Nonnull ItemStack itemStack, List textLin for (String line : wrappedLine) { int lineWidth = font.getStringWidth(line); if (textLine.contains(Tooltip.NBT_SEPARATOR)) { - lineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(EmptyHelper.EMPTY_STRING)); + lineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(StringUtils.EMPTY)); } if (lineWidth > wrappedTooltipWidth) { wrappedTooltipWidth = lineWidth; @@ -266,7 +266,7 @@ private void drawHoveringText(@Nonnull ItemStack itemStack, List textLin } if (line.contains(Tooltip.NBT_SEPARATOR)) { drawItem(line, tooltipX, tooltipY); - line = " " + PATTERN_NBT_CONTENT.matcher(line).replaceAll(EmptyHelper.EMPTY_STRING); + line = " " + PATTERN_NBT_CONTENT.matcher(line).replaceAll(StringUtils.EMPTY); } font.drawStringWithShadow(line, tooltipX, tooltipY, -1); if (lineNumber + 1 == titleLinesCount) { diff --git a/core/src/main/java/binnie/core/gui/minecraft/Window.java b/core/src/main/java/binnie/core/gui/minecraft/Window.java index e92f6bd93..9054a781a 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/Window.java +++ b/core/src/main/java/binnie/core/gui/minecraft/Window.java @@ -50,6 +50,7 @@ import binnie.core.resource.BinnieResource; import binnie.core.resource.IBinnieTexture; import binnie.core.resource.ResourceType; +import org.apache.commons.lang3.StringUtils; public abstract class Window extends TopLevelWidget implements INetwork.ReceiveGuiNBT { private final Side side; @@ -272,7 +273,7 @@ public boolean isClient() { } public World getWorld() { - return this.getPlayer().world; + return this.player.world; } public void sendClientAction(final String name, final NBTTagCompound action) { @@ -329,7 +330,7 @@ public BackgroundTexture(Window window, int i) { @Override @SideOnly(Side.CLIENT) public BinnieResource getTexture() { - return Binnie.RESOURCE.getPNG(window.getModId(), ResourceType.GUI, window.getBackgroundTextureName() + ((i == 1) ? "" : i)); + return Binnie.RESOURCE.getPNG(window.getModId(), ResourceType.GUI, window.getBackgroundTextureName() + ((i == 1) ? StringUtils.EMPTY : i)); } } } diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlEnergyBar.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlEnergyBar.java index 25758fe20..e8ad78c51 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlEnergyBar.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlEnergyBar.java @@ -1,6 +1,7 @@ package binnie.core.gui.minecraft.control; import java.text.NumberFormat; +import java.util.regex.Pattern; import binnie.core.ModId; import binnie.core.api.gui.Alignment; @@ -63,6 +64,9 @@ public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { tooltip.add(energyString); } + private static final Pattern PATTERN_MAX = Pattern.compile("$MAX$", Pattern.LITERAL); + private static final Pattern PATTERN_PERCENT = Pattern.compile("$PERCENT$", Pattern.LITERAL); + @Override @SideOnly(Side.CLIENT) public void getHelpTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { @@ -70,8 +74,8 @@ public void getHelpTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { if (tooltipFlag.isAdvanced()) { String currentFormat = I18N.localise(ModId.CORE, "gui.energy.amount.current"); NumberFormat numberFormat = I18N.getNumberFormat(); - String currentString = currentFormat.replace("$MAX$", numberFormat.format(this.getStoredEnergy())) - .replace("$PERCENT$", I18N.getPercentFormat().format(this.getPercentage() / 100.0)); + String currentString = PATTERN_MAX.matcher(currentFormat).replaceAll(numberFormat.format(this.getStoredEnergy())); + currentString = PATTERN_PERCENT.matcher(currentString).replaceAll(I18N.getPercentFormat().format(this.getPercentage() / 100.0)); tooltip.add(TextFormatting.GRAY + currentString); String maxEnergy = numberFormat.format(this.getMaxEnergy()); tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.energy.capacity", maxEnergy)); diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlErrorState.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlErrorState.java index a4b2c04b0..c54dfc840 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlErrorState.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlErrorState.java @@ -36,11 +36,13 @@ public ControlErrorState(final IWidget parent, final int x, final int y) { @Override @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { - Object texture = CraftGUITexture.STATE_WARNING; + Object texture; if (this.errorState == null) { texture = CraftGUITexture.STATE_NONE; } else if (this.type == 0) { texture = CraftGUITexture.STATE_ERROR; + } else { + texture = CraftGUITexture.STATE_WARNING; } CraftGUI.RENDER.texture(texture, Point.ZERO); super.onRenderBackground(guiWidth, guiHeight); diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlLiquidTank.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlLiquidTank.java index 5c66ab3d5..5e3422498 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlLiquidTank.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlLiquidTank.java @@ -65,7 +65,7 @@ public ControlLiquidTank(IWidget parent, int x, int y, int tankID, boolean horiz if (event.getButton() == 0) { final NBTTagCompound nbt = new NBTTagCompound(); nbt.setByte("id", (byte) ControlLiquidTank.this.tankID); - Window.get(ControlLiquidTank.this.getWidget()).sendClientAction("tank-click", nbt); + Window.get(ControlLiquidTank.this).sendClientAction("tank-click", nbt); } }); } @@ -193,7 +193,7 @@ public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { tooltip.add(I18N.localise(ModId.CORE, "gui.tank.amount", tankAmount)); return; } - tooltip.add("Empty"); + tooltip.add(I18N.localise(ModId.CORE, "gui.tank.empty")); } @Nullable diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlPlayerInventory.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlPlayerInventory.java index 17b129694..a2cdd44ca 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlPlayerInventory.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlPlayerInventory.java @@ -15,20 +15,24 @@ public class ControlPlayerInventory extends Control { public ControlPlayerInventory(final IWidget parent, final boolean wide) { super(parent, parent.getSize().xPos() / 2 - (wide ? 110 : 81), parent.getSize().yPos() - (wide ? 54 : 76) - 12, wide ? 220 : 162, wide ? 54 : 76); - this.slots = new ArrayList<>(); - for (int row = 0; row < 3; ++row) { - for (int column = 0; column < 9; ++column) { - final ControlSlot slot = new ControlSlot.Builder(this, (wide ? 58 : 0) + column * 18, row * 18).assign(InventoryType.PLAYER, 9 + column + row * 9); + final int firstRowColumn = 9; + final int rowCount = 3; + final int columnCount = 9; + this.slots = new ArrayList<>(firstRowColumn + rowCount*columnCount); + for (int row = 0; row < rowCount; ++row) { + for (int column = 0; column < columnCount; ++column) { + final ControlSlot slot = new ControlSlot.Builder(this, (wide ? 58 : 0) + column * 18, row * 18) + .assign(InventoryType.PLAYER, firstRowColumn + column + row * columnCount); this.slots.add(slot); } } if (wide) { - for (int i1 = 0; i1 < 9; ++i1) { + for (int i1 = 0; i1 < firstRowColumn; ++i1) { final ControlSlot slot2 = new ControlSlot.Builder(this, i1 % 3 * 18, i1 / 3 * 18).assign(InventoryType.PLAYER, i1); this.slots.add(slot2); } } else { - for (int i1 = 0; i1 < 9; ++i1) { + for (int i1 = 0; i1 < firstRowColumn; ++i1) { final ControlSlot slot2 = new ControlSlot.Builder(this, i1 * 18, 58).assign(InventoryType.PLAYER, i1); this.slots.add(slot2); } @@ -41,10 +45,13 @@ public ControlPlayerInventory(final IWidget parent) { public ControlPlayerInventory(final IWidget parent, final int x, final int y) { super(parent, x, y, 54, 220); + final int rowCount = 6; + final int columnCount = 6; this.slots = new ArrayList<>(); - for (int row = 0; row < 6; ++row) { - for (int column = 0; column < 6; ++column) { - final ControlSlot slot = new ControlSlot.Builder(this, column * 18, row * 18).assign(InventoryType.PLAYER,column + row * 6); + for (int row = 0; row < rowCount; ++row) { + for (int column = 0; column < columnCount; ++column) { + final ControlSlot slot = new ControlSlot.Builder(this, column * 18, row * 18) + .assign(InventoryType.PLAYER,column + row * columnCount); this.slots.add(slot); } } diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlProgressBase.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlProgressBase.java index f9c2ee924..3f2020145 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlProgressBase.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlProgressBase.java @@ -33,17 +33,25 @@ public static String convertTime(final int time) { ++minutes; seconds -= 60; } - String ts = ""; + StringBuilder stringBuilder = new StringBuilder(); if (minutes > 0) { - ts = ts + minutes + " minute" + ((minutes == 1) ? "" : "s"); + if (minutes == 1) { + stringBuilder.append(I18N.localise(ModId.CORE, "gui.progress.time.minute", minutes)); + } else { + stringBuilder.append(I18N.localise(ModId.CORE, "gui.progress.time.minutes", minutes)); + } } if (seconds > 0) { - if (ts.length() > 0) { - ts += " "; + if (stringBuilder.length() > 0) { + stringBuilder.append(' '); + } + if (seconds == 1) { + stringBuilder.append(I18N.localise(ModId.CORE, "gui.progress.time.second", seconds)); + } else { + stringBuilder.append(I18N.localise(ModId.CORE, "gui.progress.time.seconds", seconds)); } - ts = ts + seconds + " second" + ((seconds == 1) ? "" : "s"); } - return ts; + return stringBuilder.toString(); } public void setProgress(final float progress) { diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlide.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlide.java index 3f6b3f615..149a4cedf 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlide.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlide.java @@ -20,12 +20,14 @@ import binnie.core.gui.renderer.RenderUtil; import binnie.core.gui.resource.textures.CraftGUITexture; +import javax.annotation.Nullable; + public class ControlSlide extends Control { private final IArea expanded; private final IArea shrunk; private boolean slideActive; private final Alignment anchor; - private String label; + private @Nullable String label; public ControlSlide(final IWidget parent, final int x, final int y, final int w, final int h, final Alignment anchor2) { super(parent, x, y, w, h); diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlot.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlot.java index 9bb6f44b5..bdcf84da0 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlot.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlSlot.java @@ -65,7 +65,7 @@ public ControlSlot(final IWidget parent, final int x, final int y, final Slot sl final int windowId = superParent.getContainer().windowId; final int slotNumber = this.slot.slotNumber; final int button = event.getButton(); - Window.get(this.getWidget()).getGui(); + Window.get(this).getGui(); if (playerController != null) { boolean clone = mc.gameSettings.keyBindPickBlock.isActiveAndMatches(button - 100); ClickType clickType; @@ -208,7 +208,8 @@ public void getHelpTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { } else if (this.slot.inventory instanceof WindowInventory) { if (tooltipFlag.isAdvanced()) { final SlotValidator s = ((WindowInventory) this.slot.inventory).getValidator(this.slot.getSlotIndex()); - tooltip.add("Accepts: " + ((s == null) ? "Any Item" : s.getTooltip())); + final String itemDescription = (s == null) ? I18N.localise(ModId.CORE, "gui.slot.window.inventory.any") : s.getTooltip(); + tooltip.add(I18N.localise(ModId.CORE, "gui.slot.window.inventory", itemDescription)); } } else if (this.slot.inventory instanceof InventoryPlayer) { if (tooltipFlag.isAdvanced()) { diff --git a/core/src/main/java/binnie/core/gui/minecraft/control/ControlUser.java b/core/src/main/java/binnie/core/gui/minecraft/control/ControlUser.java index a80b34bad..957e2754d 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/control/ControlUser.java +++ b/core/src/main/java/binnie/core/gui/minecraft/control/ControlUser.java @@ -13,6 +13,9 @@ import binnie.core.gui.Tooltip; import binnie.core.gui.controls.core.Control; import binnie.core.gui.resource.textures.CraftGUITexture; +import binnie.core.ModId; +import binnie.core.util.I18N; +import org.apache.commons.lang3.StringUtils; public class ControlUser extends Control implements ITooltip { private final String username; @@ -32,8 +35,8 @@ public void onRenderBackground(int guiWidth, int guiHeight) { @Override public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { tooltip.setType(Tooltip.Type.USER); - tooltip.add("Owner"); - if (!Objects.equals(this.username, "")) { + tooltip.add(I18N.localise(ModId.CORE, "gui.controluser.owner")); + if (!Objects.equals(this.username, StringUtils.EMPTY)) { tooltip.add(this.username); } tooltip.setMaxWidth(200); diff --git a/core/src/main/java/binnie/core/gui/renderer/RenderUtil.java b/core/src/main/java/binnie/core/gui/renderer/RenderUtil.java index cb60865bf..877c96d2d 100644 --- a/core/src/main/java/binnie/core/gui/renderer/RenderUtil.java +++ b/core/src/main/java/binnie/core/gui/renderer/RenderUtil.java @@ -92,8 +92,8 @@ public static void drawTexture(double xCoord, double yCoord, TextureAtlasSprite double uMax = textureSprite.getMaxU(); double vMin = textureSprite.getMinV(); double vMax = textureSprite.getMaxV(); - uMax = uMax - maskRight / 16.0 * (uMax - uMin); - vMax = vMax - maskTop / 16.0 * (vMax - vMin); + uMax -= maskRight / 16.0 * (uMax - uMin); + vMax -= maskTop / 16.0 * (vMax - vMin); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); diff --git a/core/src/main/java/binnie/core/integration/extrabees/ExtraBeesIntegration.java b/core/src/main/java/binnie/core/integration/extrabees/ExtraBeesIntegration.java index 48ab91860..118283490 100644 --- a/core/src/main/java/binnie/core/integration/extrabees/ExtraBeesIntegration.java +++ b/core/src/main/java/binnie/core/integration/extrabees/ExtraBeesIntegration.java @@ -13,6 +13,7 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; +import binnie.core.Constants; import binnie.core.IInitializable; public class ExtraBeesIntegration implements IInitializable { @@ -25,7 +26,7 @@ public class ExtraBeesIntegration implements IInitializable { private static Block hive; static { - loaded = Loader.isModLoaded("extrabees"); + loaded = Loader.isModLoaded(Constants.EXTRA_BEES_MOD_ID); } public static boolean isLoaded() { @@ -39,7 +40,7 @@ public void preInit() { @Override public void init() { - hive = Preconditions.checkNotNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation("extrabees", "hive"))); + hive = Preconditions.checkNotNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Constants.EXTRA_BEES_MOD_ID, "hive"))); } @Override diff --git a/core/src/main/java/binnie/core/item/ItemFieldKit.java b/core/src/main/java/binnie/core/item/ItemFieldKit.java index aef41cb34..886b9b3ff 100644 --- a/core/src/main/java/binnie/core/item/ItemFieldKit.java +++ b/core/src/main/java/binnie/core/item/ItemFieldKit.java @@ -32,7 +32,6 @@ public class ItemFieldKit extends ItemCore { public ItemFieldKit() { super("field_kit"); - this.setUnlocalizedName("field_kit"); this.setCreativeTab(CreativeTabs.TOOLS); this.setMaxStackSize(1); this.setMaxDamage(64); diff --git a/core/src/main/java/binnie/core/item/ItemGenesis.java b/core/src/main/java/binnie/core/item/ItemGenesis.java index 414d85eb4..c8c6f42c9 100644 --- a/core/src/main/java/binnie/core/item/ItemGenesis.java +++ b/core/src/main/java/binnie/core/item/ItemGenesis.java @@ -18,7 +18,6 @@ public class ItemGenesis extends ItemCore implements IGuiItem { public ItemGenesis() { super("genesis"); this.setCreativeTab(Tabs.tabApiculture); - this.setUnlocalizedName("genesis"); this.setMaxStackSize(1); } diff --git a/core/src/main/java/binnie/core/item/ItemMisc.java b/core/src/main/java/binnie/core/item/ItemMisc.java index 86cc9ed7f..3d8e66ee5 100644 --- a/core/src/main/java/binnie/core/item/ItemMisc.java +++ b/core/src/main/java/binnie/core/item/ItemMisc.java @@ -22,7 +22,6 @@ public ItemMisc(final CreativeTabs tab, final IItemMiscProvider[] items, String super(name); this.setCreativeTab(tab); this.setHasSubtypes(true); - this.setUnlocalizedName(name); this.items = items; } diff --git a/core/src/main/java/binnie/core/item/ModuleItems.java b/core/src/main/java/binnie/core/item/ModuleItems.java index 7e491070b..e39ca2247 100644 --- a/core/src/main/java/binnie/core/item/ModuleItems.java +++ b/core/src/main/java/binnie/core/item/ModuleItems.java @@ -1,6 +1,7 @@ package binnie.core.item; import binnie.core.Constants; +import binnie.core.proxy.BinnieProxy; import binnie.core.util.RecipeUtil; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -12,10 +13,11 @@ public class ModuleItems implements IInitializable { @Override public void preInit() { + final BinnieProxy proxy = BinnieCore.getBinnieProxy(); BinnieCore.setFieldKit(new ItemFieldKit()); - BinnieCore.getBinnieProxy().registerItem(BinnieCore.getFieldKit()); + proxy.registerItem(BinnieCore.getFieldKit()); BinnieCore.setGenesis(new ItemGenesis()); - BinnieCore.getBinnieProxy().registerItem(BinnieCore.getGenesis()); + proxy.registerItem(BinnieCore.getGenesis()); } @Override diff --git a/core/src/main/java/binnie/core/liquid/FluidContainerType.java b/core/src/main/java/binnie/core/liquid/FluidContainerType.java index 8281452a1..eb5bf28f7 100644 --- a/core/src/main/java/binnie/core/liquid/FluidContainerType.java +++ b/core/src/main/java/binnie/core/liquid/FluidContainerType.java @@ -10,6 +10,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler; import binnie.core.Mods; +import binnie.core.ModId; import binnie.core.util.I18N; public enum FluidContainerType { @@ -35,7 +36,7 @@ public String getName() { } public String getDisplayName() { - return I18N.localise("binniecore.item.container." + this.name().toLowerCase()); + return I18N.localise( ModId.CORE, "item.container." + this.getName()); } public void setItem(ItemFluidContainer item) { @@ -76,7 +77,6 @@ public ItemStack getEmpty() { public ItemStack getFilled(Fluid fluid) { ItemStack stack = getEmpty(); - stack = stack.copy(); IFluidHandler fluidHandler = FluidUtil.getFluidHandler(stack); if (fluidHandler != null) { int fill = fluidHandler.fill(new FluidStack(fluid, Integer.MAX_VALUE), true); diff --git a/core/src/main/java/binnie/core/liquid/FluidHandlerItemBinnie.java b/core/src/main/java/binnie/core/liquid/FluidHandlerItemBinnie.java index 6d80e00e4..42d060935 100644 --- a/core/src/main/java/binnie/core/liquid/FluidHandlerItemBinnie.java +++ b/core/src/main/java/binnie/core/liquid/FluidHandlerItemBinnie.java @@ -6,6 +6,8 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStackSimple; +import javax.annotation.Nullable; + public class FluidHandlerItemBinnie extends FluidHandlerItemStackSimple { private final FluidContainerType containerType; @@ -14,7 +16,7 @@ public class FluidHandlerItemBinnie extends FluidHandlerItemStackSimple { this.containerType = containerType; } - private boolean contentsAllowed(FluidStack fluidStack) { + private boolean contentsAllowed(@Nullable FluidStack fluidStack) { if (fluidStack == null) { return false; } @@ -33,12 +35,12 @@ private boolean contentsAllowed(FluidStack fluidStack) { } @Override - public boolean canFillFluidType(FluidStack fluid) { + public boolean canFillFluidType(@Nullable FluidStack fluid) { return contentsAllowed(fluid); } @Override - public boolean canDrainFluidType(FluidStack fluid) { + public boolean canDrainFluidType(@Nullable FluidStack fluid) { return contentsAllowed(fluid); } diff --git a/core/src/main/java/binnie/core/liquid/ItemFluidContainer.java b/core/src/main/java/binnie/core/liquid/ItemFluidContainer.java index 732d5d20d..d192207b3 100644 --- a/core/src/main/java/binnie/core/liquid/ItemFluidContainer.java +++ b/core/src/main/java/binnie/core/liquid/ItemFluidContainer.java @@ -34,6 +34,8 @@ import forestry.api.core.IModelManager; import binnie.core.Binnie; +import binnie.core.ModId; +import binnie.core.util.I18N; public class ItemFluidContainer extends ItemFood implements IItemModelRegister { private final FluidContainerType container; @@ -53,7 +55,7 @@ public ItemFluidContainer(FluidContainerType container) { public String getItemStackDisplayName(final ItemStack itemstack) { FluidStack fluid = getContained(itemstack); if (fluid == null) { - return "Empty " + container.getDisplayName(); + return I18N.localise(ModId.CORE, "item.container.empty", container.getDisplayName()); } return fluid.getFluid().getLocalizedName(fluid) + ' ' + this.container.getDisplayName(); } diff --git a/core/src/main/java/binnie/core/liquid/ManagerLiquid.java b/core/src/main/java/binnie/core/liquid/ManagerLiquid.java index becc8759f..b4e17eb76 100644 --- a/core/src/main/java/binnie/core/liquid/ManagerLiquid.java +++ b/core/src/main/java/binnie/core/liquid/ManagerLiquid.java @@ -39,19 +39,16 @@ public ManagerLiquid() { public void createLiquids(IFluidDefinition[] liquids) { for (IFluidDefinition liquid : liquids) { FluidType type = liquid.getType(); - final BinnieFluid fluid = this.createLiquid(type); - if (fluid == null) { - Log.error("Liquid registered incorrectly - {} ", type.getIdentifier()); - } + this.createLiquid(type); } } - private BinnieFluid createLiquid(FluidType fluid) { + private void createLiquid(FluidType fluid) { this.fluids.put(fluid.getIdentifier().toLowerCase(), fluid); - final BinnieFluid bFluid = new BinnieFluid(fluid); - FluidRegistry.registerFluid(bFluid); - FluidRegistry.addBucketForFluid(bFluid); - return bFluid; + BinnieFluid bFluid = new BinnieFluid(fluid); + if ((!FluidRegistry.registerFluid(bFluid)) || (FluidRegistry.addBucketForFluid(bFluid))) { + Log.error("Liquid registered incorrectly - {} ", fluid.getIdentifier()); + } } @Nullable diff --git a/core/src/main/java/binnie/core/machines/MachineComponent.java b/core/src/main/java/binnie/core/machines/MachineComponent.java index 333fb170d..d5312d815 100644 --- a/core/src/main/java/binnie/core/machines/MachineComponent.java +++ b/core/src/main/java/binnie/core/machines/MachineComponent.java @@ -1,5 +1,6 @@ package binnie.core.machines; +import binnie.core.util.EmptyHelper; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; @@ -39,7 +40,7 @@ public void onUpdate() { public Class[] getComponentInterfaces() { Class[] componentInterfaces = Binnie.MACHINE.getComponentInterfaces(this.getClass()); if (componentInterfaces == null) { - return new Class[0]; + return EmptyHelper.CLASS_ARRAY_EMPTY; } return componentInterfaces; } diff --git a/core/src/main/java/binnie/core/machines/ManagerMachine.java b/core/src/main/java/binnie/core/machines/ManagerMachine.java index 76cecb178..6ab5168ae 100644 --- a/core/src/main/java/binnie/core/machines/ManagerMachine.java +++ b/core/src/main/java/binnie/core/machines/ManagerMachine.java @@ -17,6 +17,7 @@ import binnie.core.machines.inventory.ValidatorSprite; import binnie.core.machines.render.RenderTESRMachine; import binnie.core.proxy.IBinnieProxy; +import binnie.core.util.EmptyHelper; import forestry.api.core.INbtReadable; import forestry.api.core.INbtWritable; @@ -74,7 +75,7 @@ private void registerComponentClass(final Class comp } interfaces.remove(INbtWritable.class); interfaces.remove(INbtReadable.class); - this.componentInterfaceMap.put(component, interfaces.toArray(new Class[0])); + this.componentInterfaceMap.put(component, interfaces.toArray(EmptyHelper.CLASS_ARRAY_EMPTY)); final int networkID = this.nextNetworkID++; } diff --git a/core/src/main/java/binnie/core/machines/base/DefaultInventory.java b/core/src/main/java/binnie/core/machines/base/DefaultInventory.java index 38182de6d..2b68cd65b 100644 --- a/core/src/main/java/binnie/core/machines/base/DefaultInventory.java +++ b/core/src/main/java/binnie/core/machines/base/DefaultInventory.java @@ -6,6 +6,8 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; +import org.apache.commons.lang3.StringUtils; + class DefaultInventory implements IInventory { @Override public int getSizeInventory() { @@ -88,7 +90,7 @@ public void clear() { @Override public String getName() { - return ""; + return StringUtils.EMPTY; } @Override @@ -98,6 +100,6 @@ public boolean hasCustomName() { @Override public ITextComponent getDisplayName() { - return new TextComponentString(""); + return new TextComponentString(StringUtils.EMPTY); } } diff --git a/core/src/main/java/binnie/core/machines/base/DefaultMachineInventory.java b/core/src/main/java/binnie/core/machines/base/DefaultMachineInventory.java index 126a87a25..4d880afad 100644 --- a/core/src/main/java/binnie/core/machines/base/DefaultMachineInventory.java +++ b/core/src/main/java/binnie/core/machines/base/DefaultMachineInventory.java @@ -8,6 +8,7 @@ import net.minecraft.util.text.TextComponentString; import binnie.core.machines.inventory.IInventoryMachine; +import binnie.core.util.EmptyHelper; class DefaultMachineInventory implements IInventoryMachine { private final DefaultInventory inventory; @@ -32,7 +33,7 @@ public void markDirty() { @Override public int[] getSlotsForFace(EnumFacing side) { - return new int[0]; + return EmptyHelper.INT_ARRAY_EMPTY; } @Override diff --git a/core/src/main/java/binnie/core/machines/base/DefaultTankContainer.java b/core/src/main/java/binnie/core/machines/base/DefaultTankContainer.java index a56b2441b..cc00b17a5 100644 --- a/core/src/main/java/binnie/core/machines/base/DefaultTankContainer.java +++ b/core/src/main/java/binnie/core/machines/base/DefaultTankContainer.java @@ -2,6 +2,7 @@ import javax.annotation.Nullable; +import binnie.core.util.EmptyHelper; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; @@ -14,9 +15,10 @@ import binnie.core.machines.power.TankInfo; class DefaultTankContainer implements ITankMachine { + @Override public TankInfo[] getTankInfos() { - return new TankInfo[0]; + return EmptyHelper.TANK_INFO_EMPTY; } @Override @@ -63,6 +65,6 @@ public IFluidHandler getHandler(int[] targetTanks) { @Override public IFluidTank[] getTanks() { - return new IFluidTank[0]; + return EmptyHelper.FLUID_TANKS_EMPTY; } } diff --git a/core/src/main/java/binnie/core/machines/errors/ErrorState.java b/core/src/main/java/binnie/core/machines/errors/ErrorState.java index 7372b0d53..ad99ef276 100644 --- a/core/src/main/java/binnie/core/machines/errors/ErrorState.java +++ b/core/src/main/java/binnie/core/machines/errors/ErrorState.java @@ -10,6 +10,7 @@ import binnie.core.machines.inventory.InventorySlot; import binnie.core.machines.inventory.SlotValidator; import binnie.core.machines.inventory.Validator; +import binnie.core.util.EmptyHelper; import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntSet; import net.minecraft.entity.player.InventoryPlayer; @@ -41,7 +42,7 @@ public ErrorState(IErrorStateDefinition definition, int data) { } public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition) { - this(nameDefinition, definition, new int[0]); + this(nameDefinition, definition, EmptyHelper.INT_ARRAY_EMPTY); } public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, int[] data) { @@ -55,7 +56,7 @@ public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition de } public ErrorState(NBTTagCompound nbtTagCompound) { - this.data = new int[0]; + this.data = EmptyHelper.INT_ARRAY_EMPTY; this.itemError = false; this.tankError = false; this.powerError = false; diff --git a/core/src/main/java/binnie/core/machines/inventory/BaseSlot.java b/core/src/main/java/binnie/core/machines/inventory/BaseSlot.java index 6c39dd987..ffbfce401 100644 --- a/core/src/main/java/binnie/core/machines/inventory/BaseSlot.java +++ b/core/src/main/java/binnie/core/machines/inventory/BaseSlot.java @@ -20,7 +20,7 @@ public abstract class BaseSlot implements INbtWritable, INbtReadable, IValida private boolean readOnly; private int index; - public BaseSlot(final int index, final ResourceLocation unlocLocation) { + public BaseSlot(final int index, @Nullable final ResourceLocation unlocLocation) { this.access = new SidedAccess(); this.setIndex(index); this.unlocLocation = unlocLocation; @@ -91,12 +91,6 @@ public Collection getOutputSides() { return this.access.getExtractionSides(); } - public void setOutputSides(final EnumSet sides) { - for (final EnumFacing side : EnumSet.complementOf(sides)) { - this.access.setExtract(side, false); - } - } - public abstract String getName(); @Nullable diff --git a/core/src/main/java/binnie/core/machines/inventory/ComponentInventorySlots.java b/core/src/main/java/binnie/core/machines/inventory/ComponentInventorySlots.java index 4d8aca1de..fb19bc988 100644 --- a/core/src/main/java/binnie/core/machines/inventory/ComponentInventorySlots.java +++ b/core/src/main/java/binnie/core/machines/inventory/ComponentInventorySlots.java @@ -1,5 +1,7 @@ package binnie.core.machines.inventory; +import org.apache.commons.lang3.StringUtils; + import javax.annotation.Nullable; import java.util.Arrays; import java.util.LinkedHashMap; @@ -105,12 +107,7 @@ public void readFromNBT(final NBTTagCompound compound) { @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound = super.writeToNBT(compound); - NBTUtil.writeToList(compound, INVENTORY_KEY, inventory, (index, slot) -> { - NBTTagCompound slotTag = new NBTTagCompound(); - slotTag.setInteger(INDEX_KEY, index); - slot.writeToNBT(slotTag); - return slotTag; - }); + NBTUtil.writeToList(compound, INVENTORY_KEY, inventory, NBTUtil.writeToListConsumer(INDEX_KEY)); return compound; } @@ -223,7 +220,7 @@ public boolean canExtractItem(final int index, final ItemStack itemstack, final @Override public String getName() { - return ""; + return StringUtils.EMPTY; } @Override diff --git a/core/src/main/java/binnie/core/machines/inventory/ComponentTankContainer.java b/core/src/main/java/binnie/core/machines/inventory/ComponentTankContainer.java index 4f6840c65..a92ee1959 100644 --- a/core/src/main/java/binnie/core/machines/inventory/ComponentTankContainer.java +++ b/core/src/main/java/binnie/core/machines/inventory/ComponentTankContainer.java @@ -22,6 +22,7 @@ import binnie.core.machines.MachineComponent; import binnie.core.machines.power.ITankMachine; import binnie.core.machines.power.TankInfo; +import binnie.core.util.EmptyHelper; import binnie.core.util.NBTUtil; public class ComponentTankContainer extends MachineComponent implements ITankMachine { @@ -85,7 +86,7 @@ private FluidStack drain(final int tankIndex, final int maxDrain, final boolean } @Override - public void readFromNBT(NBTTagCompound compound) { + public void readFromNBT(final NBTTagCompound compound) { super.readFromNBT(compound); NBTUtil.readFromList(compound, TANKS_KEY, (tankNBT)->{ int index = tankNBT.getInteger(TANK_INDEX_KEY); @@ -99,12 +100,7 @@ public void readFromNBT(NBTTagCompound compound) { @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound = super.writeToNBT(compound); - NBTUtil.writeToList(compound, TANKS_KEY, tanks, (index, tank)->{ - NBTTagCompound tankNBT = new NBTTagCompound(); - tankNBT.setInteger(TANK_INDEX_KEY, index); - tank.writeToNBT(tankNBT); - return tankNBT; - }); + NBTUtil.writeToList(compound, TANKS_KEY, tanks, NBTUtil.writeToListConsumer(TANK_INDEX_KEY)); return compound; } @@ -135,7 +131,7 @@ public IFluidTank[] getTanks() { for (final TankSlot tank : this.tanks.values()) { tankList.add(tank.getTank()); } - return tankList.toArray(new IFluidTank[0]); + return tankList.toArray(EmptyHelper.FLUID_TANKS_EMPTY); } @Override @@ -229,10 +225,10 @@ private IFluidTank[] getTanks() { for (final TankSlot tank : this.tanks.values()) { ltanks.add(tank.getTank()); } - return ltanks.toArray(new IFluidTank[0]); + return ltanks.toArray(EmptyHelper.FLUID_TANKS_EMPTY); } - private static int getTankIndexToFill(Map tanks, @Nullable EnumFacing from, final FluidStack resource) { + private static int getTankIndexToFill(Map tanks, @Nullable EnumFacing from, FluidStack resource) { for (final TankSlot tank : tanks.values()) { if (tank.isValid(resource) && tank.canInsert(from) && (tank.getContent() == null || tank.getContent().isFluidEqual(resource))) { return tank.getIndex(); @@ -241,7 +237,7 @@ private static int getTankIndexToFill(Map tanks, @Nullable En return -1; } - private static int getTankIndexToDrain(Map tanks, @Nullable EnumFacing from, @Nullable final FluidStack resource) { + private static int getTankIndexToDrain(Map tanks, @Nullable EnumFacing from, @Nullable FluidStack resource) { for (final TankSlot tank : tanks.values()) { if (tank.getContent() != null && tank.canExtract(from) && (resource == null || resource.isFluidEqual(tank.getContent()))) { return tank.getIndex(); diff --git a/core/src/main/java/binnie/core/machines/inventory/FakeSlot.java b/core/src/main/java/binnie/core/machines/inventory/FakeSlot.java index 4913818d2..c571b835d 100644 --- a/core/src/main/java/binnie/core/machines/inventory/FakeSlot.java +++ b/core/src/main/java/binnie/core/machines/inventory/FakeSlot.java @@ -5,6 +5,7 @@ public final class FakeSlot extends InventorySlot { public static final FakeSlot INSTANCE = new FakeSlot(); + private static final String FAKE_SLOT = "Fake Slot!"; private FakeSlot() { super(0, null); @@ -40,7 +41,7 @@ public ItemStack getItemStack() { @Override public String getName() { - return "Fake Slot!"; + return FAKE_SLOT; } @Override diff --git a/core/src/main/java/binnie/core/machines/inventory/InventorySlot.java b/core/src/main/java/binnie/core/machines/inventory/InventorySlot.java index 1554b72b2..cadae3a49 100644 --- a/core/src/main/java/binnie/core/machines/inventory/InventorySlot.java +++ b/core/src/main/java/binnie/core/machines/inventory/InventorySlot.java @@ -1,6 +1,9 @@ package binnie.core.machines.inventory; +import org.apache.commons.lang3.StringUtils; + import javax.annotation.Nonnull; +import javax.annotation.Nullable; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -13,7 +16,7 @@ public class InventorySlot extends BaseSlot { private ItemStack content; private Type type; - public InventorySlot(final int index, final ResourceLocation unlocLocation) { + public InventorySlot(final int index, @Nullable final ResourceLocation unlocLocation) { super(index, unlocLocation); this.content = ItemStack.EMPTY; this.type = Type.Standard; @@ -96,7 +99,7 @@ public String getName() { return I18N.localise(ModId.CORE, "gui.slot.validated", validator.getTooltip()); } if (this.unlocLocation == null) { - return ""; + return StringUtils.EMPTY; } return I18N.localise(this.unlocLocation); } diff --git a/core/src/main/java/binnie/core/machines/inventory/SlotValidator.java b/core/src/main/java/binnie/core/machines/inventory/SlotValidator.java index 21409c483..f8df70df8 100644 --- a/core/src/main/java/binnie/core/machines/inventory/SlotValidator.java +++ b/core/src/main/java/binnie/core/machines/inventory/SlotValidator.java @@ -2,6 +2,8 @@ import javax.annotation.Nullable; +import binnie.core.ModId; +import binnie.core.util.I18N; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.ItemStack; @@ -56,7 +58,7 @@ public boolean isValid(final ItemStack itemStack) { @Override public String getTooltip() { - return "Breedable Individual"; + return I18N.localise(ModId.CORE, "gui.slotvalidator.individual"); } } } diff --git a/core/src/main/java/binnie/core/machines/inventory/TankSlot.java b/core/src/main/java/binnie/core/machines/inventory/TankSlot.java index 4f76354c3..ca31c2c2c 100644 --- a/core/src/main/java/binnie/core/machines/inventory/TankSlot.java +++ b/core/src/main/java/binnie/core/machines/inventory/TankSlot.java @@ -1,6 +1,7 @@ package binnie.core.machines.inventory; import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; @@ -33,8 +34,9 @@ public void readFromNBT(final NBTTagCompound compound) { @Override public NBTTagCompound writeToNBT(final NBTTagCompound compound) { - if (this.getContent() != null) { - this.getContent().writeToNBT(compound); + final FluidStack fluidStack = this.getContent(); + if (fluidStack != null) { + fluidStack.writeToNBT(compound); } return compound; } @@ -59,7 +61,7 @@ public String getName() { return I18N.localise(ModId.CORE, "gui.tank.validated", validator.getTooltip()); } if (this.unlocLocation == null) { - return ""; + return StringUtils.EMPTY; } return I18N.localise(this.unlocLocation); } diff --git a/core/src/main/java/binnie/core/machines/power/ComponentPowerReceptor.java b/core/src/main/java/binnie/core/machines/power/ComponentPowerReceptor.java index 1a457457a..817d89420 100644 --- a/core/src/main/java/binnie/core/machines/power/ComponentPowerReceptor.java +++ b/core/src/main/java/binnie/core/machines/power/ComponentPowerReceptor.java @@ -21,7 +21,7 @@ //@Optional.Interface(iface = "binnie.core.machines.component.IBuildcraft.TriggerProvider", modid = "BuildCraft|Silicon") public class ComponentPowerReceptor extends MachineComponent implements IPoweredMachine/*, IBuildcraft.TriggerProvider*/, IInteraction.ChunkUnload, IInteraction.Invalidation { - private static final int inputAverageTicks = 20; + private static final int INPUT_AVERAGE_TICKS = 20; private final float previousPower; private final LinkedList inputs; private boolean registeredToIC2EnergyNet; @@ -43,7 +43,7 @@ public ComponentPowerReceptor(final IMachine machine, final int storage) { } public static int getInputAverageTicks() { - return inputAverageTicks; + return INPUT_AVERAGE_TICKS; } @Override diff --git a/core/src/main/java/binnie/core/machines/power/ComponentProcess.java b/core/src/main/java/binnie/core/machines/power/ComponentProcess.java index fcf8995ef..8831969da 100644 --- a/core/src/main/java/binnie/core/machines/power/ComponentProcess.java +++ b/core/src/main/java/binnie/core/machines/power/ComponentProcess.java @@ -68,16 +68,18 @@ public void setProgress(final float f) { protected void onFinishTask() { } + private static final String NBT_KEY_PROGRESS = "progress"; + @Override public void readFromNBT(final NBTTagCompound nbt) { super.readFromNBT(nbt); - this.progressAmount = nbt.getFloat("progress"); + this.progressAmount = nbt.getFloat(NBT_KEY_PROGRESS); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound nbt1) { NBTTagCompound nbt = super.writeToNBT(nbt1); - nbt.setFloat("progress", this.progressAmount); + nbt.setFloat(NBT_KEY_PROGRESS, this.progressAmount); return nbt; } diff --git a/core/src/main/java/binnie/core/machines/power/ITankMachine.java b/core/src/main/java/binnie/core/machines/power/ITankMachine.java index b3212abe2..8924722fa 100644 --- a/core/src/main/java/binnie/core/machines/power/ITankMachine.java +++ b/core/src/main/java/binnie/core/machines/power/ITankMachine.java @@ -20,10 +20,13 @@ public interface ITankMachine extends IValidatedTankContainer { * @deprecated use {@link #addTank(int, ResourceLocation, int)} */ @Deprecated + @Nullable TankSlot addTank(final int index, final String name, final int capacity); + @Nullable TankSlot addTank(final int index, final ResourceLocation name, final int capacity); + @Nullable IFluidTank getTank(final int index); @Nullable diff --git a/core/src/main/java/binnie/core/machines/power/PowerInfo.java b/core/src/main/java/binnie/core/machines/power/PowerInfo.java index 0e503cc44..0822be722 100644 --- a/core/src/main/java/binnie/core/machines/power/PowerInfo.java +++ b/core/src/main/java/binnie/core/machines/power/PowerInfo.java @@ -29,16 +29,19 @@ public int getMaxEnergy() { return (int) this.maxEnergy; } + private static final String NBT_KEY_CURRENT = "current"; + private static final String NBT_KEY_MAX = "max"; + @Override public void readFromNBT(final NBTTagCompound nbttagcompound) { - this.currentEnergy = nbttagcompound.getInteger("current"); - this.maxEnergy = nbttagcompound.getInteger("max"); + this.currentEnergy = nbttagcompound.getInteger(NBT_KEY_CURRENT); + this.maxEnergy = nbttagcompound.getInteger(NBT_KEY_MAX); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound) { - nbttagcompound.setInteger("current", this.getStoredEnergy()); - nbttagcompound.setInteger("max", this.getMaxEnergy()); + nbttagcompound.setInteger(NBT_KEY_CURRENT, this.getStoredEnergy()); + nbttagcompound.setInteger(NBT_KEY_MAX, this.getMaxEnergy()); return nbttagcompound; } } diff --git a/core/src/main/java/binnie/core/machines/power/PowerInterface.java b/core/src/main/java/binnie/core/machines/power/PowerInterface.java index dd618f89b..81877bff7 100644 --- a/core/src/main/java/binnie/core/machines/power/PowerInterface.java +++ b/core/src/main/java/binnie/core/machines/power/PowerInterface.java @@ -62,9 +62,11 @@ public double getEnergySpace(final PowerSystem unit) { return unit.convertTo(this.getEnergySpace()); } + private static final String NBT_KEY_ENERGY = "Energy"; + @Override public void readFromNBT(final NBTTagCompound nbt) { - this.energy = nbt.getInteger("Energy"); + this.energy = nbt.getInteger(NBT_KEY_ENERGY); if (this.energy > this.capacity) { this.energy = this.capacity; } else if (this.energy < 0) { @@ -74,7 +76,7 @@ public void readFromNBT(final NBTTagCompound nbt) { @Override public NBTTagCompound writeToNBT(final NBTTagCompound nbt) { - nbt.setInteger("Energy", this.getEnergy()); + nbt.setInteger(NBT_KEY_ENERGY, this.getEnergy()); return nbt; } } diff --git a/core/src/main/java/binnie/core/machines/power/ProcessInfo.java b/core/src/main/java/binnie/core/machines/power/ProcessInfo.java index 864324d71..6833c0d70 100644 --- a/core/src/main/java/binnie/core/machines/power/ProcessInfo.java +++ b/core/src/main/java/binnie/core/machines/power/ProcessInfo.java @@ -12,10 +12,7 @@ public class ProcessInfo implements INbtReadable, INbtWritable { private float energyPerTick; public ProcessInfo(final IProcess process) { - this.currentProgress = 0.0f; - this.processEnergy = 0; - this.processTime = 0; - this.energyPerTick = 0.0f; + this(); this.energyPerTick = process.getEnergyPerTick(); if (process instanceof IProcessTimed) { final IProcessTimed time = (IProcessTimed) process; @@ -50,20 +47,25 @@ public float getEnergyPerTick() { return this.energyPerTick; } + private static final String NBT_KEY_ENERGY_PER_TICK = "ept"; + private static final String NBT_KEY_PROCESS_ENERGY = "e"; + private static final String NBT_KEY_PROCESS_TIME = "t"; + private static final String NBT_KEY_CURRENT_PROGRESS = "p"; + @Override public void readFromNBT(final NBTTagCompound nbttagcompound) { - this.energyPerTick = nbttagcompound.getFloat("ept"); - this.processEnergy = nbttagcompound.getInteger("e"); - this.processTime = nbttagcompound.getInteger("t"); - this.currentProgress = nbttagcompound.getFloat("p"); + this.energyPerTick = nbttagcompound.getFloat(NBT_KEY_ENERGY_PER_TICK); + this.processEnergy = nbttagcompound.getInteger(NBT_KEY_PROCESS_ENERGY); + this.processTime = nbttagcompound.getInteger(NBT_KEY_PROCESS_TIME); + this.currentProgress = nbttagcompound.getFloat(NBT_KEY_CURRENT_PROGRESS); } @Override public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound) { - nbttagcompound.setFloat("ept", this.energyPerTick); - nbttagcompound.setFloat("p", this.currentProgress); - nbttagcompound.setInteger("e", this.processEnergy); - nbttagcompound.setInteger("t", this.processTime); + nbttagcompound.setFloat(NBT_KEY_ENERGY_PER_TICK, this.energyPerTick); + nbttagcompound.setInteger(NBT_KEY_PROCESS_ENERGY, this.processEnergy); + nbttagcompound.setInteger(NBT_KEY_PROCESS_TIME, this.processTime); + nbttagcompound.setFloat(NBT_KEY_CURRENT_PROGRESS, this.currentProgress); return nbttagcompound; } } diff --git a/core/src/main/java/binnie/core/machines/power/TankInfo.java b/core/src/main/java/binnie/core/machines/power/TankInfo.java index 6e56edf6e..dfd968887 100644 --- a/core/src/main/java/binnie/core/machines/power/TankInfo.java +++ b/core/src/main/java/binnie/core/machines/power/TankInfo.java @@ -1,6 +1,7 @@ package binnie.core.machines.power; import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import net.minecraft.nbt.NBTTagCompound; @@ -16,7 +17,6 @@ public class TankInfo implements INbtReadable, INbtWritable { private float capacity; public TankInfo(final IFluidTank tank) { - this.capacity = 0.0f; this.capacity = tank.getCapacity(); this.liquid = tank.getFluid(); } @@ -26,9 +26,10 @@ public TankInfo() { } public static TankInfo[] get(final ITankMachine machine) { - final TankInfo[] info = new TankInfo[machine.getTanks().length]; + IFluidTank[] fluidTanks = machine.getTanks(); + TankInfo[] info = new TankInfo[fluidTanks.length]; for (int i = 0; i < info.length; ++i) { - info[i] = new TankInfo(machine.getTanks()[i]); + info[i] = new TankInfo(fluidTanks[i]); } return info; } @@ -46,26 +47,29 @@ public boolean isEmpty() { } public String getName() { - return (this.liquid == null) ? "" : this.liquid.getFluid().getLocalizedName(this.liquid); + return (this.liquid == null) ? StringUtils.EMPTY : this.liquid.getFluid().getLocalizedName(this.liquid); } + private static final String NBT_KEY_CAPACITY = "capacity"; + private static final String NBT_KEY_LIQUID = "liquid"; + @Override public void readFromNBT(final NBTTagCompound nbt) { - this.capacity = nbt.getInteger("capacity"); - if (nbt.hasKey("liquid")) { - this.liquid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("liquid")); + this.capacity = nbt.getInteger(NBT_KEY_CAPACITY); + if (nbt.hasKey(NBT_KEY_LIQUID)) { + this.liquid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag(NBT_KEY_LIQUID)); } } @Override public NBTTagCompound writeToNBT(final NBTTagCompound nbt) { - nbt.setInteger("capacity", (int) this.getCapacity()); + nbt.setInteger(NBT_KEY_CAPACITY, (int) this.getCapacity()); if (this.liquid == null) { return nbt; } final NBTTagCompound tag = new NBTTagCompound(); this.liquid.writeToNBT(tag); - nbt.setTag("liquid", tag); + nbt.setTag(NBT_KEY_LIQUID, tag); return nbt; } diff --git a/core/src/main/java/binnie/core/machines/storage/CompartmentTab.java b/core/src/main/java/binnie/core/machines/storage/CompartmentTab.java index 0ce176a89..1cce3cc22 100644 --- a/core/src/main/java/binnie/core/machines/storage/CompartmentTab.java +++ b/core/src/main/java/binnie/core/machines/storage/CompartmentTab.java @@ -1,5 +1,7 @@ package binnie.core.machines.storage; +import org.apache.commons.lang3.StringUtils; + import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -15,27 +17,32 @@ class CompartmentTab implements INbtWritable { private final int id; public CompartmentTab(int id) { - this.name = ""; + this.name = StringUtils.EMPTY; this.icon = new ItemStack(Items.PAPER); this.color = EnumColor.WHITE; this.id = id; } + private static final String NBT_KEY_NAME = "name"; + private static final String NBT_KEY_ICON = "icon"; + private static final String NBT_KEY_COLOR = "color"; + private static final String NBT_KEY_ID = "id"; + public CompartmentTab(NBTTagCompound nbt) { - this.name = nbt.getString("name"); - this.icon = new ItemStack(nbt.getCompoundTag("icon")); - this.color = EnumColor.values()[nbt.getByte("color")]; - this.id = nbt.getByte("id"); + this.name = nbt.getString(NBT_KEY_NAME); + this.icon = new ItemStack(nbt.getCompoundTag(NBT_KEY_ICON)); + this.color = EnumColor.values()[nbt.getByte(NBT_KEY_COLOR)]; + this.id = nbt.getByte(NBT_KEY_ID); } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - nbt.setString("name", this.name); + nbt.setString(NBT_KEY_NAME, this.name); final NBTTagCompound n = new NBTTagCompound(); this.icon.writeToNBT(n); - nbt.setTag("icon", n); - nbt.setByte("color", (byte) this.color.ordinal()); - nbt.setByte("id", (byte) this.id); + nbt.setTag(NBT_KEY_ICON, n); + nbt.setByte(NBT_KEY_COLOR, (byte) this.color.ordinal()); + nbt.setByte(NBT_KEY_ID, (byte) this.id); return nbt; } diff --git a/core/src/main/java/binnie/core/machines/storage/ComponentCompartmentInventory.java b/core/src/main/java/binnie/core/machines/storage/ComponentCompartmentInventory.java index 6c1a3a1d1..267fd7a40 100644 --- a/core/src/main/java/binnie/core/machines/storage/ComponentCompartmentInventory.java +++ b/core/src/main/java/binnie/core/machines/storage/ComponentCompartmentInventory.java @@ -46,6 +46,9 @@ public CompartmentTab getTab(final int i) { return this.tabs.computeIfAbsent(i, CompartmentTab::new); } + private static final String NBT_KEY_TABS = "tabs"; + private static final String NBT_KEY_COMP_TABS = "comp-tabs"; + @Override public void sendGuiNBTToClient(final Map nbt) { final NBTTagList list = new NBTTagList(); @@ -55,14 +58,14 @@ public void sendGuiNBTToClient(final Map nbt) { list.appendTag(nbt2); } final NBTTagCompound tag = new NBTTagCompound(); - tag.setTag("tabs", list); - nbt.put("comp-tabs", tag); + tag.setTag(NBT_KEY_TABS, list); + nbt.put(NBT_KEY_COMP_TABS, tag); } @Override - public void receiveGuiNBTOnClient(EntityPlayer player, String name, NBTTagCompound nbt) { - if (name.equals("comp-tabs")) { - final NBTTagList tags = nbt.getTagList("tabs", 10); + public void receiveGuiNBTOnClient(final EntityPlayer player, final String name, final NBTTagCompound nbt) { + if (name.equals(NBT_KEY_COMP_TABS)) { + final NBTTagList tags = nbt.getTagList(NBT_KEY_TABS, 10); for (int i = 0; i < tags.tagCount(); ++i) { final NBTTagCompound tag = tags.getCompoundTagAt(i); final CompartmentTab tab = new CompartmentTab(tag); @@ -71,11 +74,13 @@ public void receiveGuiNBTOnClient(EntityPlayer player, String name, NBTTagCompou } } + public static final String ACTION_COMP_CHANGE_TAB = "comp-change-tab"; + @Override public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, final NBTTagCompound nbt) { - if (name.equals("comp-change-tab")) { - final CompartmentTab tab2 = new CompartmentTab(nbt); - this.tabs.put(tab2.getId(), tab2); + if (name.equals(ACTION_COMP_CHANGE_TAB)) { + final CompartmentTab tab = new CompartmentTab(nbt); + this.tabs.put(tab.getId(), tab); this.getMachine().getTileEntity().markDirty(); } } @@ -83,7 +88,7 @@ public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, @Override public void readFromNBT(final NBTTagCompound compound) { super.readFromNBT(compound); - final NBTTagList tags = compound.getTagList("tabs", 10); + final NBTTagList tags = compound.getTagList(NBT_KEY_TABS, 10); for (int i = 0; i < tags.tagCount(); ++i) { final NBTTagCompound tag = tags.getCompoundTagAt(i); final CompartmentTab tab = new CompartmentTab(tag); @@ -100,7 +105,7 @@ public NBTTagCompound writeToNBT(final NBTTagCompound compound) { this.getTab(i).writeToNBT(nbt2); list.appendTag(nbt2); } - nbt.setTag("tabs", list); + nbt.setTag(NBT_KEY_TABS, list); return nbt; } } diff --git a/core/src/main/java/binnie/core/machines/storage/SearchDialog.java b/core/src/main/java/binnie/core/machines/storage/SearchDialog.java index 3fac57df3..a650993ff 100644 --- a/core/src/main/java/binnie/core/machines/storage/SearchDialog.java +++ b/core/src/main/java/binnie/core/machines/storage/SearchDialog.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; +import binnie.core.ModId; import binnie.core.api.gui.IWidget; import binnie.core.gui.CraftGUI; import binnie.core.gui.controls.ControlCheckbox; @@ -20,18 +21,22 @@ import binnie.core.gui.minecraft.control.ControlSlot; import binnie.core.gui.renderer.RenderUtil; import binnie.core.gui.resource.textures.CraftGUITexture; +import binnie.core.util.I18N; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.StringUtils; @SideOnly(Side.CLIENT) public class SearchDialog extends Dialog { private final Control slotGrid; private final WindowCompartment windowCompartment; - private String textSearch = ""; + final ControlScrollableContent scroll; + private String textSearch = StringUtils.EMPTY; private boolean sortByName; private boolean includeItems; private boolean includeBlocks; @@ -40,12 +45,13 @@ public SearchDialog(WindowCompartment windowCompartment) { super(windowCompartment, 252, 192); this.windowCompartment = windowCompartment; - final ControlScrollableContent scroll = new SearchScrollContent(this); + scroll = new SearchScrollContent(this); this.slotGrid = new Control(scroll, 1, 1, 108, 18); scroll.setScrollableContent(this.slotGrid); new ControlPlayerInventory(this, true); new ControlTextEdit(this, 16, 16, 100, 14).addEventHandler(EventTextEdit.class, event -> { - textSearch = event.getValue(); + final String value = event.getValue(); + textSearch = (value == null) ? StringUtils.EMPTY : value; updateSearch(); }); this.includeItems = true; @@ -56,38 +62,49 @@ public SearchDialog(WindowCompartment windowCompartment) { this.updateSearch(); } - private void updateSearch() { - Map slotIds = new HashMap<>(); + private Map filter(final Map slotIds) { final IInventory inv = windowCompartment.getInventory(); for (int i = 0; i < inv.getSizeInventory(); ++i) { final ItemStack stack = inv.getStackInSlot(i); if (!stack.isEmpty()) { final String name = stack.getDisplayName().toLowerCase(); - if (this.textSearch == null || name.contains(this.textSearch)) { - if (this.includeBlocks || Block.getBlockFromItem(stack.getItem()) == Blocks.AIR) { - if (this.includeItems || Block.getBlockFromItem(stack.getItem()) != Blocks.AIR) { + if (this.textSearch.length() == 0 || name.contains(this.textSearch)) { + final Item item = stack.getItem(); + final Block block = Block.getBlockFromItem(item); + if (this.includeBlocks || block == Blocks.AIR) { + if (this.includeItems || block != Blocks.AIR) { slotIds.put(i, name); } } } } } + return slotIds; + } + + private Map sort(final Map slotIds) { if (this.sortByName) { final List> list = new LinkedList<>(slotIds.entrySet()); list.sort((o1, o2) -> -o2.getValue().compareTo(o1.getValue())); - final Map result = new LinkedHashMap<>(); + slotIds.clear(); for (final Map.Entry entry : list) { - result.put(entry.getKey(), entry.getValue()); + slotIds.put(entry.getKey(), entry.getValue()); } - slotIds = result; } + return slotIds; + } + + private void updateSearch() { + final Map slotIds = new HashMap<>(); + final Map filtered = filter(slotIds); + final Map sorted = sort(filtered); int y = 0; int x = 0; final int width = 108; - final int height = 2 + 18 * (1 + (slotIds.size() - 1) / 6); + final int height = 2 + 18 * (1 + (sorted.size() - 1) / 6); this.slotGrid.deleteAllChildren(); this.slotGrid.setSize(new Point(width, height)); - for (final int k : slotIds.keySet()) { + for (final int k : sorted.keySet()) { new ControlSlot.Builder(this.slotGrid, x, y).assign(k); x += 18; if (x >= 108) { @@ -97,7 +114,7 @@ private void updateSearch() { } while (y < 108 || x != 0) { // TODO: what was this supposed to do? - new ControlSlot.Builder(this.slotGrid, x, y); + //new ControlSlot.Builder(this.slotGrid, x, y); x += 18; if (x >= 108) { x = 0; @@ -118,7 +135,7 @@ public SearchScrollContent(SearchDialog searchDialog) { @SideOnly(Side.CLIENT) public void onRenderBackground(int guiWidth, int guiHeight) { RenderUtil.setColour(11184810); - CraftGUI.RENDER.texture(CraftGUITexture.OUTLINE, searchDialog.windowCompartment.getArea().inset(new Border(0, 6, 0, 0))); + CraftGUI.RENDER.texture(CraftGUITexture.OUTLINE, searchDialog.scroll.getArea().inset(new Border(0, 6, 0, 0))); } } @@ -126,7 +143,7 @@ private static class SortAlphabeticalCheckbox extends ControlCheckbox { private final SearchDialog searchDialog; public SortAlphabeticalCheckbox(SearchDialog searchDialog) { - super(searchDialog, 16, 40, 100, "Sort A-Z", searchDialog.sortByName); + super(searchDialog, 16, 40, 100, I18N.localise(ModId.CORE, "machine.storage.search.sort_by_name"), searchDialog.sortByName); this.searchDialog = searchDialog; } @@ -140,8 +157,8 @@ protected void onValueChanged(final boolean value) { private static class IncludeItemsCheckbox extends ControlCheckbox { private final SearchDialog searchDialog; - public IncludeItemsCheckbox(SearchDialog searchDialog) { - super(searchDialog, 16, 64, 100, "Include Items", searchDialog.includeItems); + public IncludeItemsCheckbox(final SearchDialog searchDialog) { + super(searchDialog, 16, 64, 100, I18N.localise(ModId.CORE, "machine.storage.search.include_items"), searchDialog.includeItems); this.searchDialog = searchDialog; } @@ -155,8 +172,8 @@ protected void onValueChanged(final boolean value) { private static class IncludeBlocksCheckbox extends ControlCheckbox { private final SearchDialog searchDialog; - public IncludeBlocksCheckbox(SearchDialog searchDialog) { - super(searchDialog, 16, 88, 100, "Include Blocks", searchDialog.includeBlocks); + public IncludeBlocksCheckbox(final SearchDialog searchDialog) { + super(searchDialog, 16, 88, 100, I18N.localise(ModId.CORE, "machine.storage.search.include_blocks"), searchDialog.includeBlocks); this.searchDialog = searchDialog; } diff --git a/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java b/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java index abeeb28a8..3836b42dd 100644 --- a/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java +++ b/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java @@ -5,12 +5,16 @@ import java.util.HashMap; import java.util.Map; +import binnie.core.ModId; import binnie.core.api.gui.ITexture; import binnie.core.api.gui.events.EventHandlerOrigin; +import binnie.core.gui.controls.tab.ControlTab; import binnie.core.gui.geometry.Point; import binnie.core.gui.window.WindowMachine; import binnie.core.machines.IMachine; import binnie.core.machines.MachinePackage; +import binnie.core.util.I18N; +import javafx.util.Pair; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; @@ -63,7 +67,48 @@ public WindowCompartment(final EntityPlayer player, @Nullable final IInventory i this.currentTab = 0; } - //TODO: Clean Up, Localise + private Pair calcTabsSlots(final int tabsCount) { + final int half = tabsCount / 2; + Integer[] tabs1 = new Integer[half + tabsCount % 2]; + Integer[] tabs2 = new Integer[half]; + int value = 0; + for (int index = 0; index < tabs1.length; ++index) { + tabs1[index] = value++; + } + for (int index = 0; index < tabs2.length; ++index) { + tabs2[index] = value++; + } + return new Pair<>(tabs1, tabs2); + } + + private void setControlTab(ControlTabBar tab) { + final String[] tabHelp = { + I18N.localise(ModId.CORE, "machine.storage.help.compartment_tab"), + I18N.localise(ModId.CORE, "machine.storage.help.compartment_tab.desc") + }; + tab.addHelp(tabHelp); + tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> { + if (event.getValue() == null) { + return; + } + final NBTTagCompound nbt = new NBTTagCompound(); + final int i = (Integer) event.getValue(); + nbt.setByte("i", (byte) i); + Window.get(tab).sendClientAction("tab-change", nbt); + WindowCompartment.this.currentTab = i; + }); + } + + private ControlSlide createSlide() { + final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT); + slide.setLabel(I18N.localise(ModId.CORE, "machine.storage.help.slide_label")); + slide.setSlide(false); + slide.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.slide_label")); + slide.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.slide_label.desc")); + return slide; + } + + //TODO: Clean Up @Override @SideOnly(Side.CLIENT) public void initialiseClient() { @@ -74,53 +119,25 @@ public void initialiseClient() { int x = 16; final int y = 32; final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class); - Integer[] tabs1 = new Integer[0]; - Integer[] tabs2 = new Integer[0]; - if (inv.getTabCount() == 4) { - tabs1 = new Integer[]{0, 1}; - tabs2 = new Integer[]{2, 3}; - } - if (inv.getTabCount() == 6) { - tabs1 = new Integer[]{0, 1, 2}; - tabs2 = new Integer[]{3, 4, 5}; - } - if (inv.getTabCount() == 8) { - tabs1 = new Integer[]{0, 1, 2, 3}; - tabs2 = new Integer[]{4, 5, 6, 7}; - } + Pair slots = calcTabsSlots(inv.getTabCount()); + Integer[] tabs1 = slots.getKey(); + Integer[] tabs2 = slots.getValue(); final boolean doubleTabbed = tabs2.length > 0; final int compartmentPageWidth = 16 + 18 * inv.getPageSize() / 5; final int compartmentPageHeight = 106; final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24); final int compartmentHeight = compartmentPageHeight; final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight); - final ControlTabBar tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), (x1, y1, w, h, value) -> { - return new CompartmentTabIcon(this, x1, y1, w, h, value); - }); - final String[] tabHelp = {"Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately."}; - tab.addHelp(tabHelp); - tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> { - if (event.getValue() == null) { - return; - } - final NBTTagCompound nbt = new NBTTagCompound(); - final int i = (Integer) event.getValue(); - nbt.setByte("i", (byte) i); - Window.get(tab).sendClientAction("tab-change", nbt); - WindowCompartment.this.currentTab = i; - }); - x += 24; + final ControlTabBar tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), this::createTab); + setControlTab(tab); + x += tab.getWidth(); final ControlPages compartmentPages = new ControlPages<>(controlCompartment, 24, 0, compartmentPageWidth, compartmentPageHeight); - final ControlPage[] page = new ControlPage[inv.getTabCount()]; - for (int p = 0; p < inv.getTabCount(); ++p) { - page[p] = new ControlPage<>(compartmentPages, p); - } CraftGUIUtil.linkWidgets(tab, compartmentPages); int i = 0; - for (int p2 = 0; p2 < inv.getTabCount(); ++p2) { - final ControlPage thisPage = page[p2]; + for (int pos = 0; pos < inv.getTabCount(); ++pos) { + final ControlPage thisPage = new ControlPage<>(compartmentPages, pos); final Panel panel = new CompartmentCenterPanel(this, thisPage); - this.panels.put(panel, p2); + this.panels.put(panel, pos); final int[] slotsIDs = new int[inv.getPageSize()]; for (int k = 0; k < inv.getPageSize(); ++k) { slotsIDs[k] = i++; @@ -128,86 +145,85 @@ public void initialiseClient() { new ControlSlotArray.Builder(thisPage, 8, 8, inv.getPageSize() / 5, 5).create(slotsIDs); } x += compartmentPageWidth; - if (tabs2.length > 0) { - final ControlTabBar tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), (x1, y1, w, h, value) -> { - return new CompartmentTabIcon(this, x1, y1, w, h, value); - }); + if (doubleTabbed) { + final ControlTabBar tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), this::createTab); tab2.setValue(tabs1[0]); - tab2.addHelp(tabHelp); - tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> { - if (event.getValue() == null) { - return; - } - final NBTTagCompound nbt = new NBTTagCompound(); - final int iVal = (Integer) event.getValue(); - nbt.setByte("i", (byte) iVal); - Window.get(tab).sendClientAction("tab-change", nbt); - WindowCompartment.this.currentTab = iVal; - }); + setControlTab(tab2); CraftGUIUtil.linkWidgets(tab2, compartmentPages); - x += 24; + x += tab2.getWidth(); } x += 16; this.setSize(new Point(Math.max(32 + compartmentWidth, 252), this.getHeight())); controlCompartment.setPosition(new Point((this.getWidth() - controlCompartment.getWidth()) / 2, controlCompartment.getYPos())); - final ControlPlayerInventory invent = new ControlPlayerInventory(this, true); - final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT); - slide.setLabel("Tab Properties"); - slide.setSlide(false); - slide.addHelp("Tab Properties"); - slide.addHelp("The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it."); + new ControlPlayerInventory(this, true); + + ControlSlide slide = createSlide(); final Panel tabPropertyPanel = new Panel(slide, 16, 8, 112, 76, MinecraftGUI.PanelType.GRAY); int y2 = 4; - new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Name:"); - final Panel parent = tabPropertyPanel; - final int x2 = 4; - y2 += 12; - (this.tabName = new ControlTextEdit(parent, x2, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> { - final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); - currentTab.setName(event.getValue()); - final NBTTagCompound nbt = new NBTTagCompound(); - currentTab.writeToNBT(nbt); - WindowCompartment.this.sendClientAction("comp-change-tab", nbt); - }); + y2 = createTabNameControl(tabPropertyPanel, y2); + y2 += 20; + createTabIconControl(tabPropertyPanel, y2); y2 += 20; - new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Icon: "); + createTabColourControl(tabPropertyPanel, y2); + createSearchControl(compartmentPageHeight, compartmentWidth, controlCompartment); + } + + private void createSearchControl(int compartmentPageHeight, int compartmentWidth, Control controlCompartment) { + final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight); + searchButton.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.search_label")); + searchButton.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.search_label.desc")); + } + + private void createTabColourControl(Panel tabPropertyPanel, int y2) { + new ControlText(tabPropertyPanel, new Point(4, y2), I18N.localise(ModId.CORE, "machine.storage.сolour")); + final int cw = 8; + final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY); + for (int cc = 0; cc < 16; ++cc) { + final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]); + color.addSelfEventHandler(EventMouse.Down.class, event -> { + final CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); + currentTab.setColor(color.getValue()); + final NBTTagCompound nbt = new NBTTagCompound(); + currentTab.writeToNBT(nbt); + WindowCompartment.this.sendClientAction(ComponentCompartmentInventory.ACTION_COMP_CHANGE_TAB, nbt); + }); + color.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.сolour_label")); + color.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.сolour_label.desc")); + } + } + + private void createTabIconControl(Panel tabPropertyPanel, int y2) { + new ControlText(tabPropertyPanel, new Point(4, y2), I18N.localise(ModId.CORE, "machine.storage.icon")); (this.tabIcon = new ControlItemDisplay(tabPropertyPanel, 58, y2 - 4)).setItemStack(new ItemStack(Items.PAPER)); this.tabIcon.addAttribute(Attribute.MOUSE_OVER); this.tabIcon.addSelfEventHandler(EventMouse.Down.class, event -> { if (WindowCompartment.this.getHeldItemStack().isEmpty()) { return; } - final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); + final CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); final ItemStack stack = WindowCompartment.this.getHeldItemStack().copy(); stack.setCount(1); currentTab.setIcon(stack); final NBTTagCompound nbt = new NBTTagCompound(); currentTab.writeToNBT(nbt); - WindowCompartment.this.sendClientAction("comp-change-tab", nbt); + WindowCompartment.this.sendClientAction(ComponentCompartmentInventory.ACTION_COMP_CHANGE_TAB, nbt); }); this.tabColour = new ControlColourSelector(tabPropertyPanel, 82, y2 - 4, 16, 16, EnumColor.WHITE); - this.tabIcon.addHelp("Icon for Current Tab"); - this.tabIcon.addHelp("Click here with an item to change"); - y2 += 20; - new ControlText(tabPropertyPanel, new Point(4, y2), "Colour: "); - final int cw = 8; - final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY); - for (int cc = 0; cc < 16; ++cc) { - final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]); - color.addSelfEventHandler(EventMouse.Down.class, event -> { - final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); - currentTab.setColor(color.getValue()); - final NBTTagCompound nbt = new NBTTagCompound(); - currentTab.writeToNBT(nbt); - WindowCompartment.this.sendClientAction("comp-change-tab", nbt); - }); - color.addHelp("Colour Selector"); - color.addHelp("Select a colour to highlight the current tab"); - } - y2 += 20; - final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight); - searchButton.addHelp("Search Button"); - searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items."); + this.tabIcon.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.icon_label")); + this.tabIcon.addHelp(I18N.localise(ModId.CORE, "machine.storage.help.icon_label.desc")); + } + + private int createTabNameControl(Panel tabPropertyPanel, int y2) { + new ControlText(tabPropertyPanel, new Point(4, y2), I18N.localise(ModId.CORE, "machine.storage.tab_name")); + y2 += 12; + (this.tabName = new ControlTextEdit(tabPropertyPanel, 4, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> { + final CompartmentTab currentTab = WindowCompartment.this.getCurrentTab(); + currentTab.setName(event.getValue()); + final NBTTagCompound nbt = new NBTTagCompound(); + currentTab.writeToNBT(nbt); + WindowCompartment.this.sendClientAction(ComponentCompartmentInventory.ACTION_COMP_CHANGE_TAB, nbt); + }); + return y2; } @SideOnly(Side.CLIENT) @@ -240,7 +256,7 @@ public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, @Override public String getTitle() { - return "Compartment"; + return I18N.localise(ModId.CORE, "machine.storage.compartment"); } @Override @@ -269,6 +285,10 @@ public CompartmentTab getCurrentTab() { return this.getTab(this.currentTab); } + private ControlTab createTab(int x1, int y1, int w, int h, Integer value) { + return new CompartmentTabIcon(this, x1, y1, w, h, value); + } + private static class CompartmentTabIcon extends ControlTabIcon { private final WindowCompartment windowCompartment; @@ -321,7 +341,7 @@ private static class SearchButton extends ControlButton { private final WindowCompartment windowCompartment; public SearchButton(WindowCompartment windowCompartment, Control controlCompartment, int compartmentWidth, int compartmentPageHeight) { - super(controlCompartment, compartmentWidth - 24 - 64 - 8, compartmentPageHeight, 64, 16, "Search"); + super(controlCompartment, compartmentWidth - 24 - 64 - 8, compartmentPageHeight, 64, 16, I18N.localise(ModId.CORE, "machine.storage.search.button")); this.windowCompartment = windowCompartment; } diff --git a/core/src/main/java/binnie/core/machines/transfer/TransferRequest.java b/core/src/main/java/binnie/core/machines/transfer/TransferRequest.java index 7b1c90454..a6a6dbebb 100644 --- a/core/src/main/java/binnie/core/machines/transfer/TransferRequest.java +++ b/core/src/main/java/binnie/core/machines/transfer/TransferRequest.java @@ -7,6 +7,7 @@ import binnie.core.machines.inventory.IInventorySlots; import binnie.core.machines.inventory.InventorySlot; import binnie.core.machines.power.ITankMachine; +import binnie.core.util.EmptyHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -34,8 +35,8 @@ public class TransferRequest { public TransferRequest(final ItemStack toTransfer, final IInventory destination) { this.returnItem = ItemStack.EMPTY; - this.targetSlots = new int[0]; - this.targetTanks = new int[0]; + this.targetSlots = EmptyHelper.INT_ARRAY_EMPTY; + this.targetTanks = EmptyHelper.INT_ARRAY_EMPTY; this.transferLiquids = true; this.ignoreReadOnly = false; this.insertedSlots = new ArrayList<>(); @@ -43,7 +44,7 @@ public TransferRequest(final ItemStack toTransfer, final IInventory destination) for (int i = 0; i < target.length; ++i) { target[i] = i; } - int[] targetTanks = new int[0]; + int[] targetTanks = EmptyHelper.INT_ARRAY_EMPTY; if (destination instanceof ITankMachine) { targetTanks = new int[((ITankMachine) destination).getTanks().length]; for (int j = 0; j < targetTanks.length; ++j) { diff --git a/core/src/main/java/binnie/core/models/AABBModelBaker.java b/core/src/main/java/binnie/core/models/AABBModelBaker.java index 3be231457..1593c44dd 100644 --- a/core/src/main/java/binnie/core/models/AABBModelBaker.java +++ b/core/src/main/java/binnie/core/models/AABBModelBaker.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.block.Block; @@ -223,7 +224,7 @@ public IModelBakerModel bakeModel(boolean flip) { final float[] uvs = getFaceUvs(myFace, to, from); final BlockFaceUV uv = new BlockFaceUV(uvs, 0); - final BlockPartFace bpf = new BlockPartFace(myFace, face.colorIndex, "", uv); + final BlockPartFace bpf = new BlockPartFace(myFace, face.colorIndex, StringUtils.EMPTY, uv); BakedQuad bf = faceBakery.makeBakedQuad(from, to, bpf, face.spite, myFace, mr, null, true, true); diff --git a/core/src/main/java/binnie/core/modules/BinnieModule.java b/core/src/main/java/binnie/core/modules/BinnieModule.java index cacec4efa..6a383f37a 100644 --- a/core/src/main/java/binnie/core/modules/BinnieModule.java +++ b/core/src/main/java/binnie/core/modules/BinnieModule.java @@ -1,5 +1,7 @@ package binnie.core.modules; +import org.apache.commons.lang3.StringUtils; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -29,11 +31,11 @@ /** * @return Version of the module, if any. */ - String version() default ""; + String version() default StringUtils.EMPTY; /** * @return Localization key for a short description what the module does. */ - String unlocalizedDescription() default ""; + String unlocalizedDescription() default StringUtils.EMPTY; } diff --git a/core/src/main/java/binnie/core/modules/Module.java b/core/src/main/java/binnie/core/modules/Module.java index 6b8c8ae85..21f784822 100644 --- a/core/src/main/java/binnie/core/modules/Module.java +++ b/core/src/main/java/binnie/core/modules/Module.java @@ -1,11 +1,13 @@ package binnie.core.modules; +import org.apache.commons.lang3.StringUtils; + import java.util.Collections; import java.util.Set; public interface Module { default String getFailMessage(){ - return ""; + return StringUtils.EMPTY; } default Set getDependencyUids(){ diff --git a/core/src/main/java/binnie/core/proxy/I18NClient.java b/core/src/main/java/binnie/core/proxy/I18NClient.java index c931a1d3a..f7adb1269 100644 --- a/core/src/main/java/binnie/core/proxy/I18NClient.java +++ b/core/src/main/java/binnie/core/proxy/I18NClient.java @@ -7,6 +7,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.StringUtils; @SideOnly(Side.CLIENT) public class I18NClient implements I18NProxy { @@ -15,7 +16,7 @@ public class I18NClient implements I18NProxy { public String localiseOrBlank(String key) { String trans = localise(key); - return trans.equals(key) ? "" : trans; + return trans.equals(key) ? StringUtils.EMPTY : trans; } public String localise(String key) { diff --git a/core/src/main/java/binnie/core/proxy/I18NServer.java b/core/src/main/java/binnie/core/proxy/I18NServer.java index d8c3f60ab..4e054f470 100644 --- a/core/src/main/java/binnie/core/proxy/I18NServer.java +++ b/core/src/main/java/binnie/core/proxy/I18NServer.java @@ -6,6 +6,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.StringUtils; import java.util.IllegalFormatException; @@ -14,7 +15,7 @@ public class I18NServer implements I18NProxy { public String localiseOrBlank(String key) { String trans = localise(key); - return trans.equals(key) ? "" : trans; + return trans.equals(key) ? StringUtils.EMPTY : trans; } public String localise(String key) { diff --git a/core/src/main/java/binnie/core/util/EmptyHelper.java b/core/src/main/java/binnie/core/util/EmptyHelper.java index 41bccfa45..2ee7ed029 100644 --- a/core/src/main/java/binnie/core/util/EmptyHelper.java +++ b/core/src/main/java/binnie/core/util/EmptyHelper.java @@ -1,7 +1,39 @@ package binnie.core.util; +import binnie.core.api.genetics.IGene; +import binnie.core.gui.IBinnieGUID; +import binnie.core.gui.minecraft.CustomSlot; +import binnie.core.machines.power.TankInfo; +import binnie.core.network.IPacketID; +import forestry.api.genetics.IChromosomeType; +import net.minecraft.block.properties.IProperty; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.IFluidTank; + public final class EmptyHelper { private EmptyHelper() {} - public static final String EMPTY_STRING = ""; + public static final IPacketID[] PACKET_IDS_EMPTY = new IPacketID[0]; + + public static final IBinnieGUID[] BINNIE_GUIDS_EMPTY = new IBinnieGUID[0]; + + public static final Class[] CLASS_ARRAY_EMPTY = new Class[0]; + + public static final IChromosomeType[] CHROMOSOME_TYPES_EMPTY = new IChromosomeType[0]; + + public static final CustomSlot[] CUSTOM_SLOTS_EMPTY = new CustomSlot[0]; + + public static final int[] INT_ARRAY_EMPTY = new int[0]; + + public static final TankInfo[] TANK_INFO_EMPTY = new TankInfo[0]; + + public static final IFluidTank[] FLUID_TANKS_EMPTY = new IFluidTank[0]; + + public static final IProperty[] PROPERTIES_EMPTY = new IProperty[0]; + + public static final ItemStack[] ITEM_STACKS_EMPTY = new ItemStack[0]; + + public static final IGene[] GENES_EMPTY = new IGene[0]; + + public static final Integer[] DEFAULT_TABS_EMPTY = new Integer[0]; } diff --git a/core/src/main/java/binnie/core/util/FluidStackUtil.java b/core/src/main/java/binnie/core/util/FluidStackUtil.java index 42086d0fb..5263357f6 100644 --- a/core/src/main/java/binnie/core/util/FluidStackUtil.java +++ b/core/src/main/java/binnie/core/util/FluidStackUtil.java @@ -1,5 +1,7 @@ package binnie.core.util; +import org.apache.commons.lang3.StringUtils; + import javax.annotation.Nullable; import java.util.Collection; @@ -14,12 +16,13 @@ public class FluidStackUtil { - public static String toString(FluidStack fluidStack){ - if(fluidStack == null){ + public static String toString(@Nullable final FluidStack fluidStack) { + if (fluidStack == null) { return "null"; } - NBTTagCompound tag = fluidStack.tag; - return fluidStack.getFluid().getName() + ':' + fluidStack.amount + (tag != null ? ":" + fluidStack.tag : ""); + final NBTTagCompound tag = fluidStack.tag; + return fluidStack.getFluid().getName() + ':' + fluidStack.amount + + (tag != null ? ":" + fluidStack.tag : StringUtils.EMPTY); } public static NonNullList removeEqualFluids(Collection fluidsStacks) { @@ -32,8 +35,8 @@ public static NonNullList removeEqualFluids(Collection f return dedupedFluidStacks; } - public static boolean containsEqualFluid(NonNullList fluidStacks, FluidStack query) { - for (FluidStack fluidStack : fluidStacks) { + public static boolean containsEqualFluid(final NonNullList fluidStacks, final FluidStack query) { + for (final FluidStack fluidStack : fluidStacks) { if (fluidStack.isFluidEqual(query)) { return true; } @@ -42,7 +45,7 @@ public static boolean containsEqualFluid(NonNullList fluidStacks, Fl } @Nullable - public static ItemStack getContainer(FluidStack fluidStack) { + public static ItemStack getContainer(final FluidStack fluidStack) { ItemStack[] containers = { new ItemStack(Items.GLASS_BOTTLE), new ItemStack(Items.BUCKET) diff --git a/core/src/main/java/binnie/core/util/NBTUtil.java b/core/src/main/java/binnie/core/util/NBTUtil.java index e9424764e..d3299df50 100644 --- a/core/src/main/java/binnie/core/util/NBTUtil.java +++ b/core/src/main/java/binnie/core/util/NBTUtil.java @@ -4,6 +4,7 @@ import java.util.function.BiFunction; import java.util.function.Consumer; +import forestry.api.core.INbtWritable; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -16,6 +17,15 @@ public class NBTUtil { private NBTUtil() { } + public static BiFunction writeToListConsumer(final String Key) { + return (index, slot) -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + nbtTagCompound.setInteger(Key, index); + slot.writeToNBT(nbtTagCompound); + return nbtTagCompound; + }; + } + public static void readFromList(NBTTagCompound compound, String listKey, Consumer consumer){ if(!compound.hasKey(listKey, 9)){ return; diff --git a/core/src/main/resources/assets/binniecore/lang/en_US.lang b/core/src/main/resources/assets/binniecore/lang/en_US.lang index 0d0e9003f..099676cda 100644 --- a/core/src/main/resources/assets/binniecore/lang/en_US.lang +++ b/core/src/main/resources/assets/binniecore/lang/en_US.lang @@ -182,6 +182,7 @@ binniecore.gui.breedingmessage.species=Species Discovered binniecore.gui.breedingmessage.branch=Branch Discovered binniecore.gui.breedingmessage.epithet=Epithet Gained +binniecore.item.container.empty=Empty %s binniecore.item.container.capsule=Capsule binniecore.item.container.refractory=Capsule binniecore.item.container.can=Can @@ -189,6 +190,23 @@ binniecore.item.container.bucket=Bucket binniecore.item.container.glass=Bottle binniecore.item.container.cylinder=Cylinder +binniecore.machine.storage.tab_name=Tab Name: +binniecore.machine.storage.search.button=Search +binniecore.machine.storage.search.sort_by_name=Sort A-Z +binniecore.machine.storage.search.include_items=Include Items +binniecore.machine.storage.search.include_blocks=Include Blocks +binniecore.machine.storage.help.compartment_tab=Compartment Tab +binniecore.machine.storage.help.compartment_tab.desc=Tabs that divide the inventory into sections. Each one can be labelled seperately. +binniecore.machine.storage.help.slide_label=Tab Properties +binniecore.machine.storage.help.slide_label.desc=The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it. +binniecore.machine.storage.icon=Tab Icon: +binniecore.machine.storage.help.icon_label=Icon for Current Tab +binniecore.machine.storage.help.icon_label.desc=Click here with an item to change +binniecore.machine.storage.help.search_label=Search Button +binniecore.machine.storage.help.search_label.desc=Clicking this will open the Search dialog. This allows you to search the inventory for specific items. +binniecore.machine.storage.сolour=Colour: +binniecore.machine.storage.help.сolour_label=Colour Selector +binniecore.machine.storage.help.сolour_label.desc=Select a colour to highlight the current tab binniecore.machine.storage.compartment=Compartment binniecore.machine.storage.compartment.info=Chests which contain several tabs to help organise their contents. Each tab can be named, assigned a colour and assigned an icon from any Item Stack. Number of Tabs: 4, slots per Tab: 25 binniecore.machine.storage.compartment_iron=Iron Compartment @@ -352,9 +370,14 @@ binniecore.gui.slot.serum.output=Serum Output Slot binniecore.gui.slot.serum.active=Active Serum Slot binniecore.gui.slot.yeast=Yeast Slot binniecore.gui.slot.inventory=Machine Inventory +binniecore.gui.slot.window.inventory.any=Any Item +binniecore.gui.slot.window.inventory=Accepts: %s binniecore.gui.slot.player.inventory=Player Inventory binniecore.gui.slot.pickup.only=Pickup Only Slot +binniecore.gui.slotvalidator.individual=Breedable Individual + +binniecore.gui.tank.empty=Empty binniecore.gui.tank.validated=%s Tank binniecore.gui.tank.input=Input Tank binniecore.gui.tank.process=Process Tank @@ -376,10 +399,16 @@ binniecore.gui.charge.remaining.percent=Charge Remaining: %s binniecore.gui.progress.title=Progress binniecore.gui.progress.no.progress=Not in Progress binniecore.gui.progress.in.progress=In Progress +binniecore.gui.progress.time.minute=%d minute +binniecore.gui.progress.time.minutes=%d minutes +binniecore.gui.progress.time.second=%d second +binniecore.gui.progress.time.seconds=%d seconds binniecore.gui.progress.time.left=Time Left: %s binniecore.gui.progress.time.total=Total Time: %s binniecore.gui.progress.energy.cost.total=Energy Cost: %s RF +binniecore.gui.controluser.owner=Owner + binniecore.side.north=North binniecore.side.south=South binniecore.side.east=East diff --git a/core/src/main/resources/assets/binniecore/lang/ru_RU.lang b/core/src/main/resources/assets/binniecore/lang/ru_RU.lang index dab202497..f0a8c495c 100644 --- a/core/src/main/resources/assets/binniecore/lang/ru_RU.lang +++ b/core/src/main/resources/assets/binniecore/lang/ru_RU.lang @@ -182,6 +182,7 @@ binniecore.gui.breedingmessage.species=Обнаруженные виды binniecore.gui.breedingmessage.branch=Обнаруженные ветви binniecore.gui.breedingmessage.epithet=Эпитет получен +binniecore.item.container.empty=%s без жидкости binniecore.item.container.capsule=Капсула binniecore.item.container.refractory=Капсула binniecore.item.container.can=Капсула @@ -189,6 +190,23 @@ binniecore.item.container.bucket=Ведро binniecore.item.container.glass=Бутылка binniecore.item.container.cylinder=Цилиндр +binniecore.machine.storage.tab_name=Имя вкладки: +binniecore.machine.storage.search.button=Поиск +binniecore.machine.storage.search.sort_by_name=Сорт. A-Z +binniecore.machine.storage.search.include_items=Включая предметы +binniecore.machine.storage.search.include_blocks=Включая блоки +binniecore.machine.storage.help.compartment_tab=Вкладка Отсека +binniecore.machine.storage.help.compartment_tab.desc=Вкладки делят инвентарь на секции. Каждая настраивается отдельно. +binniecore.machine.storage.help.slide_label=Свойства вкладки +binniecore.machine.storage.help.slide_label.desc=Заголовок, цвет и иконка могут быть назначены здесь. Кликнув на иконке удерживая предмет изменят ее. +binniecore.machine.storage.icon=Иконка вкл.: +binniecore.machine.storage.help.icon_label=Иконка для текущей вкладки +binniecore.machine.storage.help.icon_label.desc=Кликните здесь, чтобы изменить +binniecore.machine.storage.help.search_label=Кнопка поиска +binniecore.machine.storage.help.search_label.desc=Кликнув вы откроете окно поиска. Это позволяет искать в инвентаре специфические предметы. +binniecore.machine.storage.сolour=Цвет: +binniecore.machine.storage.help.сolour_label=Выбор цвета +binniecore.machine.storage.help.сolour_label.desc=Выбрать цвет, чтобы выделять текущую вкладку binniecore.machine.storage.compartment=Отсек binniecore.machine.storage.compartment.info=Сундуки, у которых несколько вкладок, чтобы помочь организовать их содержимое. Каждая вкладка может быть: переименована, назначен цвет, назначена пиктограмма из любого элемента. Количество вкладок: 4, слоты на вкладку: 25 binniecore.machine.storage.compartment_iron=Железный отсек @@ -350,10 +368,15 @@ binniecore.gui.slot.serum.input=Входящая сыворотка binniecore.gui.slot.serum.output=Выходящая сыворотка binniecore.gui.slot.serum.active=Активная сыворотка binniecore.gui.slot.yeast=Слот для дрожжей +binniecore.gui.slot.window.inventory.any=Любой предмет +binniecore.gui.slot.window.inventory=Принимает: %s binniecore.gui.slot.inventory=Инвентарь машины binniecore.gui.slot.player.inventory=Инвентарь игрока binniecore.gui.slot.pickup.only=Можно положить только в слот +binniecore.gui.slotvalidator.individual=Разводимая особь + +binniecore.gui.tank.empty=Резервуар пуст binniecore.gui.tank.validated=%s резервуар binniecore.gui.tank.input=Входной резервуар binniecore.gui.tank.process=Технологический резервуар @@ -375,10 +398,16 @@ binniecore.gui.charge.remaining.percent=Остаток заряда: %s binniecore.gui.progress.title=Прогресс binniecore.gui.progress.no.progress=Не выполняется binniecore.gui.progress.in.progress=Выполняется +binniecore.gui.progress.time.minute=%d минута +binniecore.gui.progress.time.minutes=%d мин. +binniecore.gui.progress.time.second=%d секунда +binniecore.gui.progress.time.seconds=%d сек. binniecore.gui.progress.time.left=Осталось времени: %s binniecore.gui.progress.time.total=Общее время: %s binniecore.gui.progress.energy.cost.total=Энергетические затраты: %s RF +binniecore.gui.controluser.owner=Владелец + binniecore.side.north=Север binniecore.side.south=Юг binniecore.side.east=Восток diff --git a/design/src/main/java/binnie/design/blocks/BlockDesign.java b/design/src/main/java/binnie/design/blocks/BlockDesign.java index c475d2783..8e7a16949 100644 --- a/design/src/main/java/binnie/design/blocks/BlockDesign.java +++ b/design/src/main/java/binnie/design/blocks/BlockDesign.java @@ -9,7 +9,6 @@ import binnie.design.api.IDesignSystem; import binnie.design.api.IToolHammer; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.ItemMeshDefinition; @@ -57,6 +56,7 @@ import binnie.core.models.ModelManager; import binnie.core.models.ModelMutlipass; import binnie.core.util.TileUtil; +import binnie.core.util.EmptyHelper; public abstract class BlockDesign extends BlockMetadata implements IMultipassBlock, IColoredBlock, ISpriteRegister, IItemModelRegister, IStateMapperRegister { public static final EnumFacing[] RENDER_DIRECTIONS = new EnumFacing[]{EnumFacing.DOWN, EnumFacing.UP, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH}; @@ -201,7 +201,7 @@ public void registerModel(Item item, IModelManager manager) { @Override protected BlockStateContainer createBlockState() { - return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + return new ExtendedBlockState(this, EmptyHelper.PROPERTIES_EMPTY, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); } @Override diff --git a/design/src/main/java/binnie/design/gui/ControlRecipeSlot.java b/design/src/main/java/binnie/design/gui/ControlRecipeSlot.java index 9f8a6fcab..e2e400151 100644 --- a/design/src/main/java/binnie/design/gui/ControlRecipeSlot.java +++ b/design/src/main/java/binnie/design/gui/ControlRecipeSlot.java @@ -16,12 +16,12 @@ public class ControlRecipeSlot extends ControlSlotBase { public ControlRecipeSlot(final IWidget parent, final int x, final int y) { super(parent, x, y, 50); this.addSelfEventHandler(EventMouse.Down.class, event -> { - final TileEntity tile = (TileEntity) Window.get(ControlRecipeSlot.this.getWidget()).getInventory(); + final TileEntity tile = (TileEntity) Window.get(ControlRecipeSlot.this).getInventory(); if (!(tile instanceof TileEntityMachine)) { return; } final NBTTagCompound nbt = new NBTTagCompound(); - Window.get(ControlRecipeSlot.this.getWidget()).sendClientAction("recipe", nbt); + Window.get(ControlRecipeSlot.this).sendClientAction("recipe", nbt); }); this.setRotating(); } diff --git a/design/src/main/java/binnie/design/gui/ControlTileSelect.java b/design/src/main/java/binnie/design/gui/ControlTileSelect.java index b5615923a..9c0b7afc8 100644 --- a/design/src/main/java/binnie/design/gui/ControlTileSelect.java +++ b/design/src/main/java/binnie/design/gui/ControlTileSelect.java @@ -135,7 +135,7 @@ protected ControlTile(final IWidget parent, final int x, final int y, final IDes this.value = value; this.addAttribute(Attribute.MOUSE_OVER); this.addSelfEventHandler(EventMouse.Down.class, event -> { - final TileEntityMachine tile = (TileEntityMachine) Window.get(ControlTile.this.getWidget()).getInventory(); + final TileEntityMachine tile = (TileEntityMachine) Window.get(ControlTile.this).getInventory(); if (tile == null) { return; } @@ -143,7 +143,7 @@ protected ControlTile(final IWidget parent, final int x, final int y, final IDes ComponentDesignerRecipe recipe = tile.getMachine().getComponent(ComponentDesignerRecipe.class); final NBTTagCompound nbt = new NBTTagCompound(); nbt.setShort("d", (short) DesignAPI.manager.getDesignIndex(ControlTile.this.getValue())); - Window.get(ControlTile.this.getWidget()).sendClientAction("design", nbt); + Window.get(ControlTile.this).sendClientAction("design", nbt); }); } diff --git a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java index ecc25c844..d74b38bc0 100644 --- a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java +++ b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java @@ -32,11 +32,13 @@ public class AlvearyLogicStimulator extends AlvearyLogicElectrical { private boolean powered; private StimulatorCircuit[] modifiers; + private static final StimulatorCircuit[] STIMULATOR_CIRCUITS_EMPTY = new StimulatorCircuit[0]; + public AlvearyLogicStimulator() { super(10000); this.powerUsage = 0; this.powered = false; - this.modifiers = new StimulatorCircuit[0]; + this.modifiers = STIMULATOR_CIRCUITS_EMPTY; this.inv = new ChipsetItemStackHandler(); } @@ -78,7 +80,7 @@ private ICircuitBoard getHiveFrame() { public StimulatorCircuit[] getCircuits() { final ICircuitBoard board = this.getHiveFrame(); if (board == null) { - return new StimulatorCircuit[0]; + return STIMULATOR_CIRCUITS_EMPTY; } final ICircuit[] circuits = board.getCircuits(); final List mod = new ArrayList<>(); @@ -87,7 +89,7 @@ public StimulatorCircuit[] getCircuits() { mod.add((StimulatorCircuit) circuit); } } - return mod.toArray(new StimulatorCircuit[0]); + return mod.toArray(STIMULATOR_CIRCUITS_EMPTY); } @Override diff --git a/extratrees/src/main/java/binnie/extratrees/genetics/gui/analyst/AnalystPageFruit.java b/extratrees/src/main/java/binnie/extratrees/genetics/gui/analyst/AnalystPageFruit.java index 586492eaf..9b03444e7 100644 --- a/extratrees/src/main/java/binnie/extratrees/genetics/gui/analyst/AnalystPageFruit.java +++ b/extratrees/src/main/java/binnie/extratrees/genetics/gui/analyst/AnalystPageFruit.java @@ -29,6 +29,7 @@ import binnie.core.gui.geometry.Point; import binnie.core.gui.minecraft.control.ControlItemDisplay; import binnie.core.util.I18N; +import binnie.core.util.EmptyHelper; import binnie.core.util.UniqueItemStackSet; import binnie.genetics.api.analyst.AnalystConstants; import net.minecraftforge.fml.relauncher.Side; @@ -57,7 +58,7 @@ public AnalystPageFruit(IWidget parent, IArea area, ITree ind, IAnalystManager a FruitProviderPod pod = (FruitProviderPod) ind.getGenome().getFruitProvider(); Field f = FruitProviderPod.class.getDeclaredField("drops"); f.setAccessible(true); - Collections.addAll(products, ((Map) f.get(pod)).keySet().toArray(new ItemStack[0])); + Collections.addAll(products, ((Map) f.get(pod)).keySet().toArray(EmptyHelper.ITEM_STACKS_EMPTY)); } } catch (IllegalAccessException | NoSuchFieldException e) { throw new RuntimeException(e); @@ -118,7 +119,7 @@ public AnalystPageFruit(IWidget parent, IArea area, ITree ind, IAnalystManager a FruitProviderPod pod2 = (FruitProviderPod) ((IAlleleFruit) a).getProvider(); Field field = FruitProviderPod.class.getDeclaredField("drops"); field.setAccessible(true); - Collections.addAll(stacks, ((Map) field.get(pod2)).keySet().toArray(new ItemStack[0])); + Collections.addAll(stacks, ((Map) field.get(pod2)).keySet().toArray(EmptyHelper.ITEM_STACKS_EMPTY)); } } catch (IllegalAccessException | NoSuchFieldException e) { throw new RuntimeException(e); diff --git a/extratrees/src/main/java/binnie/extratrees/kitchen/craftgui/ControlTankSlot.java b/extratrees/src/main/java/binnie/extratrees/kitchen/craftgui/ControlTankSlot.java index 0c3699481..df2ab8438 100644 --- a/extratrees/src/main/java/binnie/extratrees/kitchen/craftgui/ControlTankSlot.java +++ b/extratrees/src/main/java/binnie/extratrees/kitchen/craftgui/ControlTankSlot.java @@ -20,7 +20,7 @@ public ControlTankSlot(final IWidget parent, final int x, final int y, final int if (event.getButton() == 0) { final NBTTagCompound nbt = new NBTTagCompound(); nbt.setByte("id", (byte) ControlTankSlot.this.tankID); - Window.get(ControlTankSlot.this.getWidget()).sendClientAction("tank-click", nbt); + Window.get(ControlTankSlot.this).sendClientAction("tank-click", nbt); } }); } diff --git a/extratrees/src/main/java/binnie/extratrees/machines/distillery/window/ControlDistilleryProgress.java b/extratrees/src/main/java/binnie/extratrees/machines/distillery/window/ControlDistilleryProgress.java index 0414dc685..9a5c3b0dd 100644 --- a/extratrees/src/main/java/binnie/extratrees/machines/distillery/window/ControlDistilleryProgress.java +++ b/extratrees/src/main/java/binnie/extratrees/machines/distillery/window/ControlDistilleryProgress.java @@ -43,7 +43,7 @@ protected ControlDistilleryProgress(final IWidget parent, final int x, final int if (distillationLevel >= 0) { final NBTTagCompound nbt = new NBTTagCompound(); nbt.setByte("i", (byte) distillationLevel); - Window.get(ControlDistilleryProgress.this.getWidget()).sendClientAction("still-level", nbt); + Window.get(ControlDistilleryProgress.this).sendClientAction("still-level", nbt); } }); } diff --git a/extratrees/src/main/java/binnie/extratrees/machines/fruitpress/window/ControlFruitPressProgress.java b/extratrees/src/main/java/binnie/extratrees/machines/fruitpress/window/ControlFruitPressProgress.java index e54da999e..c86d7875b 100644 --- a/extratrees/src/main/java/binnie/extratrees/machines/fruitpress/window/ControlFruitPressProgress.java +++ b/extratrees/src/main/java/binnie/extratrees/machines/fruitpress/window/ControlFruitPressProgress.java @@ -36,10 +36,10 @@ protected ControlFruitPressProgress(final IWidget parent, final int x, final int this.addSelfEventHandler(EventMouse.Down.class, event -> { if (event.getY() - event.getOrigin().getAbsolutePosition().yPos() > 52 + Math.round(16 * progress)) { final NBTTagCompound action = new NBTTagCompound(); - Window.get(ControlFruitPressProgress.this.getWidget()).sendClientAction("clear-fruit", action); + Window.get(ControlFruitPressProgress.this).sendClientAction("clear-fruit", action); } else { final NBTTagCompound action = new NBTTagCompound(); - Window.get(ControlFruitPressProgress.this.getWidget()).sendClientAction("fruitpress-click", action); + Window.get(ControlFruitPressProgress.this).sendClientAction("fruitpress-click", action); } }); } diff --git a/genetics/src/main/java/binnie/genetics/genetics/Engineering.java b/genetics/src/main/java/binnie/genetics/genetics/Engineering.java index be4cf4eb1..99575c475 100644 --- a/genetics/src/main/java/binnie/genetics/genetics/Engineering.java +++ b/genetics/src/main/java/binnie/genetics/genetics/Engineering.java @@ -12,6 +12,7 @@ import binnie.genetics.item.GeneticsItems; import binnie.genetics.item.ItemSerum; import binnie.genetics.item.ItemSerumArray; +import binnie.core.util.EmptyHelper; public class Engineering { public static boolean isGeneAcceptor(ItemStack stack) { @@ -80,7 +81,7 @@ public static IGene[] getGenes(ItemStack serum) { } } } - return new IGene[0]; + return EmptyHelper.GENES_EMPTY; } public static int getCharges(ItemStack serum) { diff --git a/genetics/src/main/java/binnie/genetics/item/ItemSerumArray.java b/genetics/src/main/java/binnie/genetics/item/ItemSerumArray.java index 67c4e8902..3896d2019 100644 --- a/genetics/src/main/java/binnie/genetics/item/ItemSerumArray.java +++ b/genetics/src/main/java/binnie/genetics/item/ItemSerumArray.java @@ -19,6 +19,7 @@ import binnie.core.Binnie; import binnie.core.genetics.Gene; import binnie.core.util.I18N; +import binnie.core.util.EmptyHelper; import binnie.genetics.Genetics; import binnie.core.api.genetics.IGene; import binnie.genetics.api.IItemSerum; @@ -53,9 +54,9 @@ public int getMaxCharges(ItemStack stack) { public IGene[] getGenes(final ItemStack stack) { GeneArrayItem geneItem = this.getGeneItem(stack); if (geneItem != null) { - return geneItem.getGenes().toArray(new IGene[0]); + return geneItem.getGenes().toArray(EmptyHelper.GENES_EMPTY); } - return new IGene[0]; + return EmptyHelper.GENES_EMPTY; } @Override diff --git a/genetics/src/main/java/binnie/genetics/machine/craftgui/ControlGene.java b/genetics/src/main/java/binnie/genetics/machine/craftgui/ControlGene.java index 8b4e45050..7ff45dbef 100644 --- a/genetics/src/main/java/binnie/genetics/machine/craftgui/ControlGene.java +++ b/genetics/src/main/java/binnie/genetics/machine/craftgui/ControlGene.java @@ -31,12 +31,12 @@ protected ControlGene(final IWidget parent, final int x, final int y, final IGen this.gene = gene; this.addAttribute(Attribute.MOUSE_OVER); this.addSelfEventHandler(EventMouse.Down.class, event -> { - if (ControlGene.this.canFill(Window.get(ControlGene.this.getWidget()).getHeldItemStack())) { + if (ControlGene.this.canFill(Window.get(ControlGene.this).getHeldItemStack())) { final NBTTagCompound action = new NBTTagCompound(); final NBTTagCompound geneNBT = new NBTTagCompound(); ControlGene.this.getValue().writeToNBT(geneNBT); action.setTag("gene", geneNBT); - Window.get(ControlGene.this.getWidget()).sendClientAction("gene-select", action); + Window.get(ControlGene.this).sendClientAction("gene-select", action); } }); } diff --git a/genetics/src/main/java/binnie/genetics/recipes/RotatedOreIngredient.java b/genetics/src/main/java/binnie/genetics/recipes/RotatedOreIngredient.java index 6bb0b2e36..c204227fb 100644 --- a/genetics/src/main/java/binnie/genetics/recipes/RotatedOreIngredient.java +++ b/genetics/src/main/java/binnie/genetics/recipes/RotatedOreIngredient.java @@ -5,6 +5,7 @@ import java.util.Collections; +import binnie.core.util.EmptyHelper; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntComparators; import it.unimi.dsi.fastutil.ints.IntList; @@ -51,7 +52,7 @@ public ItemStack[] getMatchingStacks() lst.add(itemstack); } Collections.rotate(lst, offset); - this.array = lst.toArray(new ItemStack[0]); + this.array = lst.toArray(EmptyHelper.ITEM_STACKS_EMPTY); } return this.array; }