Advertisement
CreativeMasterBonin

HeatProducerCodec Fail

Apr 17th, 2025
323
0
12 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. package net.bcm.cmatd.datagen;
  2.  
  3. import com.mojang.serialization.Codec;
  4. import com.mojang.serialization.codecs.RecordCodecBuilder;
  5. import net.minecraft.core.registries.BuiltInRegistries;
  6. import net.minecraft.world.level.block.Block;
  7. import net.minecraft.world.level.block.Blocks;
  8. import net.neoforged.neoforge.registries.datamaps.builtin.Compostable;
  9.  
  10. public record HeatProducers(int heatProduced, boolean turnsIntoAnotherBlock, Block blockToTurnInto, float blockReplacementChance) {
  11.     public static final Codec<HeatProducers> BLOCK_REPLACEMENT_CHANCE = Codec.floatRange(0f, 1f)
  12.             .xmap(HeatProducers::new, HeatProducers::blockReplacementChance);
  13.  
  14.     public static final Codec<HeatProducers> TURNS_INTO_BLOCK = Codec.BOOL
  15.             .xmap(HeatProducers::new, HeatProducers::turnsIntoAnotherBlock);
  16.  
  17.     public static final Codec<HeatProducers> HEAT_PRODUCED = Codec.intRange(1,Integer.MAX_VALUE)
  18.             .xmap(HeatProducers::new,HeatProducers::heatProduced);
  19.  
  20.     public static final Codec<HeatProducers> BLOCK_TO_TURN_INTO = BuiltInRegistries.BLOCK.byNameCodec()
  21.             .xmap(HeatProducers::new, HeatProducers::blockToTurnInto);
  22.  
  23.  
  24.     public static final Codec<Compostable> CODEC = Codec.withAlternative(
  25.             RecordCodecBuilder.create(in -> in.group(
  26.                     Codec.intRange(1,Integer.MAX_VALUE).fieldOf("heat_produced")
  27.                             .forGetter(HeatProducers::heatProduced).apply(in,HeatProducers::new),
  28.                     Codec.BOOL.fieldOf("turns_into_another_block")
  29.                             .forGetter(HeatProducers::turnsIntoAnotherBlock).apply(in,HeatProducers::new),
  30.                     Codec.floatRange(0f, 1f).fieldOf("block_replacement_chance")
  31.                             .forGetter(HeatProducers::blockReplacementChance).apply(in,HeatProducers::new),
  32.                     BuiltInRegistries.BLOCK.byNameCodec().fieldOf("next_oxidation_stage")
  33.                             .forGetter(HeatProducers::blockToTurnInto).apply(in, HeatProducers::new),
  34.             HEAT_PRODUCED,TURNS_INTO_BLOCK,BLOCK_TO_TURN_INTO,BLOCK_REPLACEMENT_CHANCE)));
  35.  
  36.     public HeatProducers(){
  37.         this(0,false, Blocks.AIR,0.0f);
  38.     }
  39.  
  40.     public HeatProducers(int heatProduced){
  41.         this(heatProduced,false,Blocks.AIR,0.0f);
  42.     }
  43.  
  44.     public HeatProducers(boolean turnsIntoAnotherBlock){
  45.         this(0,turnsIntoAnotherBlock,Blocks.AIR,0.0f);
  46.     }
  47.  
  48.     public HeatProducers(Block blockToTurnInto){
  49.         this(0,true,blockToTurnInto,0.0f);
  50.     }
  51.  
  52.     public HeatProducers(float blockReplacementChance){
  53.         this(0,false,Blocks.AIR,blockReplacementChance);
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement