Advertisement
Vaerys_Dawn

Rainbow Recolour

Dec 22nd, 2020
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 KB | None | 0 0
  1. // in ColorHandler
  2.  
  3.     public static void onBlockColors(ColorHandlerEvent.Block event) {
  4.         BlockColors colors = event.getBlockColors();
  5.         BEE_REGISTRY.getBees().forEach(((s, customBeeData) -> {
  6.             if (customBeeData.hasHoneycomb() && customBeeData.getColorData().hasHoneycombColor() && !customBeeData.hasCustomDrop()) {
  7.                 registerBlocks(colors, HoneycombBlock::getBlockColor, customBeeData.getCombBlockRegistryObject().get());
  8.             }
  9.         }));
  10.         BEE_REGISTRY.getHoneyBottles().forEach((h, honeyData) -> {
  11.             registerBlocks(colors, CustomHoneyBlock::getBlockColor, honeyData.getHoneyBlockRegistryObject().get());
  12.             registerBlocks(colors, CustomHoneyFluidBlock::getBlockColor, honeyData.getHoneyFluidBlockRegistryObject().get());
  13.         });
  14.     }
  15.  
  16.     private static void registerBlocks(BlockColors handler, IBlockColor blockColor, Block... blocks) {
  17.         try {
  18.             handler.register(blockColor, blocks);
  19.         } catch (NullPointerException ex) {
  20.             LOGGER.error("BlockColor Registration Failed", ex);
  21.         }
  22.     }
  23.  
  24. // in CustomHoneyFluidBlock
  25.  
  26.     public static int getBlockColor(BlockState state, @Nullable IBlockReader world, @Nullable BlockPos pos, int tintIndex) {
  27.         CustomHoneyFluidBlock honeycombBlock = ((CustomHoneyFluidBlock) state.getBlock());
  28.         return honeycombBlock.honeyData.isRainbow() ? RainbowColor.getRGB() : honeycombBlock.getHoneyColor();
  29.     }
  30.  
  31.     @Override
  32.     public void animateTick(@Nonnull BlockState stateIn, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Random rand) {
  33.         if (honeyData.isRainbow())
  34.             world.notifyBlockUpdate(pos, stateIn, stateIn, 2);
  35.         super.animateTick(stateIn, world, pos, rand);
  36.     }
  37.  
  38. // in Regisrty Handler
  39.  
  40.     private static Map<String, RegistryObject<FlowingFluid>> stillFluids = new HashMap<>();
  41.     private static Map<String, RegistryObject<FlowingFluid>> flowingFluids = new HashMap<>();
  42.     private static Map<String, RegistryObject<Item>> honeyBuckets = new HashMap<>();
  43.     private static Map<String, RegistryObject<FlowingFluidBlock>> fluidBlocks = new HashMap<>();
  44.  
  45.     private static void registerHoneyBottle(String name, HoneyBottleData honeyData) {
  46.         final RegistryObject<Block> customHoneyBlock = ModBlocks.BLOCKS.register(name + "_honey_block", () -> new CustomHoneyBlock(honeyData));
  47.         final RegistryObject<Item> customHoneyBottle = ModItems.ITEMS.register(name + "_honey_bottle", () -> new CustomHoneyBottleItem(honeyData.getProperties(), honeyData));
  48.         final RegistryObject<Item> customHoneyBlockItem = ModItems.ITEMS.register(name + "_honey_block", () -> new BlockItem(customHoneyBlock.get(), new Item.Properties().group(ItemGroupResourcefulBees.RESOURCEFUL_BEES)));
  49.  
  50.         stillFluids.put(name, ModFluids.FLUIDS.register(name + "_honey", () -> new ForgeFlowingFluid.Source(makeProperties(name, honeyData))));
  51.         flowingFluids.put(name, ModFluids.FLUIDS.register(name + "_honey_flowing", () -> new ForgeFlowingFluid.Flowing(makeProperties(name, honeyData))));
  52.         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)));
  53.         fluidBlocks.put(name, ModBlocks.BLOCKS.register(name + "_honey_fluid_block", () -> new CustomHoneyFluidBlock(stillFluids.get(name), Block.Properties.create(Material.WATER).doesNotBlockMovement().hardnessAndResistance(100.0F).noDrops(), honeyData)));
  54.  
  55.         honeyData.setHoneyBottleRegistryObject(customHoneyBottle);
  56.         honeyData.setHoneyBlockRegistryObject(customHoneyBlock);
  57.         honeyData.setHoneyBlockItemRegistryObject(customHoneyBlockItem);
  58.         honeyData.setHoneyStillFluidRegistryObject(stillFluids.get(name));
  59.         honeyData.setHoneyFlowingFluidRegistryObject(stillFluids.get(name));
  60.         honeyData.setHoneyBucketItemRegistryObject(honeyBuckets.get(name));
  61.         honeyData.setHoneyFluidBlockRegistryObject(fluidBlocks.get(name));
  62.     }
  63.  
  64.     private static ForgeFlowingFluid.Properties makeProperties(String name, HoneyBottleData honeyData) {
  65.         FluidAttributes.Builder builder;
  66.         builder = FluidAttributes.builder(ModFluids.CUSTOM_FLUID_STILL, ModFluids.CUSTOM_FLUID_FLOWING);
  67.         builder.overlay(ModFluids.CUSTOM_FLUID_OVERLAY);
  68. //        builder.color(honeyData.getHoneyColorInt());
  69.         builder.sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY);
  70.         builder.density(1300);
  71.         builder.temperature(300);
  72.         builder.viscosity(1800);
  73.  
  74.         return new ForgeFlowingFluid.Properties(stillFluids.get(name), flowingFluids.get(name), builder)
  75.                 .bucket(honeyBuckets.get(name))
  76.                 .block(fluidBlocks.get(name))
  77.                 .tickRate(20);
  78.     }
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement