From 4f4741d21efc34cde4b0b7f05a750f7d8f63f2fe Mon Sep 17 00:00:00 2001 From: Caedis Date: Wed, 7 Aug 2024 15:34:52 -0500 Subject: [PATCH] Refactor bauble methods into abstract class (#3) * Refactor some bauble methods into an abstract class * This was needed to stop TC4 from deploading the OG version * remove unneeded clientonly * Add note --- gradle.properties | 10 +-- .../java/baubles/common/BaubleItemBase.java | 59 ++++++++++++++++ src/main/java/baubles/common/Baubles.java | 3 +- .../java/baubles/common/ItemDebugger.java | 67 +++---------------- 4 files changed, 76 insertions(+), 63 deletions(-) create mode 100644 src/main/java/baubles/common/BaubleItemBase.java diff --git a/gradle.properties b/gradle.properties index 4820535..08db25d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ modId = BaublesExpanded # Root package of the mod, used to find various classes in other properties, # mcmod.info substitution, enabling assertions in run tasks, etc. -modGroup = +modGroup = baubles # Whether to use modGroup as the maven publishing group. # Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods. @@ -50,10 +50,10 @@ enableGenericInjection = false # Generate a class with a String field for the mod version named as defined below. # If generateGradleTokenClass is empty or not missing, no such class will be generated. # If gradleTokenVersion is empty or missing, the field will not be present in the class. -generateGradleTokenClass = +generateGradleTokenClass = baubles.Tags # Name of the token containing the project's current version to generate/replace. -gradleTokenVersion = GRADLETOKEN_VERSION +gradleTokenVersion = VERSION # [DEPRECATED] Mod ID replacement token. gradleTokenModId = @@ -70,7 +70,7 @@ gradleTokenGroupName = # The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's # version in @Mod([...], version = VERSION, [...]). # Leave these properties empty to skip individual token replacements. -replaceGradleTokenInFile = Baubles.java +replaceGradleTokenInFile = # In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can # leave this property empty. @@ -102,7 +102,7 @@ mixinsPackage = # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! # This parameter is for legacy compatibility only # Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin -coreModClass = thaumcraft.codechicken.core.launch.DepLoader +coreModClass = # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class # that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! diff --git a/src/main/java/baubles/common/BaubleItemBase.java b/src/main/java/baubles/common/BaubleItemBase.java new file mode 100644 index 0000000..62eb974 --- /dev/null +++ b/src/main/java/baubles/common/BaubleItemBase.java @@ -0,0 +1,59 @@ +package baubles.common; + +import baubles.api.expanded.BaubleItemHelper; +import baubles.api.expanded.IBaubleExpanded; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.List; + + +/** + * To be used to create standalone (i.e can't be used outside a bauble slot) bauble + */ +public abstract class BaubleItemBase extends Item implements IBaubleExpanded { + + public BaubleItemBase(){ + super(); + setCreativeTab(CreativeTabs.tabTools); + this.setMaxStackSize(1); + } + + @Override + public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player) { + return BaubleItemHelper.onBaubleRightClick(itemStackIn, worldIn, player); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean debug) { + BaubleItemHelper.addSlotInformation(tooltip, getBaubleTypes(stack)); + } + + @Override + public boolean hasEffect(ItemStack itemStack, int a) { + return true; + } + + @Override + public boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + public void onWornTick(ItemStack itemStack, EntityLivingBase player) {} + + @Override + public void onEquipped(ItemStack itemStack, EntityLivingBase player) {} + + @Override + public void onUnequipped(ItemStack itemStack, EntityLivingBase player) {} +} diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 525f938..eb7ead2 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -2,6 +2,7 @@ package baubles.common; import java.io.File; +import baubles.Tags; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -25,7 +26,7 @@ public class Baubles { public static final String MODID = "Baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "GRADLETOKEN_VERSION"; + public static final String VERSION = Tags.VERSION; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/ItemDebugger.java b/src/main/java/baubles/common/ItemDebugger.java index fdee953..8944ad7 100644 --- a/src/main/java/baubles/common/ItemDebugger.java +++ b/src/main/java/baubles/common/ItemDebugger.java @@ -4,31 +4,26 @@ import java.util.List; import baubles.api.BaubleType; import baubles.api.expanded.BaubleExpandedSlots; -import baubles.api.expanded.BaubleItemHelper; -import baubles.api.expanded.IBaubleExpanded; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import net.minecraft.world.World; -public class ItemDebugger extends Item implements IBaubleExpanded { +public class ItemDebugger extends BaubleItemBase { + + private IIcon[] icons; public ItemDebugger() { super(); - this.setMaxStackSize(1); this.setHasSubtypes(true); - setCreativeTab(BaublesConfig.hideDebugItem ? null : CreativeTabs.tabTools); + if (BaublesConfig.hideDebugItem){ + setCreativeTab(null); + } } - @SideOnly(Side.CLIENT) - private IIcon[] icons; - @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister ir) { @@ -38,14 +33,12 @@ public class ItemDebugger extends Item implements IBaubleExpanded { } } - @SideOnly(Side.CLIENT) - @Override - public IIcon getIconFromDamage(int meta) { - return icons[meta >= icons.length ? 0 : meta]; - } + @Override + public IIcon getIconFromDamage(int meta) { + return icons[meta >= icons.length ? 0 : meta]; + } @SuppressWarnings({"unchecked", "rawtypes"}) - @SideOnly(Side.CLIENT) @Override public void getSubItems(Item item, CreativeTabs tab, List list) { for(int i = 0; i < icons.length; i++) { @@ -53,11 +46,6 @@ public class ItemDebugger extends Item implements IBaubleExpanded { } } - @Override - public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player) { - return BaubleItemHelper.onBaubleRightClick(itemStackIn, worldIn, player); - } - @Override public String[] getBaubleTypes(ItemStack itemStack) { String type; @@ -75,41 +63,6 @@ public class ItemDebugger extends Item implements IBaubleExpanded { return null; } - @SuppressWarnings({"unchecked", "rawtypes"}) - @SideOnly(Side.CLIENT) - @Override - public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean debug) { - BaubleItemHelper.addSlotInformation(tooltip, getBaubleTypes(stack)); - } - - @Override - public void onWornTick(ItemStack itemStack, EntityLivingBase player) { - } - - @Override - public boolean hasEffect(ItemStack itemStack, int a) { - return true; - } - - @Override - public void onEquipped(ItemStack itemStack, EntityLivingBase player) { - } - - @Override - public void onUnequipped(ItemStack itemStack, EntityLivingBase player) { - } - - @Override - public boolean canEquip(ItemStack itemStack, EntityLivingBase player) { - return true; - } - - @Override - public boolean canUnequip(ItemStack itemStack, EntityLivingBase player) { - return true; - } - - @SideOnly(Side.CLIENT) public IIcon getBackgroundIconForSlotType(String type) { if(type != null && BaubleExpandedSlots.isTypeRegistered(type)) { return icons[BaubleExpandedSlots.getIndexOfTypeInRegisteredTypes(type)];