From 3c44fc56241c62972e7d5a36b540dad9c2c2b2cc Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Mon, 20 Jan 2020 15:28:22 -0600 Subject: [PATCH] Moved several packaged into WumpleUtil --- .../com/wumple/cannycomposter/Reference.java | 8 +- .../com/wumple/util/config/ConfigUtil.java | 107 ------ .../wumple/util/config/MatchingConfig.java | 259 -------------- .../com/wumple/util/config/NameKeyDebug.java | 154 -------- .../java/com/wumple/util/config/NameKeys.java | 227 ------------ .../wumple/util/xcomposter/XBoneMealItem.java | 248 ------------- .../util/xcomposter/XComposterBlock.java | 331 ------------------ src/main/resources/META-INF/mods.toml | 34 +- version.properties | 4 +- 9 files changed, 23 insertions(+), 1349 deletions(-) delete mode 100755 src/main/java/com/wumple/util/config/ConfigUtil.java delete mode 100755 src/main/java/com/wumple/util/config/MatchingConfig.java delete mode 100755 src/main/java/com/wumple/util/config/NameKeyDebug.java delete mode 100755 src/main/java/com/wumple/util/config/NameKeys.java delete mode 100755 src/main/java/com/wumple/util/xcomposter/XBoneMealItem.java delete mode 100755 src/main/java/com/wumple/util/xcomposter/XComposterBlock.java diff --git a/src/main/java/com/wumple/cannycomposter/Reference.java b/src/main/java/com/wumple/cannycomposter/Reference.java index f9e3b1b..972c53d 100755 --- a/src/main/java/com/wumple/cannycomposter/Reference.java +++ b/src/main/java/com/wumple/cannycomposter/Reference.java @@ -4,7 +4,7 @@ public class Reference { // Mod Constants - /* + // /* public static final String MOD_ID = "@MOD_ID@"; public static final String MOD_NAME = "@MOD_NAME@"; public static final String BUILD = "@BUILD@"; @@ -12,9 +12,9 @@ public class Reference public static final String DEPENDENCIES = "@DEPENDENCIES@"; public static final String UPDATEJSON = "@UPDATEJSON@"; public static final String FINGERPRINT = "@FINGERPRINT@"; - */ + // */ - // /* + /* // debugger settings since no Gradle string replacement public static final String MOD_ID = "cannycomposter"; public static final String MOD_NAME = "CannyComposter"; @@ -23,6 +23,6 @@ public class Reference public static final String DEPENDENCIES = "required-after:wumpleutil@[3.2,)"; public static final String UPDATEJSON = "update.json"; public static final String FINGERPRINT = ""; - // */ + */ } diff --git a/src/main/java/com/wumple/util/config/ConfigUtil.java b/src/main/java/com/wumple/util/config/ConfigUtil.java deleted file mode 100755 index ce10ea7..0000000 --- a/src/main/java/com/wumple/util/config/ConfigUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.wumple.util.config; - -import java.util.Arrays; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.electronwill.nightconfig.core.Config; -import com.electronwill.nightconfig.toml.TomlFormat; - -import net.minecraftforge.common.ForgeConfigSpec; - -public class ConfigUtil -{ - // ------------------------------------------------------------------------ - // copy values from a Config object into a Map for actual usage - - public static void handlePairConfig(Config config, Map map) - { - config.entrySet().forEach((e) -> { - map.put(e.getKey(), e.getValue()); - }); - } - - public static void handlePairConfig(Config config, Consumer func) - { - config.entrySet().forEach((e) -> { - func.accept(e); - }); - } - - public static void handlePairConfig(Config config, BiConsumer func) - { - handlePairConfig(config, (e) -> { - func.accept(e.getKey(), e.getValue()); - }); - } - - public static void handlePairConfig(Config config, Pattern pattern, BiConsumer func) - { - handlePairConfig(config, (e) -> { - Matcher m = pattern.matcher(e.getKey()); - if (m.matches()) - { - func.accept(e, m); - } - }); - } - - // ------------------------------------------------------------------------ - // Search a map containing overridable config-like values - - /// Search a map for values, but fail if found with falseValue - public static boolean containsNotFalseValue(Map map, String key, V falseValue) - { - V value = map.get(key); - - if (value != null) - { - if (value != falseValue) - { - return true; - } - } - - return false; - } - - /// Search a map for values, but return falseValue if not found - public static V getOrFalseValue(Map map, String key, V falseValue) - { - V value = map.get(key); - - if (value != null) - { - return value; - } - - return falseValue; - } - - // ------------------------------------------------------------------------ - - /// shortcut to build a config value for a key/value set - public static ForgeConfigSpec.ConfigValue buildSet(ForgeConfigSpec.Builder builder, String name, String comment) - { - // Example from https://github.com/gigaherz/Survivalist/blob/1.14/src/main/java/gigaherz/survivalist/ConfigManager.java#L131 - ForgeConfigSpec.ConfigValue value = builder - .comment(comment) - .define(Arrays.asList(name), - () -> Config.of(TomlFormat.instance()), - x -> true, - Config.class); - - return value; - } - - /// make r process config set c, clear the mirrored map, and read c into the mirrored map - public static void handleConfigSet(Config c, Consumer r, Map map) - { - r.accept(c); - map.clear(); - ConfigUtil.handlePairConfig(c, map); - } -} diff --git a/src/main/java/com/wumple/util/config/MatchingConfig.java b/src/main/java/com/wumple/util/config/MatchingConfig.java deleted file mode 100755 index 2a07e1a..0000000 --- a/src/main/java/com/wumple/util/config/MatchingConfig.java +++ /dev/null @@ -1,259 +0,0 @@ -package com.wumple.util.config; - -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import com.wumple.util.base.misc.Util; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -//TODO import com.wumple.util.adapter.IThing; - -/* - * Wrapper around Forge HashMap configs for (itemstack, item, entity, string)->value configs - */ -public class MatchingConfig extends NameKeys -{ - protected final Map map; - public final T FALSE_VALUE; - - public MatchingConfig(Map configIn, T falseValueIn) - { - map = configIn; - FALSE_VALUE = falseValueIn; - } - - /* - * If using this class and including default config properties, still need to - * save config with them - looks easier to add defaults to config then re-scan - * config into map afterward - */ - - // ---------------------------------------------------------------------- - // Add default properties to config - - // --- add by String - - public boolean addDefaultProperty(String name, T amountIn) - { - if (name == null) - { - name = ""; - } - - map.putIfAbsent(name, amountIn); - - return true; - } - - public boolean addDefaultProperty(String[] items, T amountIn) - { - boolean success = true; - - for (String item : items) - { - success &= addDefaultProperty(item, amountIn); - } - - return success; - } - - // --- add by Item - - public boolean addDefaultProperty(Item item, T amount) - { - // check for null Item in case another mod removes a vanilla item - if (item != null) - { - ResourceLocation resLoc = item.getRegistryName(); - if (resLoc != null) - { - String name = resLoc.toString(); - return addDefaultProperty(name, amount); - } - } - - return false; - } - - public boolean addDefaultProperty(Item item, String backup, T amount) - { - String name = backup; - - // check for null Item in case another mod removes a vanilla item - if (item != null) - { - ResourceLocation resLoc = item.getRegistryName(); - if (resLoc != null) - { - name = resLoc.toString(); - } - } - - return addDefaultProperty(name, amount); - } - - // ---------------------------------------------------------------------- - // Get value for different types - - protected T getProperty(String key) - { - T amount = null; - - if ((key != null) && map.containsKey(key)) - { - amount = map.get(key); - } - - return amount; - } - - @Nullable - protected T getProperty(List keys) - { - T amount = null; - - for (String key : keys) - { - amount = getProperty(key); - if (amount != null) - { - break; - } - } - - return amount; - } - - /** - * Get the highest priority value we match for stack Checks all keys for stack - expands to multiple keys in defined order: id@meta, id, minecraft:food - * - * @return highest priority value for stack, or null if key not found (not FALSE_VALUE) - */ - @Nullable - public T getProperty(ItemStack itemStack) - { - return getProperty(getNameKeys(itemStack)); - } - - @Nullable - public T getProperty(Item it) - { - return getProperty(getNameKeys(it)); - } - - @Nullable - public T getProperty(Block it) - { - return getProperty(getNameKeys(it)); - } - - @Nullable - public T getProperty(Entity entity) - { - return getProperty(getNameKeys(entity)); - } - - @Nullable - public T getProperty(TileEntity it) - { - return getProperty(getNameKeys(it)); - } - - /* - @Nullable - public T getProperty(IThing it) - { - return getProperty(it.getNameKeys()); - } - */ - - @Nullable - public T getProperty(ResourceLocation loc) - { - String key = (loc == null) ? null : loc.toString(); - return getProperty(key); - } - - // ---------------------------------------------------------------------- - // get value for different types - - /* - * Get the highest priority value we match for stack Checks all keys for stack - expands to multiple keys in defined order: id@meta, id, minecraft:food - * - * @return highest priority value for stack, or FALSE_VALUE if key not found - */ - public T getValue(ItemStack stack) - { - return Util.getValueOrDefault(getProperty(stack), FALSE_VALUE); - } - - public T getValue(Entity entity) - { - return Util.getValueOrDefault(getProperty(entity), FALSE_VALUE); - } - - public T getValue(TileEntity entity) - { - return Util.getValueOrDefault(getProperty(entity), FALSE_VALUE); - } - - /* - public T getValue(IThing it) - { - return Util.getValueOrDefault(getProperty(it), FALSE_VALUE); - } - */ - - public T getValue(ResourceLocation loc) - { - return Util.getValueOrDefault(getProperty(loc), FALSE_VALUE); - } - - // ---------------------------------------------------------------------- - // check for non-FALSE_VALUE for different types - - /** - * Does thing not match FALSE_VALUE? aka does thing have no entry or the default value as the entry? - * - * @returns true if thing doesn't match FALSE_VALUE, false if it does - */ - public boolean doesIt(T value) - { - return value != FALSE_VALUE; - } - - public boolean doesIt(ItemStack stack) - { - return doesIt(getValue(stack)); - } - - public boolean doesIt(Entity entity) - { - return doesIt(getValue(entity)); - } - - public boolean doesIt(TileEntity entity) - { - return doesIt(getValue(entity)); - } - - /* - public boolean doesIt(IThing it) - { - return doesIt(getValue(it)); - } - */ - - public boolean doesIt(ResourceLocation loc) - { - return getValue(loc) != FALSE_VALUE; - } -} diff --git a/src/main/java/com/wumple/util/config/NameKeyDebug.java b/src/main/java/com/wumple/util/config/NameKeyDebug.java deleted file mode 100755 index 5bd4b48..0000000 --- a/src/main/java/com/wumple/util/config/NameKeyDebug.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.wumple.util.config; - -import java.util.ArrayList; - -import com.wumple.cannycomposter.ConfigManager; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.EntityRayTraceResult; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; - -@EventBusSubscriber -public class NameKeyDebug -{ - public static boolean isDebugging() - { - return ConfigManager.Debugging.debug.get(); - } - - @SubscribeEvent - @OnlyIn(Dist.CLIENT) - public static void onItemTooltip(ItemTooltipEvent event) - { - if (isDebugging()) - { - ItemStack itemStack = event.getItemStack(); - ArrayList nameKeys = NameKeys.getNameKeys(itemStack); - - if (nameKeys != null) - { - for (String nameKey : nameKeys) - { - event.getToolTip().add(new TranslationTextComponent("misc.wumpleutil.tooltip.advanced.namekey.itemstack", nameKey)); - } - } - } - } - - /* - * Draw debug screen extras - */ - @SubscribeEvent(priority = EventPriority.HIGH) - @OnlyIn(Dist.CLIENT) - static public void onDrawOverlay(final RenderGameOverlayEvent.Text e) - { - if (isDebugging()) - { - Minecraft mc = Minecraft.getInstance(); - if (mc.gameSettings.showDebugInfo == true) - { - e.getRight().add(""); - e.getRight().add(I18n.format("misc.wumpleutil.debug.namekey.title")); - addEntityDebug(e); - addTileEntityDebug(e); - addBlockDebug(e); - } - } - } - - /* - * Add Entity debug text to debug screen if looking at Entity - */ - - @OnlyIn(Dist.CLIENT) - public static void addEntityDebug(RenderGameOverlayEvent.Text e) - { - Minecraft mc = Minecraft.getInstance(); - - if (mc.objectMouseOver != null && mc.objectMouseOver.getType() == RayTraceResult.Type.ENTITY) - { - final EntityRayTraceResult rayTraceResult = (EntityRayTraceResult) mc.objectMouseOver; - Entity entity = rayTraceResult.getEntity(); - - ArrayList nameKeys = NameKeys.getNameKeys(entity); - - if (nameKeys != null) - { - for (String nameKey : nameKeys) - { - e.getRight().add(I18n.format("misc.wumpleutil.debug.namekey.entity", nameKey)); - } - } - } - } - - /* - * Add TileEntity debug text to debug screen if looking at Block with a TileEntity - */ - @OnlyIn(Dist.CLIENT) - public static void addTileEntityDebug(RenderGameOverlayEvent.Text e) - { - Minecraft mc = Minecraft.getInstance(); - - if (mc.objectMouseOver != null && mc.objectMouseOver.getType() == RayTraceResult.Type.BLOCK) - { - final BlockRayTraceResult rayTraceResult = (BlockRayTraceResult) mc.objectMouseOver; - BlockPos blockpos = rayTraceResult.getPos(); - - TileEntity te = (blockpos == null) ? null : mc.world.getTileEntity(blockpos); - - ArrayList nameKeys = NameKeys.getNameKeys(te); - - if (nameKeys != null) - { - for (String nameKey : nameKeys) - { - e.getRight().add(I18n.format("misc.wumpleutil.debug.namekey.tileentity", nameKey)); - } - } - } - } - - /* - * Add TileEntity debug text to debug screen if looking at Block - */ - @OnlyIn(Dist.CLIENT) - public static void addBlockDebug(RenderGameOverlayEvent.Text e) - { - Minecraft mc = Minecraft.getInstance(); - - if (mc.objectMouseOver != null && mc.objectMouseOver.getType() == RayTraceResult.Type.BLOCK) - { - final BlockRayTraceResult rayTraceResult = (BlockRayTraceResult) mc.objectMouseOver; - BlockPos blockpos = rayTraceResult.getPos(); - - Block block = (blockpos == null) ? null : mc.world.getBlockState(blockpos).getBlock(); - - ArrayList nameKeys = NameKeys.getNameKeys(block); - - if (nameKeys != null) - { - for (String nameKey : nameKeys) - { - e.getRight().add(I18n.format("misc.wumpleutil.debug.namekey.block", nameKey)); - } - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/wumple/util/config/NameKeys.java b/src/main/java/com/wumple/util/config/NameKeys.java deleted file mode 100755 index 568feb1..0000000 --- a/src/main/java/com/wumple/util/config/NameKeys.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.wumple.util.config; - -import java.util.ArrayList; -import java.util.Collection; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.state.IProperty; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.EntityTypeTags; -import net.minecraft.tags.ItemTags; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.registries.IForgeRegistryEntry; - -/* - * Generate a set of strings that represent the queried object - */ -public class NameKeys -{ - // ---------------------------------------------------------------------- - // Utility - - /** - * Generate a set of strings that represent the queried ItemStack - * @see TypeIdentifier for opposite direction but similiar code - * @param itemStack for which to get namekeys for lookup - * @return namekeys to search config for, in order - */ - static public ArrayList getNameKeys(ItemStack itemStack) - { - ArrayList nameKeys = new ArrayList(); - - if (itemStack == null) - { - return nameKeys; - } - - Item item = itemStack.getItem(); - - addNameKeysResLoc(nameKeys, item); - addNameKeysItemTags(nameKeys, item); - addNameKeysObject(nameKeys, (Object)itemStack); - addNameKeysObject(nameKeys, (Object)item); - - return nameKeys; - } - - static public ArrayList getNameKeys(Item item) - { - ArrayList nameKeys = new ArrayList(); - - if (item == null) - { - return nameKeys; - } - - addNameKeysResLoc(nameKeys, item); - addNameKeysItemTags(nameKeys, item); - addNameKeysObject(nameKeys, (Object)item); - - return nameKeys; - } - - static public ArrayList getNameKeys(Block block) - { - ArrayList nameKeys = new ArrayList(); - - addNameKeysResLoc(nameKeys, block); - addNameKeysBlockTags(nameKeys, block); - addNameKeysObject(nameKeys, (Object)block); - - return nameKeys; - } - - static public ArrayList getNameKeys(Entity entity) - { - ArrayList nameKeys = new ArrayList(); - - if (entity == null) - { - return nameKeys; - } - - addNameKeysResLoc(nameKeys, entity.getType()); - addNameKeysEntityTags(nameKeys, entity); - addNameKeysObject(nameKeys, (Object)entity.getType()); - - return nameKeys; - } - - static public ArrayList getNameKeys(TileEntity entity) - { - ArrayList nameKeys = new ArrayList(); - - if (entity == null) - { - return nameKeys; - } - - // OLD: addNameKeysProperty(nameKeys, entity, BlockCrops.AGE); - addNameKeysResLoc(nameKeys, entity.getType()); - addNameKeysObject(nameKeys, (Object)entity); - - return nameKeys; - } - - // ------------------------------------------------------------------------ - // builders - - static public ArrayList addNameKeysResLoc(ArrayList nameKeys, IForgeRegistryEntry entry) - { - String name = (entry == null) ? null : entry.getRegistryName().toString(); - - if (name != null) - { - nameKeys.add(name); - } - - return nameKeys; - } - - static public > ArrayList addNameKeysProperty(ArrayList nameKeys, TileEntity te, IProperty property) - { - ResourceLocation loc = (te == null) ? null : te.getType().getRegistryName(); - if (loc == null) - { - return nameKeys; - } - - BlockPos pos = te.getPos(); - World world = te.getWorld(); - BlockState state = (world != null) ? world.getBlockState(pos) : null; - Collection> props = (state != null) ? state.getProperties() : null; - if ((props != null) && (props.contains(property))) - { - T value = state.get(property); - nameKeys.add(loc.toString() + "[" + property.getName() + "=" + value.toString() + "]" ); - } - - return nameKeys; - } - - static public ArrayList addNameKeysItemTags(ArrayList nameKeys, Item item) - { - if (item != null) - { - Collection tags = ItemTags.getCollection().getOwningTags(item); - - for (ResourceLocation tag : tags) - { - nameKeys.add("#" + tag.toString()); - } - } - - return nameKeys; - } - - static public ArrayList addNameKeysBlockTags(ArrayList nameKeys, Block block) - { - Collection tags = BlockTags.getCollection().getOwningTags(block); - - for (ResourceLocation tag : tags) - { - nameKeys.add("#" + tag.toString()); - } - - return nameKeys; - } - - static public ArrayList addNameKeysEntityTags(ArrayList nameKeys, Entity it) - { - Collection tags = EntityTypeTags.getCollection().getOwningTags(it.getType()); - - for (ResourceLocation tag : tags) - { - nameKeys.add("#" + tag.toString()); - } - - return nameKeys; - } - - static protected boolean ConfigAddClassNames() - { - // TODO - return false; - } - - static public ArrayList addNameKeysObject(ArrayList nameKeys, Object object) - { - addNameKeysSpecial(nameKeys, object); - - if (ConfigAddClassNames()) - { - addNameKeysClasses(nameKeys, object); - } - - return nameKeys; - } - - static public ArrayList addNameKeysClasses(ArrayList nameKeys, Object object) - { - // class names for dynamic matching - Class c = object.getClass(); - while (c != null) - { - String classname = c.getName(); - nameKeys.add(classname); - c = c.getSuperclass(); - } - - return nameKeys; - } - - static public ArrayList addNameKeysSpecial(ArrayList nameKeys, Object object) - { - // special tags for backwards compatibility - // no longer needed! - - return nameKeys; - } -} diff --git a/src/main/java/com/wumple/util/xcomposter/XBoneMealItem.java b/src/main/java/com/wumple/util/xcomposter/XBoneMealItem.java deleted file mode 100755 index 1d08283..0000000 --- a/src/main/java/com/wumple/util/xcomposter/XBoneMealItem.java +++ /dev/null @@ -1,248 +0,0 @@ -package com.wumple.util.xcomposter; - -import javax.annotation.Nullable; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.DeadCoralWallFanBlock; -import net.minecraft.block.IGrowable; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BoneMealItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUseContext; -import net.minecraft.particles.IParticleData; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.server.ServerWorld; - -/* - * Extendible version of BoneMealItem - * Replaces static methods with non-static, makes private parts protected, and splits methods - * Forced to copy parts of base class, unfortunately - */ -public class XBoneMealItem extends BoneMealItem -{ - protected static final int NUM_PARTICLES = 15; - - public XBoneMealItem(Item.Properties properties) - { - super(properties); - } - - /** - * Called when this item is used when targeting a Block - */ - public ActionResultType onItemUse(ItemUseContext context) - { - World world = context.getWorld(); - BlockPos blockpos = context.getPos(); - BlockPos blockpos1 = blockpos.offset(context.getFace()); - - if (applyEnrichment(context.getItem(), world, blockpos, context.getPlayer())) - { - /* - if (!world.isRemote) - { - world.playEvent(2005, blockpos, 0); - } - */ - - return ActionResultType.SUCCESS; - } - else - { - BlockState blockstate = world.getBlockState(blockpos); - boolean flag = blockstate.func_224755_d(world, blockpos, context.getFace()); - if (flag && growSomeSeagrass(context.getItem(), world, blockpos1, context.getFace())) - { - /* - if (!world.isRemote) - { - world.playEvent(2005, blockpos1, 0); - } - */ - - return ActionResultType.SUCCESS; - } - else - { - return ActionResultType.PASS; - } - } - } - - /* - @Deprecated //Forge: Use Player/Hand version - public static boolean applyEnrichment(ItemStack stack, World worldIn, BlockPos pos) - { - if (worldIn instanceof net.minecraft.world.server.ServerWorld) - return applyEnrichment(stack, worldIn, pos, net.minecraftforge.common.util.FakePlayerFactory - .getMinecraft((net.minecraft.world.server.ServerWorld) worldIn)); - return false; - } - */ - - protected boolean tryUse(World worldIn) - { - return true; - } - - protected void spawnSuccessParticles(World worldIn, BlockPos pos) - { - if (!worldIn.isRemote) - { - spawnParticles(ParticleTypes.HAPPY_VILLAGER, (ServerWorld)worldIn, pos, 0); - } - } - - protected void spawnTryFailureParticles(World worldIn, BlockPos pos) - { - - } - - public boolean applyEnrichment(ItemStack stack, World worldIn, BlockPos pos, PlayerEntity player) - { - BlockState blockstate = worldIn.getBlockState(pos); - int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, pos, blockstate, stack); - if (hook != 0) - return hook > 0; - if (blockstate.getBlock() instanceof IGrowable) - { - IGrowable igrowable = (IGrowable) blockstate.getBlock(); - if (igrowable.canGrow(worldIn, pos, blockstate, worldIn.isRemote)) - { - if (!worldIn.isRemote) - { - if (tryUse(worldIn)) - { - if (igrowable.canUseBonemeal(worldIn, worldIn.rand, pos, blockstate)) - { - igrowable.grow(worldIn, worldIn.rand, pos, blockstate); - } - - stack.shrink(1); - spawnSuccessParticles(worldIn, pos); - return true; - } - else - { - stack.shrink(1); - spawnTryFailureParticles(worldIn, pos); - } - } - - } - } - - return false; - } - - public boolean growSomeSeagrass(ItemStack stack, World worldIn, BlockPos pos, @Nullable Direction side) - { - if (worldIn.getBlockState(pos).getBlock() == Blocks.WATER && worldIn.getFluidState(pos).getLevel() == 8) - { - if (!worldIn.isRemote) - { - if (!tryUse(worldIn)) - { - stack.shrink(1); - spawnTryFailureParticles(worldIn, pos); - return false; - } - - label79: for (int i = 0; i < 128; ++i) - { - BlockPos blockpos = pos; - Biome biome = worldIn.getBiome(pos); - BlockState blockstate = Blocks.SEAGRASS.getDefaultState(); - - for (int j = 0; j < i / 16; ++j) - { - blockpos = blockpos.add(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, - random.nextInt(3) - 1); - biome = worldIn.getBiome(blockpos); - if (worldIn.getBlockState(blockpos).func_224756_o(worldIn, blockpos)) - { - continue label79; - } - } - - // FORGE: Use BiomeDictionary here to allow modded warm ocean biomes to spawn coral from bonemeal - if (net.minecraftforge.common.BiomeDictionary.hasType(biome, - net.minecraftforge.common.BiomeDictionary.Type.OCEAN) - && net.minecraftforge.common.BiomeDictionary.hasType(biome, - net.minecraftforge.common.BiomeDictionary.Type.HOT)) - { - if (i == 0 && side != null && side.getAxis().isHorizontal()) - { - blockstate = BlockTags.WALL_CORALS.getRandomElement(worldIn.rand).getDefaultState() - .with(DeadCoralWallFanBlock.FACING, side); - } - else if (random.nextInt(4) == 0) - { - blockstate = BlockTags.UNDERWATER_BONEMEALS.getRandomElement(random).getDefaultState(); - } - } - - if (blockstate.getBlock().isIn(BlockTags.WALL_CORALS)) - { - for (int k = 0; !blockstate.isValidPosition(worldIn, blockpos) && k < 4; ++k) - { - blockstate = blockstate.with(DeadCoralWallFanBlock.FACING, - Direction.Plane.HORIZONTAL.random(random)); - } - } - - if (blockstate.isValidPosition(worldIn, blockpos)) - { - BlockState blockstate1 = worldIn.getBlockState(blockpos); - if (blockstate1.getBlock() == Blocks.WATER && worldIn.getFluidState(blockpos).getLevel() == 8) - { - worldIn.setBlockState(blockpos, blockstate, 3); - } - else if (blockstate1.getBlock() == Blocks.SEAGRASS && random.nextInt(10) == 0) - { - ((IGrowable) Blocks.SEAGRASS).grow(worldIn, random, blockpos, blockstate1); - } - } - } - - stack.shrink(1); - spawnSuccessParticles(worldIn, pos); - } - - return true; - } - else - { - return false; - } - } - - public void spawnParticles(T particleType, ServerWorld worldIn, BlockPos posIn, int data) - { - if (data == 0) - { - data = NUM_PARTICLES; - } - - BlockState blockstate = worldIn.getBlockState(posIn); - if (!blockstate.isAir(worldIn, posIn)) - { - double d0 = random.nextGaussian() * 0.02D; - double d1 = random.nextGaussian() * 0.02D; - double d2 = random.nextGaussian() * 0.02D; - double x = posIn.getX(); - double y = posIn.getY() + blockstate.getShape(worldIn, posIn).getEnd(Direction.Axis.Y); - double z = posIn.getZ(); - worldIn.spawnParticle(particleType, x, y, z, data, d0, d1, d2, 0.5D); - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/wumple/util/xcomposter/XComposterBlock.java b/src/main/java/com/wumple/util/xcomposter/XComposterBlock.java deleted file mode 100755 index 72d76e0..0000000 --- a/src/main/java/com/wumple/util/xcomposter/XComposterBlock.java +++ /dev/null @@ -1,331 +0,0 @@ -package com.wumple.util.xcomposter; - -import javax.annotation.Nullable; - -import com.wumple.util.misc.TimeUtil; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComposterBlock; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.Material; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; - -/* - * Extendible version of ComposterBlock - * Replaces static methods with non-static, makes private parts protected, and splits methods - * Forced to copy parts of base class, unfortunately - */ -public class XComposterBlock extends ComposterBlock -{ - public XComposterBlock() - { - super(Block.Properties.create(Material.WOOD).hardnessAndResistance(0.6F).sound(SoundType.WOOD)); - } - - public XComposterBlock(Block.Properties properties) - { - super(properties); - } - - // ------------------------------------------------------------------------ - // For extension - - protected boolean isCompostable(ItemStack itemstack) - { - return CHANCES.containsKey(itemstack.getItem()); - } - - protected float getCompostLevelOf(ItemStack itemstack) - { - return CHANCES.getFloat(itemstack.getItem()); - } - - protected ItemStack makeCompost() - { - return new ItemStack(Items.BONE_MEAL); - } - - protected int getWaitTicks(IWorld worldIn) - { - return TimeUtil.TICKS_PER_SECOND; - } - - // ------------------------------------------------------------------------ - // From ComposterBlock - - @Override - public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, - BlockRayTraceResult hit) - { - int i = state.get(LEVEL); - ItemStack itemstack = player.getHeldItem(handIn); - if (i < 8 && isCompostable(itemstack)) - { - if (i < 7 && !worldIn.isRemote) - { - boolean flag = addItem(state, worldIn, pos, itemstack); - worldIn.playEvent(1500, pos, flag ? 1 : 0); - if (!player.abilities.isCreativeMode) - { - itemstack.shrink(1); - } - } - - return true; - } - else if (i == 8) - { - if (!worldIn.isRemote) - { - float f = 0.7F; - double d0 = (double) (worldIn.rand.nextFloat() * f) + (double) 0.15F; - double d1 = (double) (worldIn.rand.nextFloat() * f) + (double) 0.060000002F + 0.6D; - double d2 = (double) (worldIn.rand.nextFloat() * f) + (double) 0.15F; - ItemEntity itementity = new ItemEntity(worldIn, (double) pos.getX() + d0, (double) pos.getY() + d1, - (double) pos.getZ() + d2, makeCompost()); - itementity.setDefaultPickupDelay(); - worldIn.addEntity(itementity); - } - - clear(state, worldIn, pos); - worldIn.playSound((PlayerEntity) null, pos, SoundEvents.BLOCK_COMPOSTER_EMPTY, SoundCategory.BLOCKS, 1.0F, - 1.0F); - return true; - } - else - { - return false; - } - } - - protected boolean addItem(BlockState blockstateIn, IWorld worldIn, BlockPos posIn, ItemStack stackIn) - { - int i = blockstateIn.get(LEVEL); - float f = getCompostLevelOf(stackIn); - if ((i != 0 || !(f > 0.0F)) && !(worldIn.getRandom().nextDouble() < (double) f)) - { - return false; - } - else - { - int j = i + 1; - worldIn.setBlockState(posIn, blockstateIn.with(LEVEL, Integer.valueOf(j)), 3); - if (j == 7) - { - worldIn.getPendingBlockTicks().scheduleTick(posIn, blockstateIn.getBlock(), getWaitTicks(worldIn)); - } - - return true; - } - } - - protected void clear(BlockState p_220294_0_, IWorld p_220294_1_, BlockPos p_220294_2_) - { - p_220294_1_.setBlockState(p_220294_2_, p_220294_0_.with(LEVEL, Integer.valueOf(0)), 3); - } - - // ------------------------------------------------------------------------ - // ARG no access to private inner classes of ComposterBlock, so re-implement new version here - - @Override - public ISidedInventory createInventory(BlockState p_219966_1_, IWorld p_219966_2_, BlockPos p_219966_3_) - { - int i = p_219966_1_.get(LEVEL); - if (i == 8) - { - return new XComposterBlock.XFullInventory(p_219966_1_, p_219966_2_, p_219966_3_, - new ItemStack(Items.BONE_MEAL)); - } - else - { - return (ISidedInventory) (i < 7 - ? new XComposterBlock.XPartialInventory(p_219966_1_, p_219966_2_, p_219966_3_) - : new XComposterBlock.XEmptyInventory()); - } - } - - static class XEmptyInventory extends Inventory implements ISidedInventory - { - public XEmptyInventory() - { - super(0); - } - - public int[] getSlotsForFace(Direction side) - { - return new int[0]; - } - - /** - * Returns true if automation can insert the given item in the given slot from - * the given side. - */ - public boolean canInsertItem(int index, ItemStack itemStackIn, @Nullable Direction direction) - { - return false; - } - - /** - * Returns true if automation can extract the given item in the given slot from - * the given side. - */ - public boolean canExtractItem(int index, ItemStack stack, Direction direction) - { - return false; - } - } - - static protected class XFullInventory extends Inventory implements ISidedInventory - { - private final BlockState state; - private final IWorld world; - private final BlockPos pos; - private boolean extracted; - - public XFullInventory(BlockState p_i50463_1_, IWorld p_i50463_2_, BlockPos p_i50463_3_, ItemStack p_i50463_4_) - { - super(p_i50463_4_); - this.state = p_i50463_1_; - this.world = p_i50463_2_; - this.pos = p_i50463_3_; - } - - /** - * Returns the maximum stack size for a inventory slot. Seems to always be 64, - * possibly will be extended. - */ - public int getInventoryStackLimit() - { - return 1; - } - - public int[] getSlotsForFace(Direction side) - { - return side == Direction.DOWN ? new int[] { 0 } : new int[0]; - } - - /** - * Returns true if automation can insert the given item in the given slot from - * the given side. - */ - public boolean canInsertItem(int index, ItemStack itemStackIn, @Nullable Direction direction) - { - return false; - } - - /** - * Returns true if automation can extract the given item in the given slot from - * the given side. - */ - public boolean canExtractItem(int index, ItemStack stack, Direction direction) - { - return !this.extracted && direction == Direction.DOWN && stack.getItem() == Items.BONE_MEAL; - } - - /** - * For tile entities, ensures the chunk containing the tile entity is saved to - * disk later - the game won't think it hasn't changed and skip it. - */ - public void markDirty() - { - Block block = this.world.getBlockState(pos).getBlock(); - if (block instanceof XComposterBlock) - { - XComposterBlock xblock = (XComposterBlock)block; - xblock.clear(this.state, this.world, this.pos); - } - this.extracted = true; - } - } - - static class XPartialInventory extends Inventory implements ISidedInventory - { - private final BlockState state; - private final IWorld world; - private final BlockPos pos; - private boolean inserted; - - public XPartialInventory(BlockState p_i50464_1_, IWorld p_i50464_2_, BlockPos p_i50464_3_) - { - super(1); - this.state = p_i50464_1_; - this.world = p_i50464_2_; - this.pos = p_i50464_3_; - } - - /** - * Returns the maximum stack size for a inventory slot. Seems to always be 64, - * possibly will be extended. - */ - public int getInventoryStackLimit() - { - return 1; - } - - public int[] getSlotsForFace(Direction side) - { - return side == Direction.UP ? new int[] { 0 } : new int[0]; - } - - /** - * Returns true if automation can insert the given item in the given slot from - * the given side. - */ - public boolean canInsertItem(int index, ItemStack itemStackIn, @Nullable Direction direction) - { - Block block = this.world.getBlockState(pos).getBlock(); - if (block instanceof XComposterBlock) - { - XComposterBlock xblock = (XComposterBlock)block; - return !this.inserted && direction == Direction.UP - && xblock.isCompostable(itemStackIn); - } - - return false; - } - - /** - * Returns true if automation can extract the given item in the given slot from - * the given side. - */ - public boolean canExtractItem(int index, ItemStack stack, Direction direction) - { - return false; - } - - /** - * For tile entities, ensures the chunk containing the tile entity is saved to - * disk later - the game won't think it hasn't changed and skip it. - */ - public void markDirty() - { - ItemStack itemstack = this.getStackInSlot(0); - if (!itemstack.isEmpty()) - { - this.inserted = true; - Block block = this.world.getBlockState(pos).getBlock(); - if (block instanceof XComposterBlock) - { - XComposterBlock xblock = (XComposterBlock)block; - xblock.addItem(this.state, this.world, this.pos, itemstack); - } - this.removeStackFromSlot(0); - } - - } - } -} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index bf12f9e..ed0d18d 100755 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -8,49 +8,49 @@ # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="[28,)" #mandatory (28 is current forge version) +loaderVersion="[${forge_loader_version},)" #mandatory (28 is current forge version) # A URL to refer people to when problems occur with this mod -issueTrackerURL="https://github.com/Stormwind99/CannyComposter/issues" #optional +issueTrackerURL="${issueTrackerURL}" #optional # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="cannycomposter" #mandatory -# The version number of the mod - there's a few well known null variables useable here or just hardcode it -version="2.0.0" #mandatory +modId="${mod_id}" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +version="${config.version}" #mandatory # A display name for the mod -displayName="Canny Composter" #mandatory +displayName="${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification -updateJSONURL="https://raw.githubusercontent.com/Stormwind99/CannyComposter/1.14.4/update.json" #optional +updateJSONURL="${updatejson}" #optional # A URL for the "homepage" for this mod, displayed in the mod UI -displayURL="https://github.com/Stormwind99/CannyComposter" #optional +displayURL="${url}" #optional # A file name (in the root of the mod JAR) containing a logo for display -logoFile="logo.png" #optional +logoFile="${mod_logo}" #optional # A text field displayed in the mod UI -credits="Stormwind99, jaquadro" #optional +credits="${mod_credits}" #optional # A text field displayed in the mod UI -authors="Stormwind99" #optional +authors="${mod_author}" #optional # The description text for the mod (multi line!) (#mandatory) -description="Compost stuff! Turn excess organic material and rotten food into nutrients for plants." +description="${mod_description}" # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.cannycomposter]] #optional +[[dependencies.${mod_id}]] #optional # the modid of the dependency modId="forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="[28,)" #mandatory + versionRange="[${forge_loader_version},)" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER side="BOTH" # Here's another dependency -[[dependencies.cannycomposter]] +[[dependencies.${mod_id}]] modId="minecraft" mandatory=true - versionRange="[1.14.4]" + versionRange="[${config.mc_version}]" ordering="NONE" side="BOTH" -[[dependencies.cannycomposter]] +[[dependencies.${mod_id}]] modId="wumpleutil" mandatory=true versionRange="[3.2,)" diff --git a/version.properties b/version.properties index 4bfb4ed..4c76051 100755 --- a/version.properties +++ b/version.properties @@ -1,3 +1,3 @@ #Automated build number increase -#Sun Jan 19 23:26:30 CST 2020 -BUILD_NUMBER=195 +#Mon Jan 20 15:15:42 CST 2020 +BUILD_NUMBER=231