Skip to content

Commit

Permalink
Waxing & Oxidizing DataMaps (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 8, 2024
1 parent 8d4a78d commit 8787518
Show file tree
Hide file tree
Showing 15 changed files with 600 additions and 2 deletions.
10 changes: 10 additions & 0 deletions patches/net/minecraft/data/recipes/RecipeProvider.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@
BlockFamilies.getAllFamilies().filter(BlockFamily::shouldGenerateRecipe).forEach(p_313461_ -> generateRecipes(p_301146_, p_313461_, p_251836_));
}

@@ -611,8 +_,7 @@
}

protected static void waxRecipes(RecipeOutput p_301254_, FeatureFlagSet p_313879_) {
- HoneycombItem.WAXABLES
- .get()
+ net.neoforged.neoforge.common.DataMapHooks.INVERSE_WAXABLES_DATAMAP
.forEach(
(p_337490_, p_337491_) -> {
if (p_337491_.requiredFeatures().isSubsetOf(p_313879_)) {
33 changes: 33 additions & 0 deletions patches/net/minecraft/world/item/HoneycombItem.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--- a/net/minecraft/world/item/HoneycombItem.java
+++ b/net/minecraft/world/item/HoneycombItem.java
@@ -20,6 +_,10 @@
import net.minecraft.world.level.gameevent.GameEvent;

public class HoneycombItem extends Item implements SignApplicator {
+ /**
+ * @deprecated Neo: Use the {@link net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps#WAXABLES data map}, this field will be ignored in a future version
+ */
+ @Deprecated
public static final Supplier<BiMap<Block, Block>> WAXABLES = Suppliers.memoize(
() -> ImmutableBiMap.<Block, Block>builder()
.put(Blocks.COPPER_BLOCK, Blocks.WAXED_COPPER_BLOCK)
@@ -60,6 +_,10 @@
.put(Blocks.OXIDIZED_COPPER_BULB, Blocks.WAXED_OXIDIZED_COPPER_BULB)
.build()
);
+ /**
+ * @deprecated Use the {@link net.neoforged.neoforge.common.DataMapHooks#INVERSE_WAXABLES_DATAMAP inverse map} generated from the data map, this field will be ignored in a future version
+ */
+ @Deprecated
public static final Supplier<BiMap<Block, Block>> WAX_OFF_BY_BLOCK = Suppliers.memoize(() -> WAXABLES.get().inverse());

public HoneycombItem(Item.Properties p_150867_) {
@@ -87,7 +_,7 @@
}

public static Optional<BlockState> getWaxed(BlockState p_150879_) {
- return Optional.ofNullable(WAXABLES.get().get(p_150879_.getBlock())).map(p_150877_ -> p_150877_.withPropertiesOf(p_150879_));
+ return Optional.ofNullable(net.neoforged.neoforge.common.DataMapHooks.getBlockWaxed(p_150879_.getBlock())).map(p_150877_ -> p_150877_.withPropertiesOf(p_150879_));
}

@Override
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--- a/net/minecraft/world/level/block/WeatheringCopper.java
+++ b/net/minecraft/world/level/block/WeatheringCopper.java
@@ -10,6 +_,10 @@
import net.minecraft.world.level.block.state.BlockState;

public interface WeatheringCopper extends ChangeOverTimeBlock<WeatheringCopper.WeatherState> {
+ /**
+ * @deprecated Neo: Use {@link net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps#OXIDIZABLES the data map}, this field will be ignored in a future version
+ */
+ @Deprecated
Supplier<BiMap<Block, Block>> NEXT_BY_BLOCK = Suppliers.memoize(
() -> ImmutableBiMap.<Block, Block>builder()
.put(Blocks.COPPER_BLOCK, Blocks.EXPOSED_COPPER)
@@ -41,16 +_,20 @@
.put(Blocks.WEATHERED_COPPER_BULB, Blocks.OXIDIZED_COPPER_BULB)
.build()
);
+ /**
+ * @deprecated Neo: Use the {@link net.neoforged.neoforge.common.DataMapHooks#INVERSE_OXIDIZABLES_DATAMAP inverse map} generated from the data map, this field will be ignored in a future version
+ */
+ @Deprecated
Supplier<BiMap<Block, Block>> PREVIOUS_BY_BLOCK = Suppliers.memoize(() -> NEXT_BY_BLOCK.get().inverse());

static Optional<Block> getPrevious(Block p_154891_) {
- return Optional.ofNullable(PREVIOUS_BY_BLOCK.get().get(p_154891_));
+ return Optional.ofNullable(net.neoforged.neoforge.common.DataMapHooks.getPreviousOxidizedStage(p_154891_));
}

static Block getFirst(Block p_154898_) {
Block block = p_154898_;

- for (Block block1 = PREVIOUS_BY_BLOCK.get().get(p_154898_); block1 != null; block1 = PREVIOUS_BY_BLOCK.get().get(block1)) {
+ for (Block block1 = net.neoforged.neoforge.common.DataMapHooks.getPreviousOxidizedStage(p_154898_); block1 != null; block1 = net.neoforged.neoforge.common.DataMapHooks.getPreviousOxidizedStage(block1)) {
block = block1;
}

@@ -62,7 +_,7 @@
}

static Optional<Block> getNext(Block p_154905_) {
- return Optional.ofNullable(NEXT_BY_BLOCK.get().get(p_154905_));
+ return Optional.ofNullable(net.neoforged.neoforge.common.DataMapHooks.getNextOxidizedStage(p_154905_));
}

static BlockState getFirst(BlockState p_154907_) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"values": {
"minecraft:chiseled_copper": {
"next_oxidation_stage": "minecraft:exposed_chiseled_copper"
},
"minecraft:copper_block": {
"next_oxidation_stage": "minecraft:exposed_copper"
},
"minecraft:copper_bulb": {
"next_oxidation_stage": "minecraft:exposed_copper_bulb"
},
"minecraft:copper_door": {
"next_oxidation_stage": "minecraft:exposed_copper_door"
},
"minecraft:copper_grate": {
"next_oxidation_stage": "minecraft:exposed_copper_grate"
},
"minecraft:copper_trapdoor": {
"next_oxidation_stage": "minecraft:exposed_copper_trapdoor"
},
"minecraft:cut_copper": {
"next_oxidation_stage": "minecraft:exposed_cut_copper"
},
"minecraft:cut_copper_slab": {
"next_oxidation_stage": "minecraft:exposed_cut_copper_slab"
},
"minecraft:cut_copper_stairs": {
"next_oxidation_stage": "minecraft:exposed_cut_copper_stairs"
},
"minecraft:exposed_chiseled_copper": {
"next_oxidation_stage": "minecraft:weathered_chiseled_copper"
},
"minecraft:exposed_copper": {
"next_oxidation_stage": "minecraft:weathered_copper"
},
"minecraft:exposed_copper_bulb": {
"next_oxidation_stage": "minecraft:weathered_copper_bulb"
},
"minecraft:exposed_copper_door": {
"next_oxidation_stage": "minecraft:weathered_copper_door"
},
"minecraft:exposed_copper_grate": {
"next_oxidation_stage": "minecraft:weathered_copper_grate"
},
"minecraft:exposed_copper_trapdoor": {
"next_oxidation_stage": "minecraft:weathered_copper_trapdoor"
},
"minecraft:exposed_cut_copper": {
"next_oxidation_stage": "minecraft:weathered_cut_copper"
},
"minecraft:exposed_cut_copper_slab": {
"next_oxidation_stage": "minecraft:weathered_cut_copper_slab"
},
"minecraft:exposed_cut_copper_stairs": {
"next_oxidation_stage": "minecraft:weathered_cut_copper_stairs"
},
"minecraft:weathered_chiseled_copper": {
"next_oxidation_stage": "minecraft:oxidized_chiseled_copper"
},
"minecraft:weathered_copper": {
"next_oxidation_stage": "minecraft:oxidized_copper"
},
"minecraft:weathered_copper_bulb": {
"next_oxidation_stage": "minecraft:oxidized_copper_bulb"
},
"minecraft:weathered_copper_door": {
"next_oxidation_stage": "minecraft:oxidized_copper_door"
},
"minecraft:weathered_copper_grate": {
"next_oxidation_stage": "minecraft:oxidized_copper_grate"
},
"minecraft:weathered_copper_trapdoor": {
"next_oxidation_stage": "minecraft:oxidized_copper_trapdoor"
},
"minecraft:weathered_cut_copper": {
"next_oxidation_stage": "minecraft:oxidized_cut_copper"
},
"minecraft:weathered_cut_copper_slab": {
"next_oxidation_stage": "minecraft:oxidized_cut_copper_slab"
},
"minecraft:weathered_cut_copper_stairs": {
"next_oxidation_stage": "minecraft:oxidized_cut_copper_stairs"
}
}
}
112 changes: 112 additions & 0 deletions src/generated/resources/data/neoforge/data_maps/block/waxables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"values": {
"minecraft:chiseled_copper": {
"waxed": "minecraft:waxed_chiseled_copper"
},
"minecraft:copper_block": {
"waxed": "minecraft:waxed_copper_block"
},
"minecraft:copper_bulb": {
"waxed": "minecraft:waxed_copper_bulb"
},
"minecraft:copper_door": {
"waxed": "minecraft:waxed_copper_door"
},
"minecraft:copper_grate": {
"waxed": "minecraft:waxed_copper_grate"
},
"minecraft:copper_trapdoor": {
"waxed": "minecraft:waxed_copper_trapdoor"
},
"minecraft:cut_copper": {
"waxed": "minecraft:waxed_cut_copper"
},
"minecraft:cut_copper_slab": {
"waxed": "minecraft:waxed_cut_copper_slab"
},
"minecraft:cut_copper_stairs": {
"waxed": "minecraft:waxed_cut_copper_stairs"
},
"minecraft:exposed_chiseled_copper": {
"waxed": "minecraft:waxed_exposed_chiseled_copper"
},
"minecraft:exposed_copper": {
"waxed": "minecraft:waxed_exposed_copper"
},
"minecraft:exposed_copper_bulb": {
"waxed": "minecraft:waxed_exposed_copper_bulb"
},
"minecraft:exposed_copper_door": {
"waxed": "minecraft:waxed_exposed_copper_door"
},
"minecraft:exposed_copper_grate": {
"waxed": "minecraft:waxed_exposed_copper_grate"
},
"minecraft:exposed_copper_trapdoor": {
"waxed": "minecraft:waxed_exposed_copper_trapdoor"
},
"minecraft:exposed_cut_copper": {
"waxed": "minecraft:waxed_exposed_cut_copper"
},
"minecraft:exposed_cut_copper_slab": {
"waxed": "minecraft:waxed_exposed_cut_copper_slab"
},
"minecraft:exposed_cut_copper_stairs": {
"waxed": "minecraft:waxed_exposed_cut_copper_stairs"
},
"minecraft:oxidized_chiseled_copper": {
"waxed": "minecraft:waxed_oxidized_chiseled_copper"
},
"minecraft:oxidized_copper": {
"waxed": "minecraft:waxed_oxidized_copper"
},
"minecraft:oxidized_copper_bulb": {
"waxed": "minecraft:waxed_oxidized_copper_bulb"
},
"minecraft:oxidized_copper_door": {
"waxed": "minecraft:waxed_oxidized_copper_door"
},
"minecraft:oxidized_copper_grate": {
"waxed": "minecraft:waxed_oxidized_copper_grate"
},
"minecraft:oxidized_copper_trapdoor": {
"waxed": "minecraft:waxed_oxidized_copper_trapdoor"
},
"minecraft:oxidized_cut_copper": {
"waxed": "minecraft:waxed_oxidized_cut_copper"
},
"minecraft:oxidized_cut_copper_slab": {
"waxed": "minecraft:waxed_oxidized_cut_copper_slab"
},
"minecraft:oxidized_cut_copper_stairs": {
"waxed": "minecraft:waxed_oxidized_cut_copper_stairs"
},
"minecraft:weathered_chiseled_copper": {
"waxed": "minecraft:waxed_weathered_chiseled_copper"
},
"minecraft:weathered_copper": {
"waxed": "minecraft:waxed_weathered_copper"
},
"minecraft:weathered_copper_bulb": {
"waxed": "minecraft:waxed_weathered_copper_bulb"
},
"minecraft:weathered_copper_door": {
"waxed": "minecraft:waxed_weathered_copper_door"
},
"minecraft:weathered_copper_grate": {
"waxed": "minecraft:waxed_weathered_copper_grate"
},
"minecraft:weathered_copper_trapdoor": {
"waxed": "minecraft:waxed_weathered_copper_trapdoor"
},
"minecraft:weathered_cut_copper": {
"waxed": "minecraft:waxed_weathered_cut_copper"
},
"minecraft:weathered_cut_copper_slab": {
"waxed": "minecraft:waxed_weathered_cut_copper_slab"
},
"minecraft:weathered_cut_copper_stairs": {
"waxed": "minecraft:waxed_weathered_cut_copper_stairs"
}
}
}
96 changes: 96 additions & 0 deletions src/main/java/net/neoforged/neoforge/common/DataMapHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.common;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.HoneycombItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeatheringCopper;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.registries.datamaps.DataMapsUpdatedEvent;
import net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps;
import net.neoforged.neoforge.registries.datamaps.builtin.Oxidizable;
import net.neoforged.neoforge.registries.datamaps.builtin.Waxable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

// TODO: 1.21.2 remove fallback to vanilla map for waxing and oxidizing
public class DataMapHooks {
// will be removed in 1.21.2
/** Used in a gametest */
@ApiStatus.Internal
public static boolean didHaveToFallbackToVanillaMaps = false;

private static final Map<Block, Block> INVERSE_OXIDIZABLES_DATAMAP_INTERNAL = new HashMap<>();
private static final Map<Block, Block> INVERSE_WAXABLES_DATAMAP_INTERNAL = new HashMap<>();

/** The inverse map of the oxidizables data map, used in vanilla when scraping oxidization off of a block */
public static final Map<Block, Block> INVERSE_OXIDIZABLES_DATAMAP = Collections.unmodifiableMap(INVERSE_OXIDIZABLES_DATAMAP_INTERNAL);
/** The inverse map of the waxables data map, used in vanilla when scraping wax off of a block */
public static final Map<Block, Block> INVERSE_WAXABLES_DATAMAP = Collections.unmodifiableMap(INVERSE_WAXABLES_DATAMAP_INTERNAL);

@Nullable
@SuppressWarnings("deprecation")
public static Block getNextOxidizedStage(Block block) {
Oxidizable oxidizable = block.builtInRegistryHolder().getData(NeoForgeDataMaps.OXIDIZABLES);
return oxidizable != null ? oxidizable.nextOxidationStage() : WeatheringCopper.NEXT_BY_BLOCK.get().get(block);
}

@Nullable
@SuppressWarnings("deprecation")
public static Block getPreviousOxidizedStage(Block block) {
return INVERSE_OXIDIZABLES_DATAMAP.containsKey(block) ? INVERSE_OXIDIZABLES_DATAMAP.get(block) : WeatheringCopper.PREVIOUS_BY_BLOCK.get().get(block);
}

@Nullable
@SuppressWarnings("deprecation")
public static Block getBlockWaxed(Block block) {
Waxable waxable = block.builtInRegistryHolder().getData(NeoForgeDataMaps.WAXABLES);
return waxable != null ? waxable.waxed() : HoneycombItem.WAXABLES.get().get(block);
}

@Nullable
@SuppressWarnings("deprecation")
public static Block getBlockUnwaxed(Block block) {
return INVERSE_WAXABLES_DATAMAP.containsKey(block) ? INVERSE_WAXABLES_DATAMAP.get(block) : HoneycombItem.WAX_OFF_BY_BLOCK.get().get(block);
}

@SubscribeEvent
static void onDataMapsUpdated(DataMapsUpdatedEvent event) {
event.ifRegistry(Registries.BLOCK, registry -> {
INVERSE_OXIDIZABLES_DATAMAP_INTERNAL.clear();
INVERSE_WAXABLES_DATAMAP_INTERNAL.clear();

registry.getDataMap(NeoForgeDataMaps.OXIDIZABLES).forEach((resourceKey, oxidizable) -> {
INVERSE_OXIDIZABLES_DATAMAP_INTERNAL.put(oxidizable.nextOxidationStage(), BuiltInRegistries.BLOCK.get(resourceKey));
});

//noinspection deprecation
WeatheringCopper.PREVIOUS_BY_BLOCK.get().forEach((after, before) -> {
if (!INVERSE_OXIDIZABLES_DATAMAP_INTERNAL.containsKey(after)) {
INVERSE_OXIDIZABLES_DATAMAP_INTERNAL.put(after, before);
didHaveToFallbackToVanillaMaps = true;
}
});

registry.getDataMap(NeoForgeDataMaps.WAXABLES).forEach((resourceKey, waxable) -> {
INVERSE_WAXABLES_DATAMAP_INTERNAL.put(waxable.waxed(), BuiltInRegistries.BLOCK.get(resourceKey));
});

//noinspection deprecation
HoneycombItem.WAX_OFF_BY_BLOCK.get().forEach((after, before) -> {
if (!INVERSE_WAXABLES_DATAMAP_INTERNAL.containsKey(after)) {
INVERSE_OXIDIZABLES_DATAMAP_INTERNAL.put(after, before);
didHaveToFallbackToVanillaMaps = true;
}
});
});
}
}
Loading

0 comments on commit 8787518

Please sign in to comment.