From 6d9bd4fff43c6e76766816908758127737dde642 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:54:08 +0200 Subject: Bee Definition Cleanup (#326) * Bee Definition Cleanup Removed a Lot of boilerplate code, by using Consumers instead of Overrides Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> * Made Use of Static imports + use "Color" class for better IDE integration & readability + parameterised some Generics + reroute some Method overloads Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> * fixed an oversight Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> * fixed a typo Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> --- .../java/gregtech/common/bees/GT_AlleleBeeSpecies.java | 14 ++++++++++++-- src/main/java/gregtech/common/bees/GT_AlleleHelper.java | 11 ++++++++--- src/main/java/gregtech/common/bees/GT_Bee_Mutation.java | 5 +++-- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/bees/GT_AlleleBeeSpecies.java b/src/main/java/gregtech/common/bees/GT_AlleleBeeSpecies.java index 83dc82e6f9..41726b4fc5 100644 --- a/src/main/java/gregtech/common/bees/GT_AlleleBeeSpecies.java +++ b/src/main/java/gregtech/common/bees/GT_AlleleBeeSpecies.java @@ -8,9 +8,19 @@ import forestry.apiculture.genetics.alleles.AlleleBeeSpecies; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import java.awt.*; + public class GT_AlleleBeeSpecies extends AlleleBeeSpecies { - public GT_AlleleBeeSpecies(String uid, boolean dominant, String unlocalizedName, String authority, String unlocalizedDescription, IClassification branch, String binomial, int primaryColor, int secondaryColor) { - super(uid, unlocalizedName, authority, unlocalizedDescription, dominant, branch, binomial, primaryColor, secondaryColor); + public GT_AlleleBeeSpecies(String uid, + boolean dominant, + String unlocalizedName, + String authority, + String unlocalizedDescription, + IClassification branch, + String binomial, + Color primaryColor, + Color secondaryColor) { + super(uid, unlocalizedName, authority, unlocalizedDescription, dominant, branch, binomial, primaryColor.getRGB(), secondaryColor.getRGB()); AlleleManager.alleleRegistry.registerAllele(this, EnumBeeChromosome.SPECIES); } diff --git a/src/main/java/gregtech/common/bees/GT_AlleleHelper.java b/src/main/java/gregtech/common/bees/GT_AlleleHelper.java index cb54f5d4a1..e1db4c2ac0 100644 --- a/src/main/java/gregtech/common/bees/GT_AlleleHelper.java +++ b/src/main/java/gregtech/common/bees/GT_AlleleHelper.java @@ -21,7 +21,7 @@ public class GT_AlleleHelper extends AlleleHelper { private static final String modId = Constants.ID; - private Map> alleleMaps = new HashMap<>(); + private Map, Map> alleleMaps = new HashMap<>(); public void init() { if (PluginManager.Module.APICULTURE.isEnabled()) { @@ -114,12 +114,17 @@ public class GT_AlleleHelper extends AlleleHelper { } alleleMaps.put(Boolean.class, booleans); } - + @SuppressWarnings("unchecked") public static void initialisation(){ GT_AlleleHelper helper = new GT_AlleleHelper(); try { - helper.alleleMaps = (Map>) FieldUtils.readField(FieldUtils.getField(AlleleHelper.class,"alleleMaps",true),AlleleHelper.instance,true); + helper.alleleMaps = (Map, Map>) + FieldUtils.readField( + FieldUtils.getField(AlleleHelper.class,"alleleMaps",true), + AlleleHelper.instance, + true + ); } catch (IllegalAccessException e) { e.printStackTrace(); } diff --git a/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java b/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java index 7b61505fc7..ca919e7cf2 100644 --- a/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java +++ b/src/main/java/gregtech/common/bees/GT_Bee_Mutation.java @@ -16,7 +16,7 @@ import java.util.List; public class GT_Bee_Mutation extends BeeMutation { - private float split = 1; + private final float split; public GT_Bee_Mutation(IAlleleBeeSpecies bee0, IAlleleBeeSpecies bee1, IAllele[] result, int chance, float split) { super(bee0, bee1, result, chance); @@ -52,6 +52,7 @@ public class GT_Bee_Mutation extends BeeMutation { return processedChance; } + @SuppressWarnings("unchecked") private float getBasicChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) { float mutationChance = this.getBaseChance(); List mutationConditions = null; @@ -61,7 +62,7 @@ public class GT_Bee_Mutation extends BeeMutation { if (f == null) return mutationChance; try { - mutationConditions = f.get(this) instanceof List ? (List) f.get(this) : null; + mutationConditions = f.get(this) instanceof List ? (List) f.get(this) : null; } catch (IllegalAccessException e) { e.printStackTrace(); } -- cgit From 87abc3b419dfe42fb1c0cf943deaeb2e3037e19c Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Fri, 23 Oct 2020 01:14:15 +0800 Subject: Actually hide filled volumetric flask in NEI Previously this is called too early that many fluid are simply not yet registered. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../java/gregtech/common/items/GT_VolumetricFlask.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java index d0132b1fdd..8fe075ad58 100644 --- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java +++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java @@ -2,6 +2,7 @@ package gregtech.common.items; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.GT_Values; @@ -43,17 +44,17 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain setMaxStackSize(16); setNoRepair(); if (Loader.isModLoaded("NotEnoughItems")) { - for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) { - if (fluid != null) { - ItemStack stack = new ItemStack(this); - setCapacity(stack, getMaxCapacity()); - fill(stack, new FluidStack(fluid, Integer.MAX_VALUE), true); - codechicken.nei.api.API.hideItem(stack); - } - } + hideItemInNEI(); } } + @Optional.Method(modid = "NotEnoughItems") + private void hideItemInNEI() { + codechicken.nei.api.API.addItemFilter( + () -> aStack -> aStack.getItem() == this && this.getFluid(aStack) != null + ); + } + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!world.isRemote && isEmpty(stack) && getMovingObjectPositionFromPlayer(world, player, true) == null) player.openGui(GT_Values.GT, 1010, world, 0, 0, 0); -- cgit From 153ee9bf191586265d846c8f224e64f5fae0a18b Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 25 Oct 2020 03:38:00 +0800 Subject: Move the hide to proper place & use proper api Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/common/items/GT_VolumetricFlask.java | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java index 8fe075ad58..a7bd63f0a6 100644 --- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java +++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java @@ -43,16 +43,6 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain unlocalFlaskName = unlocalized; setMaxStackSize(16); setNoRepair(); - if (Loader.isModLoaded("NotEnoughItems")) { - hideItemInNEI(); - } - } - - @Optional.Method(modid = "NotEnoughItems") - private void hideItemInNEI() { - codechicken.nei.api.API.addItemFilter( - () -> aStack -> aStack.getItem() == this && this.getFluid(aStack) != null - ); } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { -- cgit From 1683c8aa42e2cef678be65dade6b748125a11c06 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 25 Oct 2020 03:41:12 +0800 Subject: Organize import Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/common/items/GT_VolumetricFlask.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java index a7bd63f0a6..5ab6b3395e 100644 --- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java +++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java @@ -1,8 +1,6 @@ package gregtech.common.items; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.GT_Values; -- cgit From 388f542576c2652971c24e9d92922ca94ce256cb Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 28 Oct 2020 22:34:56 +0800 Subject: Fix ore not synced to client in some cases Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../java/gregtech/common/blocks/GT_TileEntity_Ores.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java index 6c4a03420d..b7387f23af 100644 --- a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java @@ -132,7 +132,19 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit public Packet getDescriptionPacket() { if (!this.worldObj.isRemote) { - if ((this.mBlocked == (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord + 1, this.yCoord, this.zCoord)) && (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord - 1, this.yCoord, this.zCoord)) && (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord + 1, this.zCoord)) && (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord - 1, this.zCoord)) && (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord + 1)) && (GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord - 1)) ? 1 : 0) == 0) { + /** + * mBlocked == true means every surrounding block is solid, so this ore is hidden and no need to display it to client + * here we check if surrounding has changed. if yes then send a packet and update the state, otherwise do nothing. + */ + if (this.mBlocked != ( + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord + 1, this.yCoord, this.zCoord) && + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord - 1, this.yCoord, this.zCoord) && + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord + 1, this.zCoord) && + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord - 1, this.zCoord) && + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord + 1) && + GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord - 1) + )) { + this.mBlocked = !this.mBlocked; GT_Values.NW.sendPacketToAllPlayersInRange(this.worldObj, new GT_Packet_Ores(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), this.xCoord, this.zCoord); } } -- cgit From ccc5048f488fb110099efd0bcf9b8f308ba67e6c Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Thu, 29 Oct 2020 01:22:31 +0800 Subject: Fix ore not synced to client in some cases (again) Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java index b7387f23af..2eb100599b 100644 --- a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java @@ -132,19 +132,14 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit public Packet getDescriptionPacket() { if (!this.worldObj.isRemote) { - /** - * mBlocked == true means every surrounding block is solid, so this ore is hidden and no need to display it to client - * here we check if surrounding has changed. if yes then send a packet and update the state, otherwise do nothing. - */ - if (this.mBlocked != ( + if (!(this.mBlocked = ( GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord + 1, this.yCoord, this.zCoord) && GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord - 1, this.yCoord, this.zCoord) && GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord + 1, this.zCoord) && GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord - 1, this.zCoord) && GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord + 1) && GT_Utility.isOpaqueBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord - 1) - )) { - this.mBlocked = !this.mBlocked; + ))) { GT_Values.NW.sendPacketToAllPlayersInRange(this.worldObj, new GT_Packet_Ores(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), this.xCoord, this.zCoord); } } -- cgit