From fd7de643df65dc9c23f3756c699bcbc8eb7358a6 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 24 May 2024 17:59:00 -0400 Subject: [PATCH] Oxidizing and Waxing API --- .../world/item/HoneycombItem.java.patch | 28 ++++++++++++++ .../level/block/WeatheringCopper.java.patch | 28 ++++++++++++++ .../neoforge/common/CommonHooks.java | 38 ++++++++++++++----- 3 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 patches/net/minecraft/world/item/HoneycombItem.java.patch create mode 100644 patches/net/minecraft/world/level/block/WeatheringCopper.java.patch diff --git a/patches/net/minecraft/world/item/HoneycombItem.java.patch b/patches/net/minecraft/world/item/HoneycombItem.java.patch new file mode 100644 index 00000000000..430a321653c --- /dev/null +++ b/patches/net/minecraft/world/item/HoneycombItem.java.patch @@ -0,0 +1,28 @@ +--- a/net/minecraft/world/item/HoneycombItem.java ++++ b/net/minecraft/world/item/HoneycombItem.java +@@ -2,6 +_,7 @@ + + import com.google.common.base.Suppliers; + import com.google.common.collect.BiMap; ++import com.google.common.collect.HashBiMap; + import com.google.common.collect.ImmutableBiMap; + import java.util.Optional; + import java.util.function.Supplier; +@@ -21,7 +_,7 @@ + + public class HoneycombItem extends Item implements SignApplicator { + public static final Supplier> WAXABLES = Suppliers.memoize( +- () -> ImmutableBiMap.builder() ++ () -> HashBiMap.create(ImmutableBiMap.builder() + .put(Blocks.COPPER_BLOCK, Blocks.WAXED_COPPER_BLOCK) + .put(Blocks.EXPOSED_COPPER, Blocks.WAXED_EXPOSED_COPPER) + .put(Blocks.WEATHERED_COPPER, Blocks.WAXED_WEATHERED_COPPER) +@@ -58,7 +_,7 @@ + .put(Blocks.EXPOSED_COPPER_BULB, Blocks.WAXED_EXPOSED_COPPER_BULB) + .put(Blocks.WEATHERED_COPPER_BULB, Blocks.WAXED_WEATHERED_COPPER_BULB) + .put(Blocks.OXIDIZED_COPPER_BULB, Blocks.WAXED_OXIDIZED_COPPER_BULB) +- .build() ++ .build()) + ); + public static final Supplier> WAX_OFF_BY_BLOCK = Suppliers.memoize(() -> WAXABLES.get().inverse()); + diff --git a/patches/net/minecraft/world/level/block/WeatheringCopper.java.patch b/patches/net/minecraft/world/level/block/WeatheringCopper.java.patch new file mode 100644 index 00000000000..c8f11401d36 --- /dev/null +++ b/patches/net/minecraft/world/level/block/WeatheringCopper.java.patch @@ -0,0 +1,28 @@ +--- a/net/minecraft/world/level/block/WeatheringCopper.java ++++ b/net/minecraft/world/level/block/WeatheringCopper.java +@@ -2,6 +_,7 @@ + + import com.google.common.base.Suppliers; + import com.google.common.collect.BiMap; ++import com.google.common.collect.HashBiMap; + import com.google.common.collect.ImmutableBiMap; + import com.mojang.serialization.Codec; + import java.util.Optional; +@@ -11,7 +_,7 @@ + + public interface WeatheringCopper extends ChangeOverTimeBlock { + Supplier> NEXT_BY_BLOCK = Suppliers.memoize( +- () -> ImmutableBiMap.builder() ++ () -> HashBiMap.create(ImmutableBiMap.builder() + .put(Blocks.COPPER_BLOCK, Blocks.EXPOSED_COPPER) + .put(Blocks.EXPOSED_COPPER, Blocks.WEATHERED_COPPER) + .put(Blocks.WEATHERED_COPPER, Blocks.OXIDIZED_COPPER) +@@ -39,7 +_,7 @@ + .put(Blocks.COPPER_BULB, Blocks.EXPOSED_COPPER_BULB) + .put(Blocks.EXPOSED_COPPER_BULB, Blocks.WEATHERED_COPPER_BULB) + .put(Blocks.WEATHERED_COPPER_BULB, Blocks.OXIDIZED_COPPER_BULB) +- .build() ++ .build()) + ); + Supplier> PREVIOUS_BY_BLOCK = Suppliers.memoize(() -> NEXT_BY_BLOCK.get().inverse()); + diff --git a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java index bb93ea6f70c..cb3dc623ef8 100644 --- a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java +++ b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java @@ -98,16 +98,7 @@ import net.minecraft.world.inventory.ClickAction; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.AdventureModePredicate; -import net.minecraft.world.item.BucketItem; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.EnchantedBookItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.PotionItem; -import net.minecraft.world.item.SpawnEggItem; -import net.minecraft.world.item.Tiers; -import net.minecraft.world.item.TippedArrowItem; +import net.minecraft.world.item.*; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.context.UseOnContext; @@ -124,6 +115,7 @@ import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.WeatheringCopper; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.pattern.BlockInWorld; @@ -1360,4 +1352,30 @@ public static void onChunkUnload(PoiManager poiManager, ChunkAccess chunkAccess) poiManager.remove(sectionPosKey); } } + + /** + * Registers a before and after blocks that can oxidize and de-oxidize + * + * @param before block with less oxidization + * @param after block with more oxidization + */ + public static void registerOxidizableBlock(Block before, Block after) { + Objects.requireNonNull(before, "Oxidizable Block before must not be null"); + Objects.requireNonNull(after, "Oxidizable Block after must not be null"); + + WeatheringCopper.NEXT_BY_BLOCK.get().put(before, after); + } + + /** + * Registers a before and after blocks that can be waxed and unwaxed + * + * @param before the unwaxed block + * @param after the waxed block + */ + public static void registerWaxableBlock(Block before, Block after) { + Objects.requireNonNull(before, "Waxable before before must not be null"); + Objects.requireNonNull(after, "Waxable Block after must not be null"); + + HoneycombItem.WAXABLES.get().put(before, after); + } }