Skip to content

Commit

Permalink
Oxidizing and Waxing API
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed May 24, 2024
1 parent 66197fe commit fd7de64
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
28 changes: 28 additions & 0 deletions patches/net/minecraft/world/item/HoneycombItem.java.patch
Original file line number Diff line number Diff line change
@@ -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<BiMap<Block, Block>> WAXABLES = Suppliers.memoize(
- () -> ImmutableBiMap.<Block, Block>builder()
+ () -> HashBiMap.create(ImmutableBiMap.<Block, Block>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<BiMap<Block, Block>> WAX_OFF_BY_BLOCK = Suppliers.memoize(() -> WAXABLES.get().inverse());

Original file line number Diff line number Diff line change
@@ -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<WeatheringCopper.WeatherState> {
Supplier<BiMap<Block, Block>> NEXT_BY_BLOCK = Suppliers.memoize(
- () -> ImmutableBiMap.<Block, Block>builder()
+ () -> HashBiMap.create(ImmutableBiMap.<Block, Block>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<BiMap<Block, Block>> PREVIOUS_BY_BLOCK = Suppliers.memoize(() -> NEXT_BY_BLOCK.get().inverse());

38 changes: 28 additions & 10 deletions src/main/java/net/neoforged/neoforge/common/CommonHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit fd7de64

Please sign in to comment.