Skip to content

Commit

Permalink
Add new brick bucket (durable) and version reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
devsavage committed May 21, 2020
1 parent d482023 commit ee044d0
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 47 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.3.0'
version = '1.15.2-0.0.4.0'
group = 'io.savagedev.buckets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'Buckets'

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/savagedev/buckets/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@

import com.google.gson.JsonObject;
import io.savagedev.buckets.Buckets;
import io.savagedev.buckets.items.ItemFiredClayBucket;
import io.savagedev.buckets.items.ItemTimedBucket;
import io.savagedev.buckets.items.base.BaseItem;
import io.savagedev.buckets.items.ItemBigBucket;
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 @@ -82,6 +86,12 @@ public class ModItems
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);

public static final RegistryObject<BaseItem> UNFIRED_CLAY_BUCKET = register(ModNames.Items.UNFIRED_CLAY_BUCKET, () -> new BaseItem(p -> p.group(Buckets.modGroup).maxStackSize(1)));

public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET = register(ModNames.Items.FIRED_CLAY_BUCKET, () -> new ItemFiredClayBucket(Fluids.EMPTY));
public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET_WATER = register(ModNames.Items.FIRED_CLAY_BUCKET_WATER, () -> new ItemFiredClayBucket(Fluids.WATER));
public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET_LAVA = register(ModNames.Items.FIRED_CLAY_BUCKET_LAVA, () -> new ItemFiredClayBucket(Fluids.LAVA));

@SubscribeEvent
public void onRegisterItems(RegistryEvent.Register<Item> event) {
IForgeRegistry<Item> registry = event.getRegistry();
Expand Down Expand Up @@ -111,7 +121,11 @@ private static <T extends Item> RegistryObject<T> registerTimedBucket(ItemTimedB

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));

generateModelFile(name);

return RegistryObject.of(loc, ForgeRegistries.ITEMS);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/savagedev/buckets/items/ItemBigBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.savagedev.buckets.Buckets;
import io.savagedev.buckets.api.IBucketItem;
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
import io.savagedev.buckets.items.enums.DamageType;
import io.savagedev.buckets.items.enums.ItemBigBucketItem;
import io.savagedev.buckets.util.ModReference;
import net.minecraft.client.util.ITooltipFlag;
Expand All @@ -46,7 +47,7 @@ public class ItemBigBucket extends BaseItemDamageableBucket implements IBucketIt
public final ItemBigBucketItem bucketItem;

public ItemBigBucket(ItemBigBucketItem bucketItem) {
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketDamage())), bucketItem.getFluidType());
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketDamage())), bucketItem.getFluidType(), DamageType.BIG);
this.bucketItem = bucketItem;
}

Expand Down
179 changes: 179 additions & 0 deletions src/main/java/io/savagedev/buckets/items/ItemFiredClayBucket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package io.savagedev.buckets.items;

/*
* ItemFiredClayBucket.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.helpers.ItemHelper;
import io.savagedev.buckets.init.ModItems;
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
import io.savagedev.buckets.items.enums.DamageType;
import io.savagedev.buckets.util.LogHelper;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.BlockState;
import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;

public class ItemFiredClayBucket extends BaseItemDamageableBucket implements IBucketItem
{
public ItemFiredClayBucket(Fluid fluid) {
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(20)), fluid.getFluid(), DamageType.NORMAL);
}

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack bucket = playerIn.getHeldItem(handIn);
RayTraceResult target = ItemHelper.rayTrace(worldIn, playerIn, this.containedFluid == Fluids.EMPTY ? RayTraceContext.FluidMode.SOURCE_ONLY : RayTraceContext.FluidMode.NONE);
ActionResult<ItemStack> bucketUseResult = ForgeEventFactory.onBucketUse(playerIn, worldIn, bucket, target);

if(bucketUseResult != null) {
return bucketUseResult;
}

if(target.getType() == RayTraceResult.Type.MISS) {
return ActionResult.resultPass(bucket);
} else if(target.getType() != RayTraceResult.Type.BLOCK) {
return ActionResult.resultPass(bucket);
} else {
BlockRayTraceResult targetBlock = (BlockRayTraceResult) target;
BlockPos targetBlockPos = targetBlock.getPos();
Direction targetBlockDirection = targetBlock.getFace();
BlockPos targetBlockPosOffset = targetBlockPos.offset(targetBlockDirection);

if(worldIn.isBlockModifiable(playerIn, targetBlockPos) && playerIn.canPlayerEdit(targetBlockPos, targetBlockDirection, bucket)) {
if(this.containedFluid == Fluids.EMPTY) {
BlockState targetBlockState = worldIn.getBlockState(targetBlockPos);

if(targetBlockState.getBlock() instanceof IBucketPickupHandler) {
Fluid fluid = ((IBucketPickupHandler)targetBlockState.getBlock()).pickupFluid(worldIn, targetBlockPos, targetBlockState);

if(fluid != Fluids.EMPTY) {
SoundEvent soundevent = this.containedFluid.getAttributes().getEmptySound();
if (soundevent == null) {
soundevent = fluid.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_FILL_LAVA : SoundEvents.ITEM_BUCKET_FILL;
}

playerIn.playSound(soundevent, 1.0F, 1.0F);

ItemStack filledBucket = this.fillBucket(bucket, playerIn, getFilledBucket(fluid.getFluid()).getItem());

return ActionResult.resultPass(filledBucket);
}
}

return ActionResult.resultFail(bucket);
} else {
BlockState targetBlockState = worldIn.getBlockState(targetBlockPos);
BlockPos getBlockPos = canTargetTakeFluid(worldIn, targetBlockPos, targetBlockState) ? targetBlockPos : targetBlockPosOffset;
if (this.attemptPlaceFluid(playerIn, worldIn, targetBlockPosOffset, targetBlock)) {
if (playerIn instanceof ServerPlayerEntity) {
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)playerIn, getBlockPos, bucket);
}

if(bucket.getDamage() + 1 < bucket.getMaxDamage()) {
bucket.damageItem(1, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
});

ItemStack emptyBucket = new ItemStack(this.getEmptyBucketItem());
emptyBucket.setDamage(bucket.getDamage());

bucket.shrink(1);

return ActionResult.resultSuccess(emptyBucket);
} else{
bucket.damageItem(1, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
});

return ActionResult.resultConsume(bucket);
}
} else {
return ActionResult.resultFail(bucket);
}
}
} else {
return ActionResult.resultFail(bucket);
}
}
}

@Override
public ItemStack fillBucket(ItemStack emptyBucket, PlayerEntity playerEntity, Item fullBucket) {
if(playerEntity.isCreative()) {
return emptyBucket;
} else {
if(emptyBucket.getDamage() + 1 < emptyBucket.getMaxDamage()) {
emptyBucket.damageItem(1, playerEntity, (event) -> {
event.sendBreakAnimation(Hand.MAIN_HAND);
});

ItemStack newFullBucket = new ItemStack(fullBucket);
newFullBucket.setDamage(emptyBucket.getDamage());

emptyBucket.shrink(1);

if(emptyBucket.isEmpty()) {
return newFullBucket;
} else {
if(!playerEntity.inventory.addItemStackToInventory(newFullBucket)) {
playerEntity.dropItem(newFullBucket, false);
}

return emptyBucket;
}
} else {
return ItemStack.EMPTY;
}
}
}

@Override
public Item getEmptyBucketItem() {
return ModItems.FIRED_CLAY_BUCKET.get();
}

@Override
public Item getLavaBucketItem() {
return ModItems.FIRED_CLAY_BUCKET_LAVA.get();
}

@Override
public Item getWaterBucketItem() {
return ModItems.FIRED_CLAY_BUCKET_WATER.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.savagedev.buckets.Buckets;
import io.savagedev.buckets.api.IBucketItem;
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
import io.savagedev.buckets.items.enums.DamageType;
import io.savagedev.buckets.items.enums.ItemTimedBucketItem;
import io.savagedev.buckets.util.LogHelper;
import io.savagedev.buckets.util.ModNames;
Expand All @@ -52,7 +53,7 @@ public class ItemTimedBucket extends BaseItemDamageableBucket implements IBucket
public final ItemTimedBucketItem bucketItem;

public ItemTimedBucket(ItemTimedBucketItem bucketItem) {
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketMaxTime())), bucketItem.getFluidType());
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketMaxTime())), bucketItem.getFluidType(), DamageType.NORMAL);
this.bucketItem = bucketItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.savagedev.buckets.api.IBucketItem;
import io.savagedev.buckets.helpers.ItemHelper;
import io.savagedev.buckets.items.ItemBigBucket;
import io.savagedev.buckets.items.enums.DamageType;
import io.savagedev.buckets.util.LogHelper;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -59,11 +60,13 @@

public class BaseItemDamageableBucket extends BaseItem
{
private final Fluid containedFluid;
protected DamageType damageType;
protected final Fluid containedFluid;

public BaseItemDamageableBucket(Function<Properties, Properties> properties, Fluid fluid) {
public BaseItemDamageableBucket(Function<Properties, Properties> properties, Fluid fluid, DamageType damageType) {
super(properties);
this.containedFluid = fluid;
this.damageType = damageType;
}

@Override
Expand Down Expand Up @@ -102,7 +105,7 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity play
playerIn.playSound(soundevent, 1.0F, 1.0F);

ItemStack filledBucket = this.fillBucket(bucket, playerIn, getFilledBucket(fluid.getFluid()).getItem());
LogHelper.debug(filledBucket);

return ActionResult.resultSuccess(filledBucket);
}
}
Expand All @@ -116,12 +119,23 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity play
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)playerIn, getBlockPos, bucket);
}

// Temp add item back to inv after broken
if(bucket.getItem() instanceof ItemBigBucket) {
bucket.damageItem(100, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
});
//TODO: Fix this to replace item in actual slot and not add to inventory
switch (this.damageType) {
case BIG:
bucket.damageItem(100, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
});
break;
case NORMAL:
bucket.damageItem(1, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
});
case TIMED:
return ActionResult.resultPass(bucket);
default:
return ActionResult.resultSuccess(bucket);
}

return ActionResult.resultPass(bucket);
Expand Down Expand Up @@ -199,7 +213,7 @@ public ItemStack fillBucket(ItemStack emptyBucket, PlayerEntity playerEntity, It
}
}

private ItemStack getFilledBucket(Fluid fluid) {
protected ItemStack getFilledBucket(Fluid fluid) {
if(this instanceof IBucketItem) {
if(fluid.getFluid() == Fluids.LAVA) {
return new ItemStack(((IBucketItem)this).getLavaBucketItem());
Expand All @@ -213,11 +227,11 @@ private ItemStack getFilledBucket(Fluid fluid) {
return ItemStack.EMPTY;
}

private boolean canTargetTakeFluid(World world, BlockPos targetPos, BlockState targetState) {
protected boolean canTargetTakeFluid(World world, BlockPos targetPos, BlockState targetState) {
return targetState.getBlock() instanceof ILiquidContainer && ((ILiquidContainer)targetState.getBlock()).canContainFluid(world, targetPos, targetState, this.containedFluid);
}

private void playEmptySound(PlayerEntity playerEntity, IWorld worldIn, BlockPos pos) {
protected void playEmptySound(PlayerEntity playerEntity, IWorld worldIn, BlockPos pos) {
SoundEvent soundevent = this.containedFluid.getAttributes().getEmptySound();
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);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/savagedev/buckets/items/enums/DamageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.savagedev.buckets.items.enums;

/*
* DamageType.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.
*/

public enum DamageType
{
NORMAL,
BIG,
TIMED
}
Loading

0 comments on commit ee044d0

Please sign in to comment.