mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Oxidizable and Waxable Blocks registries (#1832)
* Oxidizable Blocks registry * Allow waxable blocks to be registered outside of OxidizableFamilies * Refactor Separated OxidizableBlocksRegistry and WaxableBlocksRegistry Separated OxidizableFamily and WaxableBlockPair Added null check to WaxableBlockPair Added several methods * whoops lol * Apply suggestions from code review Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> * Update ContentRegistryTest.java * Refactor again lol Now uses mixins to change the vanilla ImmutableBiMaps to HashBiMaps and adds to them instead of keeping separate maps and having methods of their own. Much cleaner! * gutted everything lol removed all the charm and character- uh, i mean, superfluous stuff and reduced the api to the bare basics oh and also one-way methods which is neat i guess if you're into that sort of thing * 🦀one way methods are gone🦀 all my homies hate one way methods maps are linked again * re-merged oxidizable and waxable registry classes * Update ContentRegistryTest.java * implement suggestions by @Juuxel * Oxidization -> Oxidation as per https://github.com/FabricMC/yarn/pull/2837 * Improve Dynamics Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>
This commit is contained in:
parent
295197a789
commit
f7c1d59979
5 changed files with 162 additions and 1 deletions
fabric-content-registries-v0/src
main
java/net/fabricmc/fabric
api/registry
mixin/content/registry
resources
testmod/java/net/fabricmc/fabric/test/content/registry
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.registry;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Oxidizable;
|
||||
import net.minecraft.item.HoneycombItem;
|
||||
|
||||
/**
|
||||
* Provides methods for registering oxidizable and waxable blocks.
|
||||
*/
|
||||
public final class OxidizableBlocksRegistry {
|
||||
private OxidizableBlocksRegistry() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block pair as being able to increase and decrease oxidation.
|
||||
*
|
||||
* @param less the variant with less oxidation
|
||||
* @param more the variant with more oxidation
|
||||
*/
|
||||
public static void registerOxidizableBlockPair(Block less, Block more) {
|
||||
Objects.requireNonNull(less, "Oxidizable block cannot be null!");
|
||||
Objects.requireNonNull(more, "Oxidizable block cannot be null!");
|
||||
Oxidizable.OXIDATION_LEVEL_INCREASES.get().put(less, more);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block pair as being able to add and remove wax.
|
||||
*
|
||||
* @param unwaxed the unwaxed variant
|
||||
* @param waxed the waxed variant
|
||||
*/
|
||||
public static void registerWaxableBlockPair(Block unwaxed, Block waxed) {
|
||||
Objects.requireNonNull(unwaxed, "Unwaxed block cannot be null!");
|
||||
Objects.requireNonNull(waxed, "Waxed block cannot be null!");
|
||||
HoneycombItem.UNWAXED_TO_WAXED_BLOCKS.get().put(unwaxed, waxed);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.content.registry;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.spongepowered.asm.mixin.Dynamic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.item.HoneycombItem;
|
||||
|
||||
@Mixin(HoneycombItem.class)
|
||||
public class HoneycombItemMixin {
|
||||
@Dynamic("method_34723: Synthetic lambda body for Suppliers.memoize in initialization of UNWAXED_TO_WAXED_BLOCKS")
|
||||
@Inject(method = "method_34723", at = @At("RETURN"), cancellable = true)
|
||||
private static void createUnwaxedToWaxedMap(CallbackInfoReturnable<BiMap> cir) {
|
||||
cir.setReturnValue(HashBiMap.create(cir.getReturnValue()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.content.registry;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.spongepowered.asm.mixin.Dynamic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.block.Oxidizable;
|
||||
|
||||
@Mixin(Oxidizable.class)
|
||||
public interface OxidizableMixin {
|
||||
@Dynamic("method_34740: Synthetic lambda body for Suppliers.memoize in initialization of OXIDATION_LEVEL_INCREASES")
|
||||
@Inject(method = "method_34740", at = @At("RETURN"), cancellable = true)
|
||||
private static void createOxidationLevelIncreasesMap(CallbackInfoReturnable<BiMap> cir) {
|
||||
cir.setReturnValue(HashBiMap.create(cir.getReturnValue()));
|
||||
}
|
||||
}
|
|
@ -5,8 +5,10 @@
|
|||
"mixins": [
|
||||
"AxeItemAccessor",
|
||||
"HoeItemAccessor",
|
||||
"HoneycombItemMixin",
|
||||
"MixinAbstractFurnaceBlockEntity",
|
||||
"MixinFireBlock",
|
||||
"OxidizableMixin",
|
||||
"ShovelItemAccessor"
|
||||
],
|
||||
"client": [
|
||||
|
|
|
@ -16,21 +16,29 @@
|
|||
|
||||
package net.fabricmc.fabric.test.content.registry;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.HoeItem;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.registry.FlattenableBlockRegistry;
|
||||
import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry;
|
||||
import net.fabricmc.fabric.api.registry.StrippableBlockRegistry;
|
||||
import net.fabricmc.fabric.api.registry.TillableBlockRegistry;
|
||||
|
||||
public final class ContentRegistryTest implements ModInitializer {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// Expected behavior:
|
||||
// - red wool is flattenable to yellow wool
|
||||
// - quartz pillars are strippable to hay blocks
|
||||
// - green wool is tillable to lime wool
|
||||
// - copper ore, iron ore, gold ore, and diamond ore can be waxed into their deepslate variants and scraped back again
|
||||
// - aforementioned ores can be scraped from diamond -> gold -> iron -> copper
|
||||
|
||||
FlattenableBlockRegistry.register(Blocks.RED_WOOL, Blocks.YELLOW_WOOL.getDefaultState());
|
||||
StrippableBlockRegistry.register(Blocks.QUARTZ_PILLAR, Blocks.HAY_BLOCK);
|
||||
|
@ -39,11 +47,35 @@ public final class ContentRegistryTest implements ModInitializer {
|
|||
try {
|
||||
StrippableBlockRegistry.register(Blocks.BLUE_WOOL, Blocks.OAK_LOG);
|
||||
StrippableBlockRegistry.register(Blocks.HAY_BLOCK, Blocks.BLUE_WOOL);
|
||||
throw new AssertionError("StrippableBlockRegistry didn't throw when blocks where missing the 'axis' property!");
|
||||
throw new AssertionError("StrippableBlockRegistry didn't throw when blocks were missing the 'axis' property!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected behavior
|
||||
LOGGER.info("StrippableBlockRegistry test passed!");
|
||||
}
|
||||
|
||||
TillableBlockRegistry.register(Blocks.GREEN_WOOL, context -> true, HoeItem.createTillAction(Blocks.LIME_WOOL.getDefaultState()));
|
||||
|
||||
OxidizableBlocksRegistry.registerOxidizableBlockPair(Blocks.COPPER_ORE, Blocks.IRON_ORE);
|
||||
OxidizableBlocksRegistry.registerOxidizableBlockPair(Blocks.IRON_ORE, Blocks.GOLD_ORE);
|
||||
OxidizableBlocksRegistry.registerOxidizableBlockPair(Blocks.GOLD_ORE, Blocks.DIAMOND_ORE);
|
||||
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE);
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE);
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE);
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE);
|
||||
|
||||
// assert that OxidizableBlocksRegistry throws when registered blocks are null
|
||||
try {
|
||||
OxidizableBlocksRegistry.registerOxidizableBlockPair(Blocks.EMERALD_ORE, null);
|
||||
OxidizableBlocksRegistry.registerOxidizableBlockPair(null, Blocks.COAL_ORE);
|
||||
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(null, Blocks.DEAD_BRAIN_CORAL);
|
||||
OxidizableBlocksRegistry.registerWaxableBlockPair(Blocks.BRAIN_CORAL, null);
|
||||
|
||||
throw new AssertionError("OxidizableBlocksRegistry didn't throw when blocks were null!");
|
||||
} catch (NullPointerException e) {
|
||||
// expected behavior
|
||||
LOGGER.info("OxidizableBlocksRegistry test passed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue