mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Add and test for missing method overrides in FabricBlockSettings (#3056)
This commit is contained in:
parent
c53558c7e5
commit
4d8536c91f
13 changed files with 172 additions and 25 deletions
fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup
fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen
fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event
fabric-item-api-v1/src/testmod/java/net/fabricmc/fabric/test/item
fabric-mining-level-api-v1/src/testmod/java/net/fabricmc/fabric/test/mininglevel
fabric-object-builder-api-v1/src
main/java/net/fabricmc/fabric/api/object/builder/v1/block
testmod
fabric-registry-sync-v0/src/testmod/java/net/fabricmc/fabric/test/registry/sync
fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/simple
fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame
gradle.properties
|
@ -41,17 +41,17 @@ public class FabricApiLookupTest implements ModInitializer {
|
|||
public static final String MOD_ID = "fabric-lookup-api-v1-testmod";
|
||||
// Chute - Block without model that transfers item from the container above to the container below.
|
||||
// It's meant to work with unsided containers: chests, dispensers, droppers and hoppers.
|
||||
public static final ChuteBlock CHUTE_BLOCK = new ChuteBlock(FabricBlockSettings.of());
|
||||
public static final ChuteBlock CHUTE_BLOCK = new ChuteBlock(FabricBlockSettings.create());
|
||||
public static final BlockItem CHUTE_ITEM = new BlockItem(CHUTE_BLOCK, new Item.Settings());
|
||||
public static BlockEntityType<ChuteBlockEntity> CHUTE_BLOCK_ENTITY_TYPE;
|
||||
// Cobble gen - Block without model that can generate infinite cobblestone when placed above a chute.
|
||||
// It's meant to test BlockApiLookup#registerSelf.
|
||||
public static final CobbleGenBlock COBBLE_GEN_BLOCK = new CobbleGenBlock(FabricBlockSettings.of());
|
||||
public static final CobbleGenBlock COBBLE_GEN_BLOCK = new CobbleGenBlock(FabricBlockSettings.create());
|
||||
public static final BlockItem COBBLE_GEN_ITEM = new BlockItem(COBBLE_GEN_BLOCK, new Item.Settings());
|
||||
public static BlockEntityType<CobbleGenBlockEntity> COBBLE_GEN_BLOCK_ENTITY_TYPE;
|
||||
// Testing for item api lookups is done in the `item` package.
|
||||
|
||||
public static final InspectorBlock INSPECTOR_BLOCK = new InspectorBlock(FabricBlockSettings.of());
|
||||
public static final InspectorBlock INSPECTOR_BLOCK = new InspectorBlock(FabricBlockSettings.create());
|
||||
public static final BlockItem INSPECTOR_ITEM = new BlockItem(INSPECTOR_BLOCK, new Item.Settings());
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,11 +48,11 @@ public class DataGeneratorTestContent implements ModInitializer {
|
|||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.of());
|
||||
BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false, AbstractBlock.Settings.of());
|
||||
BLOCK_WITHOUT_LOOT_TABLE = createBlock("block_without_loot_table", false, AbstractBlock.Settings.of());
|
||||
BLOCK_WITH_VANILLA_LOOT_TABLE = createBlock("block_with_vanilla_loot_table", false, AbstractBlock.Settings.of().dropsLike(Blocks.STONE));
|
||||
BLOCK_THAT_DROPS_NOTHING = createBlock("block_that_drops_nothing", false, AbstractBlock.Settings.of().dropsNothing());
|
||||
SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.create());
|
||||
BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false, AbstractBlock.Settings.create());
|
||||
BLOCK_WITHOUT_LOOT_TABLE = createBlock("block_without_loot_table", false, AbstractBlock.Settings.create());
|
||||
BLOCK_WITH_VANILLA_LOOT_TABLE = createBlock("block_with_vanilla_loot_table", false, AbstractBlock.Settings.create().dropsLike(Blocks.STONE));
|
||||
BLOCK_THAT_DROPS_NOTHING = createBlock("block_that_drops_nothing", false, AbstractBlock.Settings.create().dropsNothing());
|
||||
|
||||
ItemGroupEvents.modifyEntriesEvent(SIMPLE_ITEM_GROUP).register(entries -> entries.add(SIMPLE_BLOCK));
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
|
|||
|
||||
public final class EntityEventTests implements ModInitializer {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EntityEventTests.class);
|
||||
public static final Block TEST_BED = new TestBedBlock(AbstractBlock.Settings.of().strength(1, 1));
|
||||
public static final Block TEST_BED = new TestBedBlock(AbstractBlock.Settings.create().strength(1, 1));
|
||||
public static final Item DIAMOND_ELYTRA = new DiamondElytraItem();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,11 +16,17 @@
|
|||
|
||||
package net.fabricmc.fabric.test.item;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
|
@ -31,5 +37,29 @@ public class FabricItemSettingsTests implements ModInitializer {
|
|||
// Registers an item with a custom equipment slot.
|
||||
Item testItem = new Item(new FabricItemSettings().equipmentSlot(stack -> EquipmentSlot.CHEST));
|
||||
Registry.register(Registries.ITEM, new Identifier("fabric-item-api-v1-testmod", "test_item"), testItem);
|
||||
|
||||
final List<String> missingMethods = new ArrayList<>();
|
||||
|
||||
for (Method method : FabricItemSettings.class.getMethods()) {
|
||||
if ((method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0) {
|
||||
// Ignore synthetic bridge methods
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((method.getModifiers() & Opcodes.ACC_STATIC) != 0) {
|
||||
// Ignore static methods
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.getReturnType() == Item.Settings.class) {
|
||||
missingMethods.add(method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (missingMethods.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Missing method overrides in FabricItemSettings: " + String.join(", ", missingMethods));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,21 +46,21 @@ public final class MiningLevelTest implements ModInitializer {
|
|||
|
||||
/// Tagged blocks
|
||||
// sword + dynamic mining level tag
|
||||
public static final Block NEEDS_NETHERITE_SWORD = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_NETHERITE_SWORD = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// sword + vanilla mining level tag
|
||||
public static final Block NEEDS_STONE_SWORD = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_STONE_SWORD = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// any sword
|
||||
public static final Block NEEDS_ANY_SWORD = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_ANY_SWORD = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// shears
|
||||
public static final Block NEEDS_SHEARS = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_SHEARS = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// vanilla mineable tag + dynamic mining level tag
|
||||
public static final Block NEEDS_NETHERITE_PICKAXE = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_NETHERITE_PICKAXE = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// vanilla mineable tag, requires tool (this type of block doesn't exist in vanilla)
|
||||
public static final Block NEEDS_AXE = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_AXE = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// vanilla mineable tag, requires tool (this type of block doesn't exist in vanilla)
|
||||
public static final Block NEEDS_HOE = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_HOE = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
// vanilla mineable tag, requires tool (this type of block doesn't exist in vanilla)
|
||||
public static final Block NEEDS_SHOVEL = new Block(AbstractBlock.Settings.of().strength(2, 3).requiresTool());
|
||||
public static final Block NEEDS_SHOVEL = new Block(AbstractBlock.Settings.create().strength(2, 3).requiresTool());
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
|
|
@ -16,12 +16,15 @@
|
|||
|
||||
package net.fabricmc.fabric.api.object.builder.v1.block;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.MapColor;
|
||||
import net.minecraft.block.enums.Instrument;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.resource.featuretoggle.FeatureFlag;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
@ -82,10 +85,18 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
this.emissiveLighting(otherAccessor.getEmissiveLightingPredicate());
|
||||
}
|
||||
|
||||
public static FabricBlockSettings of() {
|
||||
public static FabricBlockSettings create() {
|
||||
return new FabricBlockSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link FabricBlockSettings#create()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static FabricBlockSettings of() {
|
||||
return create();
|
||||
}
|
||||
|
||||
public static FabricBlockSettings copyOf(AbstractBlock block) {
|
||||
return new FabricBlockSettings(((AbstractBlockAccessor) block).getSettings());
|
||||
}
|
||||
|
@ -272,6 +283,54 @@ public class FabricBlockSettings extends AbstractBlock.Settings {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings mapColor(Function<BlockState, MapColor> mapColorProvider) {
|
||||
super.mapColor(mapColorProvider);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings burnable() {
|
||||
super.burnable();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings liquid() {
|
||||
super.liquid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings solid() {
|
||||
super.solid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings notSolid() {
|
||||
super.notSolid();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings pistonBehavior(PistonBehavior pistonBehavior) {
|
||||
super.pistonBehavior(pistonBehavior);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings instrument(Instrument instrument) {
|
||||
super.instrument(instrument);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FabricBlockSettings replaceable() {
|
||||
super.replaceable();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* FABRIC ADDITIONS*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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.test.object.builder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
public class FabricBlockSettingsTest implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
final List<String> missingMethods = new ArrayList<>();
|
||||
|
||||
for (Method method : FabricBlockSettings.class.getMethods()) {
|
||||
if ((method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0) {
|
||||
// Ignore synthetic bridge methods
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((method.getModifiers() & Opcodes.ACC_STATIC) != 0) {
|
||||
// Ignore static methods
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.getReturnType() == AbstractBlock.Settings.class) {
|
||||
missingMethods.add(method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (missingMethods.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Missing method overrides in FabricBlockSettings: " + String.join(", ", missingMethods));
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@
|
|||
"main": [
|
||||
"net.fabricmc.fabric.test.object.builder.BlockEntityTypeBuilderTest",
|
||||
"net.fabricmc.fabric.test.object.builder.CriterionRegistryTest::init",
|
||||
"net.fabricmc.fabric.test.object.builder.FabricBlockSettingsTest",
|
||||
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest1",
|
||||
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest2",
|
||||
"net.fabricmc.fabric.test.object.builder.TealSignTest"
|
||||
|
|
|
@ -129,7 +129,7 @@ public class RegistrySyncTest implements ModInitializer {
|
|||
|
||||
private static void registerBlocks(String namespace, int amount, int startingId) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Block block = new Block(AbstractBlock.Settings.of());
|
||||
Block block = new Block(AbstractBlock.Settings.create());
|
||||
Registry.register(Registries.BLOCK, new Identifier(namespace, "block_" + (i + startingId)), block);
|
||||
|
||||
if (REGISTER_ITEMS) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class RendererTest implements ModInitializer {
|
|||
public static final BlockEntityType<FrameBlockEntity> FRAME_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(FrameBlockEntity::new, FRAMES).build(null);
|
||||
|
||||
public static final Identifier PILLAR_ID = id("pillar");
|
||||
public static final Block PILLAR = new Block(FabricBlockSettings.of());
|
||||
public static final Block PILLAR = new Block(FabricBlockSettings.create());
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
|
|
@ -41,7 +41,7 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
|
|||
|
||||
public class FluidChuteBlock extends Block implements BlockEntityProvider {
|
||||
public FluidChuteBlock() {
|
||||
super(Settings.of());
|
||||
super(Settings.create());
|
||||
}
|
||||
|
||||
private static final VoxelShape SHAPE = VoxelShapes.cuboid(
|
||||
|
|
|
@ -34,8 +34,8 @@ import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
|
|||
public class TransferTestInitializer implements ModInitializer {
|
||||
public static final String MOD_ID = "fabric-transfer-api-v1-testmod";
|
||||
|
||||
private static final Block INFINITE_WATER_SOURCE = new Block(AbstractBlock.Settings.of());
|
||||
private static final Block INFINITE_LAVA_SOURCE = new Block(AbstractBlock.Settings.of());
|
||||
private static final Block INFINITE_WATER_SOURCE = new Block(AbstractBlock.Settings.create());
|
||||
private static final Block INFINITE_LAVA_SOURCE = new Block(AbstractBlock.Settings.create());
|
||||
private static final Block FLUID_CHUTE = new FluidChuteBlock();
|
||||
private static final Item EXTRACT_STICK = new ExtractStickItem();
|
||||
public static BlockEntityType<FluidChuteBlockEntity> FLUID_CHUTE_TYPE;
|
||||
|
|
|
@ -4,7 +4,7 @@ fabric.loom.multiProjectOptimisation=true
|
|||
|
||||
version=0.80.2
|
||||
minecraft_version=1.20-pre1
|
||||
yarn_version=+build.1
|
||||
yarn_version=+build.5
|
||||
loader_version=0.14.19
|
||||
installer_version=0.11.1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue