Advertisement
Vaerys_Dawn

Custom Honey Buckets not working

Dec 23rd, 2020
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.77 KB | None | 0 0
  1. // tank on use
  2.     @Nonnull
  3.     @Override
  4.     public ActionResultType onUse(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult blockRayTraceResult) {
  5.  
  6.         ItemStack heldItem = player.getHeldItem(hand);
  7.         boolean usingHoney = heldItem.getItem() instanceof HoneyBottleItem;
  8.         boolean usingBottle = heldItem.getItem() instanceof GlassBottleItem;
  9.         boolean usingBucket = heldItem.getItem() instanceof BucketItem;
  10.         TileEntity tileEntity = world.getTileEntity(pos);
  11.  
  12.         if (!world.isRemote) {
  13.             if (tileEntity instanceof HoneyTankTileEntity) {
  14.                 HoneyTankTileEntity tank = (HoneyTankTileEntity) tileEntity;
  15.                 if (usingBucket) {
  16.                     LOGGER.info("using bucket");
  17.                     tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
  18.                             .ifPresent(iFluidHandler -> FluidUtil.interactWithFluidHandler(player, hand, world, pos, null));
  19.                 } else if (usingBottle) {
  20.                     world.playSound(player, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.PLAYERS, 1.0f, 1.0f);
  21.                     tank.fillBottle(player, hand);
  22.                 } else if (usingHoney) {
  23.                     world.playSound(player, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.PLAYERS, 1.0f, 1.0f);
  24.                     tank.emptyBottle(player, hand);
  25.                 }
  26.                 updateBlockState(world, pos);
  27.             }
  28.         }
  29.         if (usingBottle || usingBucket || usingHoney) {
  30.             return ActionResultType.SUCCESS;
  31.         }
  32.         return ActionResultType.FAIL;
  33.     }
  34.  
  35. // registring custom honey
  36.  
  37.     private static Map<String, RegistryObject<FlowingFluid>> stillFluids = new HashMap<>();
  38.     private static Map<String, RegistryObject<FlowingFluid>> flowingFluids = new HashMap<>();
  39.     private static Map<String, RegistryObject<Item>> honeyBuckets = new HashMap<>();
  40.     private static Map<String, RegistryObject<FlowingFluidBlock>> fluidBlocks = new HashMap<>();
  41.  
  42.     private static void registerHoneyBottle(String name, HoneyBottleData honeyData) {
  43.         final RegistryObject<Block> customHoneyBlock = ModBlocks.BLOCKS.register(name + "_honey_block", () -> new CustomHoneyBlock(honeyData));
  44.         final RegistryObject<Item> customHoneyBottle = ModItems.ITEMS.register(name + "_honey_bottle", () -> new CustomHoneyBottleItem(honeyData.getProperties(), honeyData));
  45.         final RegistryObject<Item> customHoneyBlockItem = ModItems.ITEMS.register(name + "_honey_block", () -> new BlockItem(customHoneyBlock.get(), new Item.Properties().group(ItemGroupResourcefulBees.RESOURCEFUL_BEES)));
  46.  
  47.         stillFluids.put(name, ModFluids.FLUIDS.register(name + "_honey", () -> new HoneyFlowingFluid.Source(makeProperties(name, honeyData), honeyData)));
  48.         flowingFluids.put(name, ModFluids.FLUIDS.register(name + "_honey_flowing", () -> new HoneyFlowingFluid.Flowing(makeProperties(name, honeyData), honeyData)));
  49.         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)));
  50.         fluidBlocks.put(name, ModBlocks.BLOCKS.register(name + "_honey", () -> new CustomHoneyFluidBlock(stillFluids.get(name), Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops(), honeyData)));
  51.  
  52.         honeyData.setHoneyBottleRegistryObject(customHoneyBottle);
  53.         honeyData.setHoneyBlockRegistryObject(customHoneyBlock);
  54.         honeyData.setHoneyBlockItemRegistryObject(customHoneyBlockItem);
  55.         honeyData.setHoneyStillFluidRegistryObject(stillFluids.get(name));
  56.         honeyData.setHoneyFlowingFluidRegistryObject(flowingFluids.get(name));
  57.         honeyData.setHoneyBucketItemRegistryObject(honeyBuckets.get(name));
  58.         honeyData.setHoneyFluidBlockRegistryObject(fluidBlocks.get(name));
  59.     }
  60.  
  61.     private static ForgeFlowingFluid.Properties makeProperties(String name, HoneyBottleData honeyData) {
  62.         HoneyFluidAttributes.Builder builder;
  63.         builder = HoneyFluidAttributes.builder(ModFluids.CUSTOM_FLUID_STILL, ModFluids.CUSTOM_FLUID_FLOWING, honeyData);
  64.         builder.overlay(ModFluids.CUSTOM_FLUID_OVERLAY);
  65.         builder.sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY);
  66.         builder.density(1300);
  67.         builder.temperature(300);
  68.         builder.viscosity(1800);
  69.  
  70.         return new ForgeFlowingFluid.Properties(stillFluids.get(name), flowingFluids.get(name), builder)
  71.                 .bucket(honeyBuckets.get(name))
  72.                 .block(fluidBlocks.get(name))
  73.                 .tickRate(20);
  74.     }
  75.  
  76.  
  77. // registring default honey bucket
  78.  
  79.     private static ForgeFlowingFluid.Properties makeProperties() {
  80.         return new ForgeFlowingFluid.Properties(HONEY_STILL, HONEY_FLOWING,
  81.                 FluidAttributes.builder(FLUID_STILL, FLUID_FLOWING).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY)
  82.                         .overlay(FLUID_OVERLAY).density(1300).temperature(300).viscosity(1800).rarity(Rarity.COMMON))
  83.                 .bucket(ModItems.HONEY_FLUID_BUCKET).block(ModBlocks.HONEY_FLUID_BLOCK).tickRate(20);
  84.     }
  85.  
  86.     public static RegistryObject<FlowingFluid> HONEY_STILL = FLUIDS.register("honey", () ->
  87.             new ForgeFlowingFluid.Source(makeProperties())
  88.     );
  89.     public static RegistryObject<FlowingFluid> HONEY_FLOWING = FLUIDS.register("honey_flowing", () ->
  90.             new ForgeFlowingFluid.Flowing(makeProperties())
  91.     );
  92.  
  93.  
  94. 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)));
  95.  
  96. // custom bucket class
  97. public class CustomHoneyBucketItem extends BucketItem {
  98.  
  99.     private final HoneyBottleData honeyBottleData;
  100.  
  101.     public CustomHoneyBucketItem(Supplier<? extends Fluid> supplier, Properties builder, HoneyBottleData honeyBottleData) {
  102.         super(supplier, builder);
  103.         this.honeyBottleData = honeyBottleData;
  104.     }
  105.  
  106.     public static int getColor(ItemStack stack, int tintIndex) {
  107.         if (tintIndex == 1) {
  108.             CustomHoneyBucketItem honeyBottleItem = (CustomHoneyBucketItem) stack.getItem();
  109.             return honeyBottleItem.honeyBottleData.isRainbow() ? RainbowColor.getRGB() : honeyBottleItem.getHoneyBucketColor();
  110.         }
  111.         return BeeConstants.DEFAULT_ITEM_COLOR;
  112.     }
  113.  
  114.     public int getHoneyBucketColor() {
  115.         return honeyBottleData.getHoneyColorInt();
  116.     }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement