Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tank on use
- @Nonnull
- @Override
- public ActionResultType onUse(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult blockRayTraceResult) {
- ItemStack heldItem = player.getHeldItem(hand);
- boolean usingHoney = heldItem.getItem() instanceof HoneyBottleItem;
- boolean usingBottle = heldItem.getItem() instanceof GlassBottleItem;
- boolean usingBucket = heldItem.getItem() instanceof BucketItem;
- TileEntity tileEntity = world.getTileEntity(pos);
- if (!world.isRemote) {
- if (tileEntity instanceof HoneyTankTileEntity) {
- HoneyTankTileEntity tank = (HoneyTankTileEntity) tileEntity;
- if (usingBucket) {
- LOGGER.info("using bucket");
- tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
- .ifPresent(iFluidHandler -> FluidUtil.interactWithFluidHandler(player, hand, world, pos, null));
- } else if (usingBottle) {
- world.playSound(player, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.PLAYERS, 1.0f, 1.0f);
- tank.fillBottle(player, hand);
- } else if (usingHoney) {
- world.playSound(player, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.PLAYERS, 1.0f, 1.0f);
- tank.emptyBottle(player, hand);
- }
- updateBlockState(world, pos);
- }
- }
- if (usingBottle || usingBucket || usingHoney) {
- return ActionResultType.SUCCESS;
- }
- return ActionResultType.FAIL;
- }
- // registring custom honey
- private static Map<String, RegistryObject<FlowingFluid>> stillFluids = new HashMap<>();
- private static Map<String, RegistryObject<FlowingFluid>> flowingFluids = new HashMap<>();
- private static Map<String, RegistryObject<Item>> honeyBuckets = new HashMap<>();
- private static Map<String, RegistryObject<FlowingFluidBlock>> fluidBlocks = new HashMap<>();
- private static void registerHoneyBottle(String name, HoneyBottleData honeyData) {
- final RegistryObject<Block> customHoneyBlock = ModBlocks.BLOCKS.register(name + "_honey_block", () -> new CustomHoneyBlock(honeyData));
- final RegistryObject<Item> customHoneyBottle = ModItems.ITEMS.register(name + "_honey_bottle", () -> new CustomHoneyBottleItem(honeyData.getProperties(), honeyData));
- final RegistryObject<Item> customHoneyBlockItem = ModItems.ITEMS.register(name + "_honey_block", () -> new BlockItem(customHoneyBlock.get(), new Item.Properties().group(ItemGroupResourcefulBees.RESOURCEFUL_BEES)));
- stillFluids.put(name, ModFluids.FLUIDS.register(name + "_honey", () -> new HoneyFlowingFluid.Source(makeProperties(name, honeyData), honeyData)));
- flowingFluids.put(name, ModFluids.FLUIDS.register(name + "_honey_flowing", () -> new HoneyFlowingFluid.Flowing(makeProperties(name, honeyData), honeyData)));
- honeyBuckets.put(name, ModItems.ITEMS.register(name + "_honey_fluid_bucket", () -> new CustomHoneyBucketItem(stillFluids.get(name), new Item.Properties().group(ItemGroupResourcefulBees.RESOURCEFUL_BEES).containerItem(Items.BUCKET).maxStackSize(1), honeyData)));
- fluidBlocks.put(name, ModBlocks.BLOCKS.register(name + "_honey", () -> new CustomHoneyFluidBlock(stillFluids.get(name), Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops(), honeyData)));
- honeyData.setHoneyBottleRegistryObject(customHoneyBottle);
- honeyData.setHoneyBlockRegistryObject(customHoneyBlock);
- honeyData.setHoneyBlockItemRegistryObject(customHoneyBlockItem);
- honeyData.setHoneyStillFluidRegistryObject(stillFluids.get(name));
- honeyData.setHoneyFlowingFluidRegistryObject(flowingFluids.get(name));
- honeyData.setHoneyBucketItemRegistryObject(honeyBuckets.get(name));
- honeyData.setHoneyFluidBlockRegistryObject(fluidBlocks.get(name));
- }
- private static ForgeFlowingFluid.Properties makeProperties(String name, HoneyBottleData honeyData) {
- HoneyFluidAttributes.Builder builder;
- builder = HoneyFluidAttributes.builder(ModFluids.CUSTOM_FLUID_STILL, ModFluids.CUSTOM_FLUID_FLOWING, honeyData);
- builder.overlay(ModFluids.CUSTOM_FLUID_OVERLAY);
- builder.sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY);
- builder.density(1300);
- builder.temperature(300);
- builder.viscosity(1800);
- return new ForgeFlowingFluid.Properties(stillFluids.get(name), flowingFluids.get(name), builder)
- .bucket(honeyBuckets.get(name))
- .block(fluidBlocks.get(name))
- .tickRate(20);
- }
- // registring default honey bucket
- private static ForgeFlowingFluid.Properties makeProperties() {
- return new ForgeFlowingFluid.Properties(HONEY_STILL, HONEY_FLOWING,
- FluidAttributes.builder(FLUID_STILL, FLUID_FLOWING).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY)
- .overlay(FLUID_OVERLAY).density(1300).temperature(300).viscosity(1800).rarity(Rarity.COMMON))
- .bucket(ModItems.HONEY_FLUID_BUCKET).block(ModBlocks.HONEY_FLUID_BLOCK).tickRate(20);
- }
- public static RegistryObject<FlowingFluid> HONEY_STILL = FLUIDS.register("honey", () ->
- new ForgeFlowingFluid.Source(makeProperties())
- );
- public static RegistryObject<FlowingFluid> HONEY_FLOWING = FLUIDS.register("honey_flowing", () ->
- new ForgeFlowingFluid.Flowing(makeProperties())
- );
- public static final RegistryObject<Item> HONEY_FLUID_BUCKET = ITEMS.register("honey_fluid_bucket", () -> new BucketItem(ModFluids.HONEY_STILL, new Item.Properties().group(ItemGroupResourcefulBees.RESOURCEFUL_BEES).containerItem(net.minecraft.item.Items.BUCKET).maxStackSize(1)));
- // custom bucket class
- public class CustomHoneyBucketItem extends BucketItem {
- private final HoneyBottleData honeyBottleData;
- public CustomHoneyBucketItem(Supplier<? extends Fluid> supplier, Properties builder, HoneyBottleData honeyBottleData) {
- super(supplier, builder);
- this.honeyBottleData = honeyBottleData;
- }
- public static int getColor(ItemStack stack, int tintIndex) {
- if (tintIndex == 1) {
- CustomHoneyBucketItem honeyBottleItem = (CustomHoneyBucketItem) stack.getItem();
- return honeyBottleItem.honeyBottleData.isRainbow() ? RainbowColor.getRGB() : honeyBottleItem.getHoneyBucketColor();
- }
- return BeeConstants.DEFAULT_ITEM_COLOR;
- }
- public int getHoneyBucketColor() {
- return honeyBottleData.getHoneyColorInt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement