From d4820237278a66ab1e979478ae19994e913f854c Mon Sep 17 00:00:00 2001 From: Savage Date: Thu, 21 May 2020 01:19:36 -0400 Subject: [PATCH] Add 3 new timed buckets --- build.gradle | 2 +- .../java/io/savagedev/buckets/Buckets.java | 10 ++ .../handler/TimedBucketTickHandler.java | 64 +++++++++++++ .../io/savagedev/buckets/init/ModItems.java | 29 +++++- .../buckets/items/ItemBigBucket.java | 19 ++-- .../buckets/items/ItemTimedBucket.java | 78 +++++++++++++++ .../buckets/items/{ => base}/BaseItem.java | 2 +- .../{ => base}/BaseItemDamageableBucket.java | 26 ++--- .../items/{ => enums}/ItemBigBucketItem.java | 2 +- .../items/enums/ItemTimedBucketItem.java | 85 +++++++++++++++++ .../io/savagedev/buckets/util/ModNames.java | 5 + .../io/savagedev/buckets/util/NBTHelper.java | 89 ++++++++++++++++++ .../resources/assets/buckets/lang/en_us.json | 14 ++- .../models/item/cobblestone_bucket_empty.json | 1 + .../models/item/cobblestone_bucket_lava.json | 1 + .../models/item/cobblestone_bucket_water.json | 1 + .../models/item/smoothstone_bucket_empty.json | 1 + .../models/item/smoothstone_bucket_lava.json | 1 + .../models/item/smoothstone_bucket_water.json | 1 + .../models/item/wooden_bucket_empty.json | 1 + .../models/item/wooden_bucket_lava.json | 1 + .../models/item/wooden_bucket_water.json | 1 + .../item/cobblestone_bucket_empty.png | Bin 0 -> 1301 bytes .../textures/item/cobblestone_bucket_lava.png | Bin 0 -> 1304 bytes .../item/cobblestone_bucket_water.png | Bin 0 -> 1294 bytes .../item/smoothstone_bucket_empty.png | Bin 0 -> 1250 bytes .../textures/item/smoothstone_bucket_lava.png | Bin 0 -> 1276 bytes .../item/smoothstone_bucket_water.png | Bin 0 -> 1264 bytes .../textures/item/wooden_bucket_empty.png | Bin 0 -> 1247 bytes .../textures/item/wooden_bucket_lava.png | Bin 0 -> 1275 bytes .../textures/item/wooden_bucket_water.png | Bin 0 -> 1262 bytes .../recipes/cobblestone_bucket_empty.json | 16 ++++ .../recipes/smoothstone_bucket_empty.json | 16 ++++ .../buckets/recipes/wooden_bucket_empty.json | 16 ++++ 34 files changed, 447 insertions(+), 35 deletions(-) create mode 100644 src/main/java/io/savagedev/buckets/handler/TimedBucketTickHandler.java create mode 100644 src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java rename src/main/java/io/savagedev/buckets/items/{ => base}/BaseItem.java (97%) rename src/main/java/io/savagedev/buckets/items/{ => base}/BaseItemDamageableBucket.java (92%) rename src/main/java/io/savagedev/buckets/items/{ => enums}/ItemBigBucketItem.java (98%) create mode 100644 src/main/java/io/savagedev/buckets/items/enums/ItemTimedBucketItem.java create mode 100644 src/main/java/io/savagedev/buckets/util/NBTHelper.java create mode 100644 src/main/resources/assets/buckets/models/item/cobblestone_bucket_empty.json create mode 100644 src/main/resources/assets/buckets/models/item/cobblestone_bucket_lava.json create mode 100644 src/main/resources/assets/buckets/models/item/cobblestone_bucket_water.json create mode 100644 src/main/resources/assets/buckets/models/item/smoothstone_bucket_empty.json create mode 100644 src/main/resources/assets/buckets/models/item/smoothstone_bucket_lava.json create mode 100644 src/main/resources/assets/buckets/models/item/smoothstone_bucket_water.json create mode 100644 src/main/resources/assets/buckets/models/item/wooden_bucket_empty.json create mode 100644 src/main/resources/assets/buckets/models/item/wooden_bucket_lava.json create mode 100644 src/main/resources/assets/buckets/models/item/wooden_bucket_water.json create mode 100644 src/main/resources/assets/buckets/textures/item/cobblestone_bucket_empty.png create mode 100644 src/main/resources/assets/buckets/textures/item/cobblestone_bucket_lava.png create mode 100644 src/main/resources/assets/buckets/textures/item/cobblestone_bucket_water.png create mode 100644 src/main/resources/assets/buckets/textures/item/smoothstone_bucket_empty.png create mode 100644 src/main/resources/assets/buckets/textures/item/smoothstone_bucket_lava.png create mode 100644 src/main/resources/assets/buckets/textures/item/smoothstone_bucket_water.png create mode 100644 src/main/resources/assets/buckets/textures/item/wooden_bucket_empty.png create mode 100644 src/main/resources/assets/buckets/textures/item/wooden_bucket_lava.png create mode 100644 src/main/resources/assets/buckets/textures/item/wooden_bucket_water.png create mode 100644 src/main/resources/data/buckets/recipes/cobblestone_bucket_empty.json create mode 100644 src/main/resources/data/buckets/recipes/smoothstone_bucket_empty.json create mode 100644 src/main/resources/data/buckets/recipes/wooden_bucket_empty.json diff --git a/build.gradle b/build.gradle index 3aee215..423e6b3 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.15.2-1.0.2.1' +version = '1.15.2-1.0.3.0' group = 'io.savagedev.buckets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'Buckets' diff --git a/src/main/java/io/savagedev/buckets/Buckets.java b/src/main/java/io/savagedev/buckets/Buckets.java index 735ecfe..efe77b6 100644 --- a/src/main/java/io/savagedev/buckets/Buckets.java +++ b/src/main/java/io/savagedev/buckets/Buckets.java @@ -23,13 +23,17 @@ * THE SOFTWARE. */ +import io.savagedev.buckets.handler.TimedBucketTickHandler; import io.savagedev.buckets.init.ModItems; import io.savagedev.buckets.util.ModReference; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(ModReference.MOD_ID) @@ -45,6 +49,12 @@ public ItemStack createIcon() { public Buckets() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + modEventBus.register(this); modEventBus.register(new ModItems()); } + + @SubscribeEvent + public void onCommonSetup(FMLCommonSetupEvent event) { + MinecraftForge.EVENT_BUS.register(new TimedBucketTickHandler()); + } } diff --git a/src/main/java/io/savagedev/buckets/handler/TimedBucketTickHandler.java b/src/main/java/io/savagedev/buckets/handler/TimedBucketTickHandler.java new file mode 100644 index 0000000..4fc352e --- /dev/null +++ b/src/main/java/io/savagedev/buckets/handler/TimedBucketTickHandler.java @@ -0,0 +1,64 @@ +package io.savagedev.buckets.handler; + +/* + * TimedBucketTickHandler.java + * Copyright (C) 2020 Savage - github.com/devsavage + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import io.savagedev.buckets.api.IBucketItem; +import io.savagedev.buckets.items.ItemTimedBucket; +import io.savagedev.buckets.util.LogHelper; +import io.savagedev.buckets.util.ModNames; +import io.savagedev.buckets.util.NBTHelper; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.fluid.Fluids; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.LogicalSide; + +public class TimedBucketTickHandler +{ + public int tickTimer = 0; + + @SubscribeEvent + public void onPlayerTick(TickEvent.PlayerTickEvent event) { + if(event.phase == TickEvent.Phase.START && event.player.world.getGameTime() % 20 == 0) { + PlayerEntity player = event.player; + PlayerInventory playerInv = player.inventory; + int invSize = playerInv.getSizeInventory(); + + for(int i = 0; i < invSize; i++) { + ItemStack stackInSlot = playerInv.getStackInSlot(i); + + if(stackInSlot.getItem() instanceof ItemTimedBucket) { + stackInSlot.damageItem(1, player, (playerEntity) -> { + playerEntity.sendBreakAnimation(Hand.MAIN_HAND); + }); + } + } + } + } +} diff --git a/src/main/java/io/savagedev/buckets/init/ModItems.java b/src/main/java/io/savagedev/buckets/init/ModItems.java index 454ed92..0a85c82 100644 --- a/src/main/java/io/savagedev/buckets/init/ModItems.java +++ b/src/main/java/io/savagedev/buckets/init/ModItems.java @@ -25,14 +25,13 @@ import com.google.gson.JsonObject; import io.savagedev.buckets.Buckets; -import io.savagedev.buckets.items.BaseItem; +import io.savagedev.buckets.items.ItemTimedBucket; +import io.savagedev.buckets.items.base.BaseItem; import io.savagedev.buckets.items.ItemBigBucket; -import io.savagedev.buckets.items.ItemBigBucketItem; +import io.savagedev.buckets.items.enums.ItemBigBucketItem; +import io.savagedev.buckets.items.enums.ItemTimedBucketItem; import io.savagedev.buckets.util.LogHelper; -import io.savagedev.buckets.util.ModNames; import io.savagedev.buckets.util.ModReference; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.Fluids; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; @@ -71,6 +70,18 @@ public class ModItems public static final RegistryObject DIAMOND_BUCKET_WATER = registerBigBucket(ItemBigBucketItem.DIAMOND_BUCKET_WATER); public static final RegistryObject DIAMOND_BUCKET_LAVA = registerBigBucket(ItemBigBucketItem.DIAMOND_BUCKET_LAVA); + public static final RegistryObject WOODEN_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_EMPTY); + public static final RegistryObject WOODEN_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_WATER); + public static final RegistryObject WOODEN_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_LAVA); + + public static final RegistryObject COBBLESTONE_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_EMPTY); + public static final RegistryObject COBBLESTONE_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_WATER); + public static final RegistryObject COBBLESTONE_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_LAVA); + + public static final RegistryObject SMOOTHSTONE_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_EMPTY); + public static final RegistryObject SMOOTHSTONE_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_WATER); + public static final RegistryObject SMOOTHSTONE_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_LAVA); + @SubscribeEvent public void onRegisterItems(RegistryEvent.Register event) { IForgeRegistry registry = event.getRegistry(); @@ -90,6 +101,14 @@ private static RegistryObject registerBigBucket(ItemBigBucke return register(bucketItem.getName(), () -> new ItemBigBucket(bucketItem)); } + private static RegistryObject registerTimedBucket(ItemTimedBucketItem bucketItem) { + generateModelFile(bucketItem.getEmptyBucket()); + generateModelFile(bucketItem.getWaterBucket()); + generateModelFile(bucketItem.getLavaBucket()); + + return register(bucketItem.getName(), () -> new ItemTimedBucket(bucketItem)); + } + private static RegistryObject register(String name, Supplier item) { ResourceLocation loc = new ResourceLocation(ModReference.MOD_ID, name); ENTRIES.add(() -> item.get().setRegistryName(loc)); diff --git a/src/main/java/io/savagedev/buckets/items/ItemBigBucket.java b/src/main/java/io/savagedev/buckets/items/ItemBigBucket.java index ce16411..89190e8 100644 --- a/src/main/java/io/savagedev/buckets/items/ItemBigBucket.java +++ b/src/main/java/io/savagedev/buckets/items/ItemBigBucket.java @@ -23,37 +23,31 @@ * THE SOFTWARE. */ -import com.google.common.collect.Maps; import io.savagedev.buckets.Buckets; import io.savagedev.buckets.api.IBucketItem; -import io.savagedev.buckets.init.ModItems; +import io.savagedev.buckets.items.base.BaseItemDamageableBucket; +import io.savagedev.buckets.items.enums.ItemBigBucketItem; import io.savagedev.buckets.util.ModReference; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; -import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nullable; import java.util.List; -import java.util.Map; import java.util.Objects; public class ItemBigBucket extends BaseItemDamageableBucket implements IBucketItem { - public static final Map BIG_BUCKETS_MAP = Maps.newEnumMap(ItemBigBucketItem.class); public final ItemBigBucketItem bucketItem; public ItemBigBucket(ItemBigBucketItem bucketItem) { super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketDamage())), bucketItem.getFluidType()); this.bucketItem = bucketItem; - BIG_BUCKETS_MAP.put(bucketItem, this); } @Override @@ -70,4 +64,13 @@ public Item getLavaBucketItem() { public Item getWaterBucketItem() { return Objects.requireNonNull(ForgeRegistries.ITEMS.getValue(new ResourceLocation(ModReference.MOD_ID, this.bucketItem.getWaterBucket()))).getItem(); } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + if(stack.getMaxDamage() == 0) { + tooltip.add(new StringTextComponent("Uses: 1")); + } else { + tooltip.add(new StringTextComponent("Uses: " + (this.getMaxDamage(stack) - this.getDamage(stack)) / 100)); + } + } } diff --git a/src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java b/src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java new file mode 100644 index 0000000..5aba56f --- /dev/null +++ b/src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java @@ -0,0 +1,78 @@ +package io.savagedev.buckets.items; + +/* + * ItemTimedBucket.java + * Copyright (C) 2020 Savage - github.com/devsavage + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import io.savagedev.buckets.Buckets; +import io.savagedev.buckets.api.IBucketItem; +import io.savagedev.buckets.items.base.BaseItemDamageableBucket; +import io.savagedev.buckets.items.enums.ItemTimedBucketItem; +import io.savagedev.buckets.util.LogHelper; +import io.savagedev.buckets.util.ModNames; +import io.savagedev.buckets.util.ModReference; +import io.savagedev.buckets.util.NBTHelper; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.UseAction; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.world.World; +import net.minecraftforge.registries.ForgeRegistries; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Objects; + +public class ItemTimedBucket extends BaseItemDamageableBucket implements IBucketItem +{ + public final ItemTimedBucketItem bucketItem; + + public ItemTimedBucket(ItemTimedBucketItem bucketItem) { + super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketMaxTime())), bucketItem.getFluidType()); + this.bucketItem = bucketItem; + } + + @Override + public Item getEmptyBucketItem() { + return Objects.requireNonNull(ForgeRegistries.ITEMS.getValue(new ResourceLocation(ModReference.MOD_ID, this.bucketItem.getEmptyBucket()))).getItem(); + } + + @Override + public Item getLavaBucketItem() { + return Objects.requireNonNull(ForgeRegistries.ITEMS.getValue(new ResourceLocation(ModReference.MOD_ID, this.bucketItem.getLavaBucket()))).getItem(); + } + + @Override + public Item getWaterBucketItem() { + return Objects.requireNonNull(ForgeRegistries.ITEMS.getValue(new ResourceLocation(ModReference.MOD_ID, this.bucketItem.getWaterBucket()))).getItem(); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + tooltip.add(new StringTextComponent("Seconds Remaining: " + (this.bucketItem.getBucketMaxTime() - this.getDamage(stack)))); + } +} diff --git a/src/main/java/io/savagedev/buckets/items/BaseItem.java b/src/main/java/io/savagedev/buckets/items/base/BaseItem.java similarity index 97% rename from src/main/java/io/savagedev/buckets/items/BaseItem.java rename to src/main/java/io/savagedev/buckets/items/base/BaseItem.java index e43a665..516a18b 100644 --- a/src/main/java/io/savagedev/buckets/items/BaseItem.java +++ b/src/main/java/io/savagedev/buckets/items/base/BaseItem.java @@ -1,4 +1,4 @@ -package io.savagedev.buckets.items; +package io.savagedev.buckets.items.base; /* * BaseItem.java diff --git a/src/main/java/io/savagedev/buckets/items/BaseItemDamageableBucket.java b/src/main/java/io/savagedev/buckets/items/base/BaseItemDamageableBucket.java similarity index 92% rename from src/main/java/io/savagedev/buckets/items/BaseItemDamageableBucket.java rename to src/main/java/io/savagedev/buckets/items/base/BaseItemDamageableBucket.java index e2624d3..6155722 100644 --- a/src/main/java/io/savagedev/buckets/items/BaseItemDamageableBucket.java +++ b/src/main/java/io/savagedev/buckets/items/base/BaseItemDamageableBucket.java @@ -1,4 +1,4 @@ -package io.savagedev.buckets.items; +package io.savagedev.buckets.items.base; /* * BaseItemDamageableBucket.java @@ -25,7 +25,7 @@ import io.savagedev.buckets.api.IBucketItem; import io.savagedev.buckets.helpers.ItemHelper; -import io.savagedev.buckets.init.ModItems; +import io.savagedev.buckets.items.ItemBigBucket; import io.savagedev.buckets.util.LogHelper; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.BlockState; @@ -38,12 +38,9 @@ import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; -import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.UseAction; import net.minecraft.particles.ParticleTypes; -import net.minecraft.stats.Stats; import net.minecraft.tags.FluidTags; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; @@ -120,10 +117,12 @@ public ActionResult onItemRightClick(World worldIn, PlayerEntity play } // Temp add item back to inv after broken - bucket.damageItem(100, playerIn, (playerEntity) -> { - playerEntity.sendBreakAnimation(Hand.MAIN_HAND); - playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem())); - }); + if(bucket.getItem() instanceof ItemBigBucket) { + bucket.damageItem(100, playerIn, (playerEntity) -> { + playerEntity.sendBreakAnimation(Hand.MAIN_HAND); + playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem())); + }); + } return ActionResult.resultPass(bucket); } else { @@ -223,13 +222,4 @@ private void playEmptySound(PlayerEntity playerEntity, IWorld worldIn, BlockPos if(soundevent == null) soundevent = this.containedFluid.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY; worldIn.playSound(playerEntity, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F); } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - if(stack.getMaxDamage() == 0) { - tooltip.add(new StringTextComponent("Uses: 1")); - } else { - tooltip.add(new StringTextComponent("Uses: " + (this.getMaxDamage(stack) - this.getDamage(stack)) / 100)); - } - } } diff --git a/src/main/java/io/savagedev/buckets/items/ItemBigBucketItem.java b/src/main/java/io/savagedev/buckets/items/enums/ItemBigBucketItem.java similarity index 98% rename from src/main/java/io/savagedev/buckets/items/ItemBigBucketItem.java rename to src/main/java/io/savagedev/buckets/items/enums/ItemBigBucketItem.java index 9d3b18e..78df346 100644 --- a/src/main/java/io/savagedev/buckets/items/ItemBigBucketItem.java +++ b/src/main/java/io/savagedev/buckets/items/enums/ItemBigBucketItem.java @@ -1,4 +1,4 @@ -package io.savagedev.buckets.items; +package io.savagedev.buckets.items.enums; /* * ItemBigBucketItem.java diff --git a/src/main/java/io/savagedev/buckets/items/enums/ItemTimedBucketItem.java b/src/main/java/io/savagedev/buckets/items/enums/ItemTimedBucketItem.java new file mode 100644 index 0000000..0df054e --- /dev/null +++ b/src/main/java/io/savagedev/buckets/items/enums/ItemTimedBucketItem.java @@ -0,0 +1,85 @@ +package io.savagedev.buckets.items.enums; + +/* + * ItemTimedBucketItem.java + * Copyright (C) 2020 Savage - github.com/devsavage + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; +import net.minecraft.util.IStringSerializable; + +import java.util.Arrays; +import java.util.Comparator; + +public enum ItemTimedBucketItem implements IStringSerializable +{ + WOODEN_BUCKET_EMPTY("wooden_bucket", Fluids.EMPTY, 0), + WOODEN_BUCKET_WATER("wooden_bucket", Fluids.WATER, 20), + WOODEN_BUCKET_LAVA("wooden_bucket", Fluids.LAVA, 20), + + COBBLESTONE_BUCKET_EMPTY("cobblestone_bucket", Fluids.EMPTY, 0), + COBBLESTONE_BUCKET_WATER("cobblestone_bucket", Fluids.WATER, 60), + COBBLESTONE_BUCKET_LAVA("cobblestone_bucket", Fluids.LAVA, 60), + + SMOOTHSTONE_BUCKET_EMPTY("smoothstone_bucket", Fluids.EMPTY, 0), + SMOOTHSTONE_BUCKET_WATER("smoothstone_bucket", Fluids.WATER, 300), + SMOOTHSTONE_BUCKET_LAVA("smoothstone_bucket", Fluids.LAVA, 300); + + private static final ItemTimedBucketItem[] VALUES = Arrays.stream(values()).sorted(Comparator.comparing(ItemTimedBucketItem::getName)).toArray((bucketName) -> { + return new ItemTimedBucketItem[bucketName]; + }); + + private final String bucketName; + private final Fluid fluidDef; + private final int bucketMaxTime; + + private ItemTimedBucketItem(String bucketNameIn, Fluid fluidDef, int bucketMaxTimeIn) { + this.bucketName = bucketNameIn; + this.fluidDef = fluidDef; + this.bucketMaxTime = bucketMaxTimeIn; + } + + public Fluid getFluidType() { + return fluidDef; + } + + public String getEmptyBucket() { + return this.bucketName + "_empty"; + } + + public String getLavaBucket() { + return this.bucketName + "_lava"; + } + + public String getWaterBucket() { + return this.bucketName + "_water"; + } + + @Override + public String getName() { + return this.bucketName + "_" + this.fluidDef.getRegistryName().getPath(); + } + + public int getBucketMaxTime() { + return bucketMaxTime; + } +} diff --git a/src/main/java/io/savagedev/buckets/util/ModNames.java b/src/main/java/io/savagedev/buckets/util/ModNames.java index b00642a..78961fa 100644 --- a/src/main/java/io/savagedev/buckets/util/ModNames.java +++ b/src/main/java/io/savagedev/buckets/util/ModNames.java @@ -31,4 +31,9 @@ public static final class Items public static final String DIAMOND_BUCKET_WATER = "diamond_bucket_water"; public static final String DIAMOND_BUCKET_LAVA = "diamond_bucket_lava"; } + + public static final class NBT + { + public static final String TIMED_BUCKET_TIMER_TAG = "TimedBucketTimeLeft"; + } } diff --git a/src/main/java/io/savagedev/buckets/util/NBTHelper.java b/src/main/java/io/savagedev/buckets/util/NBTHelper.java new file mode 100644 index 0000000..4927589 --- /dev/null +++ b/src/main/java/io/savagedev/buckets/util/NBTHelper.java @@ -0,0 +1,89 @@ +package io.savagedev.buckets.util; + +/* + * NBTHelper.java + * A wrapper to easily get & set CompoundNBT tags on ItemStacks. + * Copyright (C) 2020 Savage - github.com/devsavage + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; + +public class NBTHelper +{ + private static void initNBTTagCompound(ItemStack itemStack) { + if (itemStack.getTag() == null) { + itemStack.setTag(new CompoundNBT()); + } + } + + public static boolean hasTag(ItemStack itemStack, String keyName) { + return itemStack.hasTag() && itemStack.getTag().contains(keyName); + } + + public static int getInt(ItemStack itemStack, String keyName) { + initNBTTagCompound(itemStack); + + if (!itemStack.getTag().contains(keyName)) { + setInt(itemStack, keyName, 0); + } + + return itemStack.getTag().getInt(keyName); + } + + public static void setInt(ItemStack itemStack, String keyName, int keyValue) { + initNBTTagCompound(itemStack); + + itemStack.getTag().putInt(keyName, keyValue); + } + + public static String getString(ItemStack itemStack, String keyName) { + initNBTTagCompound(itemStack); + + if (!itemStack.getTag().contains(keyName)) { + setString(itemStack, keyName, ""); + } + + return itemStack.getTag().getString(keyName); + } + + public static void setString(ItemStack itemStack, String keyName, String keyValue) { + initNBTTagCompound(itemStack); + + itemStack.getTag().putString(keyName, keyValue); + } + + public static long getLong(ItemStack itemStack, String keyName) { + initNBTTagCompound(itemStack); + + if (!itemStack.getTag().contains(keyName)) { + setLong(itemStack, keyName, 0L); + } + + return itemStack.getTag().getLong(keyName); + } + + public static void setLong(ItemStack itemStack, String keyName, long keyValue) { + initNBTTagCompound(itemStack); + + itemStack.getTag().putLong(keyName, keyValue); + } +} diff --git a/src/main/resources/assets/buckets/lang/en_us.json b/src/main/resources/assets/buckets/lang/en_us.json index 76cdb41..72727eb 100644 --- a/src/main/resources/assets/buckets/lang/en_us.json +++ b/src/main/resources/assets/buckets/lang/en_us.json @@ -19,5 +19,17 @@ "item.buckets.emerald_bucket_empty": "Emerald Bucket", "item.buckets.emerald_bucket_water": "Emerald Water Bucket", - "item.buckets.emerald_bucket_lava": "Emerald Lava Bucket" + "item.buckets.emerald_bucket_lava": "Emerald Lava Bucket", + + "item.buckets.wooden_bucket_empty": "Wooden Bucket", + "item.buckets.wooden_bucket_water": "Wooden Water Bucket", + "item.buckets.wooden_bucket_lava": "Wooden Lava Bucket", + + "item.buckets.cobblestone_bucket_empty": "Cobblestone Bucket", + "item.buckets.cobblestone_bucket_water": "Cobblestone Water Bucket", + "item.buckets.cobblestone_bucket_lava": "Cobblestone Lava Bucket", + + "item.buckets.smoothstone_bucket_empty": "Smoothstone Bucket", + "item.buckets.smoothstone_bucket_water": "Smoothstone Water Bucket", + "item.buckets.smoothstone_bucket_lava": "Smoothstone Lava Bucket" } \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/cobblestone_bucket_empty.json b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_empty.json new file mode 100644 index 0000000..6bb7e63 --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_empty.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/cobblestone_bucket_empty"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/cobblestone_bucket_lava.json b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_lava.json new file mode 100644 index 0000000..ec84ebe --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_lava.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/cobblestone_bucket_lava"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/cobblestone_bucket_water.json b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_water.json new file mode 100644 index 0000000..9e533a1 --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/cobblestone_bucket_water.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/cobblestone_bucket_water"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/smoothstone_bucket_empty.json b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_empty.json new file mode 100644 index 0000000..a551682 --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_empty.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/smoothstone_bucket_empty"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/smoothstone_bucket_lava.json b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_lava.json new file mode 100644 index 0000000..ebc8dbc --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_lava.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/smoothstone_bucket_lava"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/smoothstone_bucket_water.json b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_water.json new file mode 100644 index 0000000..f3040ea --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/smoothstone_bucket_water.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/smoothstone_bucket_water"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/wooden_bucket_empty.json b/src/main/resources/assets/buckets/models/item/wooden_bucket_empty.json new file mode 100644 index 0000000..11eb78d --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/wooden_bucket_empty.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/wooden_bucket_empty"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/wooden_bucket_lava.json b/src/main/resources/assets/buckets/models/item/wooden_bucket_lava.json new file mode 100644 index 0000000..e650306 --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/wooden_bucket_lava.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/wooden_bucket_lava"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/models/item/wooden_bucket_water.json b/src/main/resources/assets/buckets/models/item/wooden_bucket_water.json new file mode 100644 index 0000000..2507967 --- /dev/null +++ b/src/main/resources/assets/buckets/models/item/wooden_bucket_water.json @@ -0,0 +1 @@ +{"parent":"item/generated","textures":{"layer0":"buckets:item/wooden_bucket_water"}} \ No newline at end of file diff --git a/src/main/resources/assets/buckets/textures/item/cobblestone_bucket_empty.png b/src/main/resources/assets/buckets/textures/item/cobblestone_bucket_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..70d1cf6fd035626bc48b91f68ac4ce713966558c GIT binary patch literal 1301 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@Irlz*GwgCYFfq{WRK|vuQAz@)*k&%&6QBl#+(Xp|yadB~p ziHS)`Noi?m85tRwnVE%!g+)b0B_$>0<>i%?l{GarwY9bN_4SR7jZIBWZEbDs?d_eN zojpB0y}iACeSQ7?{gWn5nm&E{%$YN1&z?PJ&YXGk<}F&ZXz}93%a$!$xpL*Yb?erz zUk`N5C>RX^dWL{-P?!=hpD>gJ`33(U*?=MVJG&|{>^TcOB8wRq_zr?F37S^68#Vw%CUaY(ciWnS=R{+*;SP;&8f^>bP0l+XkKbugK5 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/cobblestone_bucket_lava.png b/src/main/resources/assets/buckets/textures/item/cobblestone_bucket_lava.png new file mode 100644 index 0000000000000000000000000000000000000000..5c6268e507fc6d2b4f1b71ccecf88d650a1c3b43 GIT binary patch literal 1304 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@Irlz*GwgCYFfq{WRK|vuQAz@)*k&%&6QBl#+(Xp|yiHV6x zNl9sGX&D(AB_$>0<>i%?m9@3C_4V~rb3zwaCm*(xKkA@(+D-k8o5qb`lc_zStDCa- zPpezKD0~05x;t$ak9+K2PI7%U+3nH!s3(_VUR_UWYHDh0YinFMd~>+A3D zpFVy1%$YOi&6~Gq(W1qR7cX134CuU3Fd7213xU%8l|{gO!cY?A7yN%@1BT%5?5egXx{&;gUD74I2#TcOyIc-UsNP=Igh2aw2>V z^IY4n2i&llTQ-NSs56Z83KGlT!G@Irlz*GwgCYFfq{WRK|vuQAz@)*k&%&6QBl#+(Xp|yiHV6x zNl9sGX&D(AB_$>0<>i%?m9@3C_4W1k;j?rjFB`>PH;KPxm3rSQ?SW6q@}R7BDK-1u zi{3OfHMO<1wYRr-c6Rpk^z`-h_4oHrpFVx&%$f7%&0Dl+(c;C6mn~Zcbi*hZ4S@j( zfv1e;yny+Hp(MyJ`2WZT48h;oRe_PfS>O>_%)r2R5QG_bOw4`@6zukNaSYK2EVn_!k;m# z?0ImMGSk6ryo*GP)-*C4uwfQI7T-F>we91Z8Xb%2OFbTNtd2Oj_RXJp4fgWiUp_09 zKCo|nTHwiD?C!6+MNbzjY`>h6%JSRk$5HX)EY9a@8DhEG#kNH}+5t*1p00i_>zopr E0DoPZ0{{R3 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/smoothstone_bucket_empty.png b/src/main/resources/assets/buckets/textures/item/smoothstone_bucket_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..695251d909826b2b91e1551ea1df77e52d702639 GIT binary patch literal 1250 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@Irlx^`fk8n*85tQRB_&l=RrU4t{r&yZrcGPAbm`i)YtNlK z_y7NYpvqA&8Un*C1Re$ZKLF+vhLRw^U|=F2$$%mFJG&|{dN~U`B8wRq_zrNSs56Z83KGlT!G@Irlx^`fk8n*85tQRB_&l=RrU4tQ*%NWS0^8~lRxU9c-l?< zjGM-dV3Vmmp{tv+_fM-^y(oMCwz@lQ7LR-EUrus;HQDXa`KTwCVqRTO>hJHLHf`G4 zwQJ9vJNN(pf1vrJU^D~ zFr%o3R|8P6($mE;L?gKL{A<1@10L3da{+8c6K@w-aKHaQWwWd>59jmn-%po#3fG@v zWeD(U4P?-`wJ(3S15d>>e&h4Y-m$TG7)G7`v`Vm%AzF(0PQ3$n{L$T33AuBMC-)uL zB;;KB*tV(TTDpal(xnNuhuSrMv;S-rKF0g4;y>%n%WXEA|2Dh_B_U5&KbLh*2~7aI C5`p&s literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/smoothstone_bucket_water.png b/src/main/resources/assets/buckets/textures/item/smoothstone_bucket_water.png new file mode 100644 index 0000000000000000000000000000000000000000..c4ff22b58a9a73170dcc9f766e93938b8658517c GIT binary patch literal 1264 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@Irlx^`fk8n*85tQRB_&l=RrU4t_TjU1BQG1pUN?!qWtDp0 zD(!(!%JQJBbtyIb-HYDz_xDemHf`of$$%mFJG&|{4mk@vB8wRq_zr#n)JNh69%7ZcHC4vQj57IdzolPH$r5&YL*Nn1@AyVY>ba z?|4@);agGJzV{rKaz0$MoAKyx+cVr;`a7g^l&;r5h~HvZ_aOXz{te3(x216vk)Rai M>FVdQ&MBb@0NR>qj{pDw literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/wooden_bucket_empty.png b/src/main/resources/assets/buckets/textures/item/wooden_bucket_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..a4b7f7dcce75229cfd4fcfdab213f2bdb826fbf3 GIT binary patch literal 1247 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@|THtC5uJ&2m9S>A63PwX< zxQ2kW%(Vt!K4B;c@(cbyvH?TzcXm}^JaZO!L>4nJ@ErtU#vK#0-vR|=JY5_^G=fXd z2l6!-a4-ifY})nvez{oN;WN$ z6U=3wLRaj&pcm(}K%_uC!uXwO3(FBb3yt`W{RWZjXTH=iH=Jo~T3OsP3zWz_UHx3v IIVCg!05#xE=>Px# literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/wooden_bucket_lava.png b/src/main/resources/assets/buckets/textures/item/wooden_bucket_lava.png new file mode 100644 index 0000000000000000000000000000000000000000..48e86be179eb7e6f9ac9a581fd9becfc34cdc7f3 GIT binary patch literal 1275 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@|TH;G;Rc&OzjC>+a15UDSQ94y48!a_iwAa(`NCw$NuFc*H@F>9-WVRaw+E3 z^(3IlqhK@y26+es+V8Ib<`agJAiv=MBO5RTe`i+(Mi*y+M`SSr1K&XqX529``z=tg z!qdeuL?gKL{6oG&3Op@%gX3@avMRhsQxa ziD$9^xh+~8iu u(x@BKI(HuIJv8%)_z&@}9{C^3rkJa(YX12Bjn6VrI`VY&b6Mw<&;$TvczpQ) literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/buckets/textures/item/wooden_bucket_water.png b/src/main/resources/assets/buckets/textures/item/wooden_bucket_water.png new file mode 100644 index 0000000000000000000000000000000000000000..a8c3e5c73393ea1ec8ea9c6fdd4b920e4aa66ec7 GIT binary patch literal 1262 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NSs56Z83KGlT!G@|THY(?i1RIzPjPYo|^y=x9%E;dn4-{>m9bEIMlEg_N}<8W<(y4cPZ~2}nKh&6W*e zom9hhA?{$x;;F9|#%}n)`d+kblKzKy4axip?WatE-