Skip to content

Commit

Permalink
Add new item
Browse files Browse the repository at this point in the history
  • Loading branch information
devsavage committed May 22, 2020
1 parent ee044d0 commit 7f4e7ea
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 6 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-0.0.4.0'
version = '1.15.2-0.0.5.0'
group = 'io.savagedev.buckets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'Buckets'

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/savagedev/buckets/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.gson.JsonObject;
import io.savagedev.buckets.Buckets;
import io.savagedev.buckets.items.ItemFiredClayBucket;
import io.savagedev.buckets.items.ItemIcyBucket;
import io.savagedev.buckets.items.ItemTimedBucket;
import io.savagedev.buckets.items.base.BaseItem;
import io.savagedev.buckets.items.ItemBigBucket;
Expand Down Expand Up @@ -92,17 +93,15 @@ public class ModItems
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));

public static final RegistryObject<BaseItem> ICY_BUCKET = register(ModNames.Items.ICY_BUCKET, ItemIcyBucket::new);

@SubscribeEvent
public void onRegisterItems(RegistryEvent.Register<Item> event) {
IForgeRegistry<Item> registry = event.getRegistry();

ENTRIES.stream().map(Supplier::get).forEach(registry::register);
}

private static <T extends Item> RegistryObject<T> register(String name) {
return register(name, () -> new BaseItem(p -> p.group(Buckets.modGroup)));
}

private static <T extends Item> RegistryObject<T> registerBigBucket(ItemBigBucketItem bucketItem) {
generateModelFile(bucketItem.getEmptyBucket());
generateModelFile(bucketItem.getWaterBucket());
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/io/savagedev/buckets/items/ItemIcyBucket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.savagedev.buckets.items;

/*
* ItemIcyBucket.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.items.base.BaseItem;
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.ItemStack;
import net.minecraft.item.Items;
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 java.util.function.Function;

public class ItemIcyBucket extends BaseItem
{
public ItemIcyBucket() {
super(p -> p.maxStackSize(1).maxDamage(256).group(Buckets.modGroup));
}

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack bucket = playerIn.getHeldItem(handIn);
RayTraceResult target = ItemHelper.rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
BlockRayTraceResult targetBlock = (BlockRayTraceResult) target;
BlockPos targetBlockPos = targetBlock.getPos();
Direction targetBlockDirection = targetBlock.getFace();

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

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

if(fluid != Fluids.EMPTY) {
if(fluid == Fluids.LAVA) {
if(!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.OBSIDIAN, 2))) {
playerIn.dropItem(new ItemStack(Items.OBSIDIAN, 2), false);
}
} else if(fluid == Fluids.WATER) {
if(!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.ICE ))) {
playerIn.dropItem(new ItemStack(Items.ICE ), false);
}
}

bucket.damageItem(1, playerIn, (playerEntity) -> {
playerEntity.sendBreakAnimation(Hand.MAIN_HAND);
});

return ActionResult.resultPass(bucket);
}
}

return ActionResult.resultFail(bucket);
} else {
return ActionResult.resultFail(bucket);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/savagedev/buckets/util/ModNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public static final class Items
public static final String FIRED_CLAY_BUCKET = "fired_clay_bucket_empty";
public static final String FIRED_CLAY_BUCKET_WATER = "fired_clay_bucket_water";
public static final String FIRED_CLAY_BUCKET_LAVA = "fired_clay_bucket_lava";

public static final String ICY_BUCKET = "icy_bucket";
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/buckets/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
"item.buckets.fired_clay_bucket_water": "Brick Water Bucket",
"item.buckets.fired_clay_bucket_lava": "Brick Lava Bucket",

"item.buckets.unfired_clay_bucket": "Unfired Clay Bucket"
"item.buckets.unfired_clay_bucket": "Unfired Clay Bucket",

"item.buckets.icy_bucket": "Icy Bucket"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":"item/generated","textures":{"layer0":"buckets:item/icy_bucket"}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/main/resources/data/buckets/recipes/icy_bucket.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "crafting_shaped",
"pattern": [
"SSS",
"DSD",
" D "
],
"key": {
"S": {
"item": "minecraft:snowball"
},
"D": {
"item": "minecraft:diamond"
}
},
"result": {
"item": "buckets:icy_bucket",
"count": 1
}
}

0 comments on commit 7f4e7ea

Please sign in to comment.