Skip to content

Commit

Permalink
Add 3 new timed buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
devsavage committed May 21, 2020
1 parent eb9b66e commit d482023
Show file tree
Hide file tree
Showing 34 changed files with 447 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/savagedev/buckets/Buckets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
}
}
}
29 changes: 24 additions & 5 deletions src/main/java/io/savagedev/buckets/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +70,18 @@ public class ModItems
public static final RegistryObject<BaseItem> DIAMOND_BUCKET_WATER = registerBigBucket(ItemBigBucketItem.DIAMOND_BUCKET_WATER);
public static final RegistryObject<BaseItem> DIAMOND_BUCKET_LAVA = registerBigBucket(ItemBigBucketItem.DIAMOND_BUCKET_LAVA);

public static final RegistryObject<BaseItem> WOODEN_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_EMPTY);
public static final RegistryObject<BaseItem> WOODEN_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_WATER);
public static final RegistryObject<BaseItem> WOODEN_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.WOODEN_BUCKET_LAVA);

public static final RegistryObject<BaseItem> COBBLESTONE_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_EMPTY);
public static final RegistryObject<BaseItem> COBBLESTONE_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_WATER);
public static final RegistryObject<BaseItem> COBBLESTONE_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.COBBLESTONE_BUCKET_LAVA);

public static final RegistryObject<BaseItem> SMOOTHSTONE_BUCKET_EMPTY = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_EMPTY);
public static final RegistryObject<BaseItem> SMOOTHSTONE_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_WATER);
public static final RegistryObject<BaseItem> SMOOTHSTONE_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_LAVA);

@SubscribeEvent
public void onRegisterItems(RegistryEvent.Register<Item> event) {
IForgeRegistry<Item> registry = event.getRegistry();
Expand All @@ -90,6 +101,14 @@ private static <T extends Item> RegistryObject<T> registerBigBucket(ItemBigBucke
return register(bucketItem.getName(), () -> new ItemBigBucket(bucketItem));
}

private static <T extends Item> RegistryObject<T> registerTimedBucket(ItemTimedBucketItem bucketItem) {
generateModelFile(bucketItem.getEmptyBucket());
generateModelFile(bucketItem.getWaterBucket());
generateModelFile(bucketItem.getLavaBucket());

return register(bucketItem.getName(), () -> new ItemTimedBucket(bucketItem));
}

private static <T extends Item> RegistryObject<T> register(String name, Supplier<? extends Item> item) {
ResourceLocation loc = new ResourceLocation(ModReference.MOD_ID, name);
ENTRIES.add(() -> item.get().setRegistryName(loc));
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/io/savagedev/buckets/items/ItemBigBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemBigBucketItem, ItemBigBucket> 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
Expand All @@ -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<ITextComponent> 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));
}
}
}
78 changes: 78 additions & 0 deletions src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java
Original file line number Diff line number Diff line change
@@ -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<ITextComponent> tooltip, ITooltipFlag flagIn) {
tooltip.add(new StringTextComponent("Seconds Remaining: " + (this.bucketItem.getBucketMaxTime() - this.getDamage(stack))));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.savagedev.buckets.items;
package io.savagedev.buckets.items.base;

/*
* BaseItem.java
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.savagedev.buckets.items;
package io.savagedev.buckets.items.base;

/*
* BaseItemDamageableBucket.java
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -120,10 +117,12 @@ public ActionResult<ItemStack> 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 {
Expand Down Expand Up @@ -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<ITextComponent> 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));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.savagedev.buckets.items;
package io.savagedev.buckets.items.enums;

/*
* ItemBigBucketItem.java
Expand Down
Loading

0 comments on commit d482023

Please sign in to comment.