Skip to content

Commit ee044d0

Browse files
committed
Add new brick bucket (durable) and version reformat
1 parent d482023 commit ee044d0

21 files changed

Lines changed: 330 additions & 47 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
1313
apply plugin: 'eclipse'
1414
apply plugin: 'maven-publish'
1515

16-
version = '1.15.2-1.0.3.0'
16+
version = '1.15.2-0.0.4.0'
1717
group = 'io.savagedev.buckets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1818
archivesBaseName = 'Buckets'
1919

src/main/java/io/savagedev/buckets/init/ModItems.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525

2626
import com.google.gson.JsonObject;
2727
import io.savagedev.buckets.Buckets;
28+
import io.savagedev.buckets.items.ItemFiredClayBucket;
2829
import io.savagedev.buckets.items.ItemTimedBucket;
2930
import io.savagedev.buckets.items.base.BaseItem;
3031
import io.savagedev.buckets.items.ItemBigBucket;
3132
import io.savagedev.buckets.items.enums.ItemBigBucketItem;
3233
import io.savagedev.buckets.items.enums.ItemTimedBucketItem;
3334
import io.savagedev.buckets.util.LogHelper;
35+
import io.savagedev.buckets.util.ModNames;
3436
import io.savagedev.buckets.util.ModReference;
37+
import net.minecraft.fluid.Fluid;
38+
import net.minecraft.fluid.Fluids;
3539
import net.minecraft.item.Item;
3640
import net.minecraft.util.ResourceLocation;
3741
import net.minecraftforge.event.RegistryEvent;
@@ -82,6 +86,12 @@ public class ModItems
8286
public static final RegistryObject<BaseItem> SMOOTHSTONE_BUCKET_WATER = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_WATER);
8387
public static final RegistryObject<BaseItem> SMOOTHSTONE_BUCKET_LAVA = registerTimedBucket(ItemTimedBucketItem.SMOOTHSTONE_BUCKET_LAVA);
8488

89+
public static final RegistryObject<BaseItem> UNFIRED_CLAY_BUCKET = register(ModNames.Items.UNFIRED_CLAY_BUCKET, () -> new BaseItem(p -> p.group(Buckets.modGroup).maxStackSize(1)));
90+
91+
public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET = register(ModNames.Items.FIRED_CLAY_BUCKET, () -> new ItemFiredClayBucket(Fluids.EMPTY));
92+
public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET_WATER = register(ModNames.Items.FIRED_CLAY_BUCKET_WATER, () -> new ItemFiredClayBucket(Fluids.WATER));
93+
public static final RegistryObject<BaseItem> FIRED_CLAY_BUCKET_LAVA = register(ModNames.Items.FIRED_CLAY_BUCKET_LAVA, () -> new ItemFiredClayBucket(Fluids.LAVA));
94+
8595
@SubscribeEvent
8696
public void onRegisterItems(RegistryEvent.Register<Item> event) {
8797
IForgeRegistry<Item> registry = event.getRegistry();
@@ -111,7 +121,11 @@ private static <T extends Item> RegistryObject<T> registerTimedBucket(ItemTimedB
111121

112122
private static <T extends Item> RegistryObject<T> register(String name, Supplier<? extends Item> item) {
113123
ResourceLocation loc = new ResourceLocation(ModReference.MOD_ID, name);
124+
114125
ENTRIES.add(() -> item.get().setRegistryName(loc));
126+
127+
generateModelFile(name);
128+
115129
return RegistryObject.of(loc, ForgeRegistries.ITEMS);
116130
}
117131

src/main/java/io/savagedev/buckets/items/ItemBigBucket.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.savagedev.buckets.Buckets;
2727
import io.savagedev.buckets.api.IBucketItem;
2828
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
29+
import io.savagedev.buckets.items.enums.DamageType;
2930
import io.savagedev.buckets.items.enums.ItemBigBucketItem;
3031
import io.savagedev.buckets.util.ModReference;
3132
import net.minecraft.client.util.ITooltipFlag;
@@ -46,7 +47,7 @@ public class ItemBigBucket extends BaseItemDamageableBucket implements IBucketIt
4647
public final ItemBigBucketItem bucketItem;
4748

4849
public ItemBigBucket(ItemBigBucketItem bucketItem) {
49-
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketDamage())), bucketItem.getFluidType());
50+
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketDamage())), bucketItem.getFluidType(), DamageType.BIG);
5051
this.bucketItem = bucketItem;
5152
}
5253

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package io.savagedev.buckets.items;
2+
3+
/*
4+
* ItemFiredClayBucket.java
5+
* Copyright (C) 2020 Savage - github.com/devsavage
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
import io.savagedev.buckets.Buckets;
27+
import io.savagedev.buckets.api.IBucketItem;
28+
import io.savagedev.buckets.helpers.ItemHelper;
29+
import io.savagedev.buckets.init.ModItems;
30+
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
31+
import io.savagedev.buckets.items.enums.DamageType;
32+
import io.savagedev.buckets.util.LogHelper;
33+
import net.minecraft.advancements.CriteriaTriggers;
34+
import net.minecraft.block.BlockState;
35+
import net.minecraft.block.IBucketPickupHandler;
36+
import net.minecraft.entity.player.PlayerEntity;
37+
import net.minecraft.entity.player.ServerPlayerEntity;
38+
import net.minecraft.fluid.Fluid;
39+
import net.minecraft.fluid.Fluids;
40+
import net.minecraft.item.Item;
41+
import net.minecraft.item.ItemStack;
42+
import net.minecraft.tags.FluidTags;
43+
import net.minecraft.util.*;
44+
import net.minecraft.util.math.BlockPos;
45+
import net.minecraft.util.math.BlockRayTraceResult;
46+
import net.minecraft.util.math.RayTraceContext;
47+
import net.minecraft.util.math.RayTraceResult;
48+
import net.minecraft.world.World;
49+
import net.minecraftforge.event.ForgeEventFactory;
50+
51+
public class ItemFiredClayBucket extends BaseItemDamageableBucket implements IBucketItem
52+
{
53+
public ItemFiredClayBucket(Fluid fluid) {
54+
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(20)), fluid.getFluid(), DamageType.NORMAL);
55+
}
56+
57+
@Override
58+
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
59+
ItemStack bucket = playerIn.getHeldItem(handIn);
60+
RayTraceResult target = ItemHelper.rayTrace(worldIn, playerIn, this.containedFluid == Fluids.EMPTY ? RayTraceContext.FluidMode.SOURCE_ONLY : RayTraceContext.FluidMode.NONE);
61+
ActionResult<ItemStack> bucketUseResult = ForgeEventFactory.onBucketUse(playerIn, worldIn, bucket, target);
62+
63+
if(bucketUseResult != null) {
64+
return bucketUseResult;
65+
}
66+
67+
if(target.getType() == RayTraceResult.Type.MISS) {
68+
return ActionResult.resultPass(bucket);
69+
} else if(target.getType() != RayTraceResult.Type.BLOCK) {
70+
return ActionResult.resultPass(bucket);
71+
} else {
72+
BlockRayTraceResult targetBlock = (BlockRayTraceResult) target;
73+
BlockPos targetBlockPos = targetBlock.getPos();
74+
Direction targetBlockDirection = targetBlock.getFace();
75+
BlockPos targetBlockPosOffset = targetBlockPos.offset(targetBlockDirection);
76+
77+
if(worldIn.isBlockModifiable(playerIn, targetBlockPos) && playerIn.canPlayerEdit(targetBlockPos, targetBlockDirection, bucket)) {
78+
if(this.containedFluid == Fluids.EMPTY) {
79+
BlockState targetBlockState = worldIn.getBlockState(targetBlockPos);
80+
81+
if(targetBlockState.getBlock() instanceof IBucketPickupHandler) {
82+
Fluid fluid = ((IBucketPickupHandler)targetBlockState.getBlock()).pickupFluid(worldIn, targetBlockPos, targetBlockState);
83+
84+
if(fluid != Fluids.EMPTY) {
85+
SoundEvent soundevent = this.containedFluid.getAttributes().getEmptySound();
86+
if (soundevent == null) {
87+
soundevent = fluid.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_FILL_LAVA : SoundEvents.ITEM_BUCKET_FILL;
88+
}
89+
90+
playerIn.playSound(soundevent, 1.0F, 1.0F);
91+
92+
ItemStack filledBucket = this.fillBucket(bucket, playerIn, getFilledBucket(fluid.getFluid()).getItem());
93+
94+
return ActionResult.resultPass(filledBucket);
95+
}
96+
}
97+
98+
return ActionResult.resultFail(bucket);
99+
} else {
100+
BlockState targetBlockState = worldIn.getBlockState(targetBlockPos);
101+
BlockPos getBlockPos = canTargetTakeFluid(worldIn, targetBlockPos, targetBlockState) ? targetBlockPos : targetBlockPosOffset;
102+
if (this.attemptPlaceFluid(playerIn, worldIn, targetBlockPosOffset, targetBlock)) {
103+
if (playerIn instanceof ServerPlayerEntity) {
104+
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)playerIn, getBlockPos, bucket);
105+
}
106+
107+
if(bucket.getDamage() + 1 < bucket.getMaxDamage()) {
108+
bucket.damageItem(1, playerIn, (playerEntity) -> {
109+
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
110+
});
111+
112+
ItemStack emptyBucket = new ItemStack(this.getEmptyBucketItem());
113+
emptyBucket.setDamage(bucket.getDamage());
114+
115+
bucket.shrink(1);
116+
117+
return ActionResult.resultSuccess(emptyBucket);
118+
} else{
119+
bucket.damageItem(1, playerIn, (playerEntity) -> {
120+
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
121+
});
122+
123+
return ActionResult.resultConsume(bucket);
124+
}
125+
} else {
126+
return ActionResult.resultFail(bucket);
127+
}
128+
}
129+
} else {
130+
return ActionResult.resultFail(bucket);
131+
}
132+
}
133+
}
134+
135+
@Override
136+
public ItemStack fillBucket(ItemStack emptyBucket, PlayerEntity playerEntity, Item fullBucket) {
137+
if(playerEntity.isCreative()) {
138+
return emptyBucket;
139+
} else {
140+
if(emptyBucket.getDamage() + 1 < emptyBucket.getMaxDamage()) {
141+
emptyBucket.damageItem(1, playerEntity, (event) -> {
142+
event.sendBreakAnimation(Hand.MAIN_HAND);
143+
});
144+
145+
ItemStack newFullBucket = new ItemStack(fullBucket);
146+
newFullBucket.setDamage(emptyBucket.getDamage());
147+
148+
emptyBucket.shrink(1);
149+
150+
if(emptyBucket.isEmpty()) {
151+
return newFullBucket;
152+
} else {
153+
if(!playerEntity.inventory.addItemStackToInventory(newFullBucket)) {
154+
playerEntity.dropItem(newFullBucket, false);
155+
}
156+
157+
return emptyBucket;
158+
}
159+
} else {
160+
return ItemStack.EMPTY;
161+
}
162+
}
163+
}
164+
165+
@Override
166+
public Item getEmptyBucketItem() {
167+
return ModItems.FIRED_CLAY_BUCKET.get();
168+
}
169+
170+
@Override
171+
public Item getLavaBucketItem() {
172+
return ModItems.FIRED_CLAY_BUCKET_LAVA.get();
173+
}
174+
175+
@Override
176+
public Item getWaterBucketItem() {
177+
return ModItems.FIRED_CLAY_BUCKET_WATER.get();
178+
}
179+
}

src/main/java/io/savagedev/buckets/items/ItemTimedBucket.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.savagedev.buckets.Buckets;
2727
import io.savagedev.buckets.api.IBucketItem;
2828
import io.savagedev.buckets.items.base.BaseItemDamageableBucket;
29+
import io.savagedev.buckets.items.enums.DamageType;
2930
import io.savagedev.buckets.items.enums.ItemTimedBucketItem;
3031
import io.savagedev.buckets.util.LogHelper;
3132
import io.savagedev.buckets.util.ModNames;
@@ -52,7 +53,7 @@ public class ItemTimedBucket extends BaseItemDamageableBucket implements IBucket
5253
public final ItemTimedBucketItem bucketItem;
5354

5455
public ItemTimedBucket(ItemTimedBucketItem bucketItem) {
55-
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketMaxTime())), bucketItem.getFluidType());
56+
super(p -> (p.group(Buckets.modGroup).maxStackSize(1).maxDamage(bucketItem.getBucketMaxTime())), bucketItem.getFluidType(), DamageType.NORMAL);
5657
this.bucketItem = bucketItem;
5758
}
5859

src/main/java/io/savagedev/buckets/items/base/BaseItemDamageableBucket.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.savagedev.buckets.api.IBucketItem;
2727
import io.savagedev.buckets.helpers.ItemHelper;
2828
import io.savagedev.buckets.items.ItemBigBucket;
29+
import io.savagedev.buckets.items.enums.DamageType;
2930
import io.savagedev.buckets.util.LogHelper;
3031
import net.minecraft.advancements.CriteriaTriggers;
3132
import net.minecraft.block.BlockState;
@@ -59,11 +60,13 @@
5960

6061
public class BaseItemDamageableBucket extends BaseItem
6162
{
62-
private final Fluid containedFluid;
63+
protected DamageType damageType;
64+
protected final Fluid containedFluid;
6365

64-
public BaseItemDamageableBucket(Function<Properties, Properties> properties, Fluid fluid) {
66+
public BaseItemDamageableBucket(Function<Properties, Properties> properties, Fluid fluid, DamageType damageType) {
6567
super(properties);
6668
this.containedFluid = fluid;
69+
this.damageType = damageType;
6770
}
6871

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

104107
ItemStack filledBucket = this.fillBucket(bucket, playerIn, getFilledBucket(fluid.getFluid()).getItem());
105-
LogHelper.debug(filledBucket);
108+
106109
return ActionResult.resultSuccess(filledBucket);
107110
}
108111
}
@@ -116,12 +119,23 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity play
116119
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)playerIn, getBlockPos, bucket);
117120
}
118121

119-
// Temp add item back to inv after broken
120-
if(bucket.getItem() instanceof ItemBigBucket) {
121-
bucket.damageItem(100, playerIn, (playerEntity) -> {
122-
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
123-
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
124-
});
122+
//TODO: Fix this to replace item in actual slot and not add to inventory
123+
switch (this.damageType) {
124+
case BIG:
125+
bucket.damageItem(100, playerIn, (playerEntity) -> {
126+
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
127+
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
128+
});
129+
break;
130+
case NORMAL:
131+
bucket.damageItem(1, playerIn, (playerEntity) -> {
132+
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
133+
playerEntity.addItemStackToInventory(new ItemStack(((IBucketItem)this).getEmptyBucketItem()));
134+
});
135+
case TIMED:
136+
return ActionResult.resultPass(bucket);
137+
default:
138+
return ActionResult.resultSuccess(bucket);
125139
}
126140

127141
return ActionResult.resultPass(bucket);
@@ -199,7 +213,7 @@ public ItemStack fillBucket(ItemStack emptyBucket, PlayerEntity playerEntity, It
199213
}
200214
}
201215

202-
private ItemStack getFilledBucket(Fluid fluid) {
216+
protected ItemStack getFilledBucket(Fluid fluid) {
203217
if(this instanceof IBucketItem) {
204218
if(fluid.getFluid() == Fluids.LAVA) {
205219
return new ItemStack(((IBucketItem)this).getLavaBucketItem());
@@ -213,11 +227,11 @@ private ItemStack getFilledBucket(Fluid fluid) {
213227
return ItemStack.EMPTY;
214228
}
215229

216-
private boolean canTargetTakeFluid(World world, BlockPos targetPos, BlockState targetState) {
230+
protected boolean canTargetTakeFluid(World world, BlockPos targetPos, BlockState targetState) {
217231
return targetState.getBlock() instanceof ILiquidContainer && ((ILiquidContainer)targetState.getBlock()).canContainFluid(world, targetPos, targetState, this.containedFluid);
218232
}
219233

220-
private void playEmptySound(PlayerEntity playerEntity, IWorld worldIn, BlockPos pos) {
234+
protected void playEmptySound(PlayerEntity playerEntity, IWorld worldIn, BlockPos pos) {
221235
SoundEvent soundevent = this.containedFluid.getAttributes().getEmptySound();
222236
if(soundevent == null) soundevent = this.containedFluid.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
223237
worldIn.playSound(playerEntity, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.savagedev.buckets.items.enums;
2+
3+
/*
4+
* DamageType.java
5+
* Copyright (C) 2020 Savage - github.com/devsavage
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
public enum DamageType
27+
{
28+
NORMAL,
29+
BIG,
30+
TIMED
31+
}

0 commit comments

Comments
 (0)