This commit is contained in:
apple502j 2024-08-30 01:54:21 +09:00 committed by GitHub
parent 9c280a9ffa
commit 2cd4845256
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
68 changed files with 334 additions and 967 deletions

View file

@ -1,447 +0,0 @@
/*
* 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.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.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.loot.LootTable;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.DyeColor;
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor;
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor;
/**
* @deprecated replace with {@link AbstractBlock.Settings}
*/
@Deprecated
public class FabricBlockSettings extends AbstractBlock.Settings {
protected FabricBlockSettings() {
super();
}
protected FabricBlockSettings(AbstractBlock.Settings settings) {
this();
// Mostly Copied from vanilla's copy method
// Note: If new methods are added to Block settings, an accessor must be added here
AbstractBlockSettingsAccessor thisAccessor = (AbstractBlockSettingsAccessor) this;
AbstractBlockSettingsAccessor otherAccessor = (AbstractBlockSettingsAccessor) settings;
// Copied in vanilla: sorted by vanilla copy order
this.hardness(otherAccessor.getHardness());
this.resistance(otherAccessor.getResistance());
this.collidable(otherAccessor.getCollidable());
thisAccessor.setRandomTicks(otherAccessor.getRandomTicks());
this.luminance(otherAccessor.getLuminance());
thisAccessor.setMapColorProvider(otherAccessor.getMapColorProvider());
this.sounds(otherAccessor.getSoundGroup());
this.slipperiness(otherAccessor.getSlipperiness());
this.velocityMultiplier(otherAccessor.getVelocityMultiplier());
thisAccessor.setDynamicBounds(otherAccessor.getDynamicBounds());
thisAccessor.setOpaque(otherAccessor.getOpaque());
thisAccessor.setIsAir(otherAccessor.getIsAir());
thisAccessor.setBurnable(otherAccessor.getBurnable());
thisAccessor.setLiquid(otherAccessor.getLiquid());
thisAccessor.setForceNotSolid(otherAccessor.getForceNotSolid());
thisAccessor.setForceSolid(otherAccessor.getForceSolid());
this.pistonBehavior(otherAccessor.getPistonBehavior());
thisAccessor.setToolRequired(otherAccessor.isToolRequired());
thisAccessor.setOffsetter(otherAccessor.getOffsetter());
thisAccessor.setBlockBreakParticles(otherAccessor.getBlockBreakParticles());
thisAccessor.setRequiredFeatures(otherAccessor.getRequiredFeatures());
this.emissiveLighting(otherAccessor.getEmissiveLightingPredicate());
this.instrument(otherAccessor.getInstrument());
thisAccessor.setReplaceable(otherAccessor.getReplaceable());
// Vanilla did not copy those fields until 23w45a, which introduced
// copyShallow method (maintaining the behavior previously used by the copy method)
// and the copy method that copies those fields as well. copyShallow is now
// deprecated. To maintain compatibility and since this behavior seems to be the
// more proper way, this copies all the fields, not just the shallow ones.
// Fields are added by field definition order.
this.jumpVelocityMultiplier(otherAccessor.getJumpVelocityMultiplier());
this.drops(otherAccessor.getLootTableKey());
this.allowsSpawning(otherAccessor.getAllowsSpawningPredicate());
this.solidBlock(otherAccessor.getSolidBlockPredicate());
this.suffocates(otherAccessor.getSuffocationPredicate());
this.blockVision(otherAccessor.getBlockVisionPredicate());
this.postProcess(otherAccessor.getPostProcessPredicate());
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#create()}
*/
@Deprecated
public static FabricBlockSettings create() {
return new FabricBlockSettings();
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#create()}
*/
@Deprecated
public static FabricBlockSettings of() {
return create();
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#copy(AbstractBlock)}
*/
@Deprecated
public static FabricBlockSettings copyOf(AbstractBlock block) {
return new FabricBlockSettings(((AbstractBlockAccessor) block).getSettings());
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#copy(AbstractBlock)}
*/
@Deprecated
public static FabricBlockSettings copyOf(AbstractBlock.Settings settings) {
return new FabricBlockSettings(settings);
}
@Deprecated
@Override
public FabricBlockSettings noCollision() {
super.noCollision();
return this;
}
@Deprecated
@Override
public FabricBlockSettings nonOpaque() {
super.nonOpaque();
return this;
}
@Deprecated
@Override
public FabricBlockSettings slipperiness(float value) {
super.slipperiness(value);
return this;
}
@Deprecated
@Override
public FabricBlockSettings velocityMultiplier(float velocityMultiplier) {
super.velocityMultiplier(velocityMultiplier);
return this;
}
@Deprecated
@Override
public FabricBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) {
super.jumpVelocityMultiplier(jumpVelocityMultiplier);
return this;
}
@Deprecated
@Override
public FabricBlockSettings sounds(BlockSoundGroup group) {
super.sounds(group);
return this;
}
/**
* @deprecated Please use {@link FabricBlockSettings#luminance(ToIntFunction)}.
*/
@Deprecated
public FabricBlockSettings lightLevel(ToIntFunction<BlockState> levelFunction) {
return this.luminance(levelFunction);
}
@Deprecated
@Override
public FabricBlockSettings luminance(ToIntFunction<BlockState> luminanceFunction) {
super.luminance(luminanceFunction);
return this;
}
@Deprecated
@Override
public FabricBlockSettings strength(float hardness, float resistance) {
super.strength(hardness, resistance);
return this;
}
@Deprecated
@Override
public FabricBlockSettings breakInstantly() {
super.breakInstantly();
return this;
}
@Deprecated
@Override
public FabricBlockSettings strength(float strength) {
super.strength(strength);
return this;
}
@Deprecated
@Override
public FabricBlockSettings ticksRandomly() {
super.ticksRandomly();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dynamicBounds() {
super.dynamicBounds();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dropsNothing() {
super.dropsNothing();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dropsLike(Block block) {
super.dropsLike(block);
return this;
}
@Deprecated
@Override
public FabricBlockSettings air() {
super.air();
return this;
}
@Deprecated
@Override
public FabricBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate<EntityType<?>> predicate) {
super.allowsSpawning(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) {
super.solidBlock(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) {
super.suffocates(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) {
super.blockVision(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) {
super.postProcess(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) {
super.emissiveLighting(predicate);
return this;
}
/**
* Make the block require tool to drop and slows down mining speed if the incorrect tool is used.
*/
@Deprecated
@Override
public FabricBlockSettings requiresTool() {
super.requiresTool();
return this;
}
@Deprecated
@Override
public FabricBlockSettings mapColor(MapColor color) {
super.mapColor(color);
return this;
}
@Deprecated
@Override
public FabricBlockSettings hardness(float hardness) {
super.hardness(hardness);
return this;
}
@Deprecated
@Override
public FabricBlockSettings resistance(float resistance) {
super.resistance(resistance);
return this;
}
@Deprecated
@Override
public FabricBlockSettings offset(AbstractBlock.OffsetType offsetType) {
super.offset(offsetType);
return this;
}
@Deprecated
@Override
public FabricBlockSettings noBlockBreakParticles() {
super.noBlockBreakParticles();
return this;
}
@Deprecated
@Override
public FabricBlockSettings requires(FeatureFlag... features) {
super.requires(features);
return this;
}
@Deprecated
@Override
public FabricBlockSettings mapColor(Function<BlockState, MapColor> mapColorProvider) {
super.mapColor(mapColorProvider);
return this;
}
@Deprecated
@Override
public FabricBlockSettings burnable() {
super.burnable();
return this;
}
@Deprecated
@Override
public FabricBlockSettings liquid() {
super.liquid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings solid() {
super.solid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings notSolid() {
super.notSolid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings pistonBehavior(PistonBehavior pistonBehavior) {
super.pistonBehavior(pistonBehavior);
return this;
}
@Deprecated
@Override
public FabricBlockSettings instrument(NoteBlockInstrument instrument) {
super.instrument(instrument);
return this;
}
@Deprecated
@Override
public FabricBlockSettings replaceable() {
super.replaceable();
return this;
}
/* FABRIC ADDITIONS*/
/**
* @deprecated Please use {@link FabricBlockSettings#luminance(int)}.
*/
@Deprecated
public FabricBlockSettings lightLevel(int lightLevel) {
this.luminance(lightLevel);
return this;
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#luminance(ToIntFunction)}
*/
@Deprecated
public FabricBlockSettings luminance(int luminance) {
this.luminance(ignored -> luminance);
return this;
}
@Deprecated
public FabricBlockSettings drops(RegistryKey<LootTable> dropTableId) {
((AbstractBlockSettingsAccessor) this).setLootTableKey(dropTableId);
return this;
}
/* FABRIC DELEGATE WRAPPERS */
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(MapColor)}
*/
@Deprecated
public FabricBlockSettings materialColor(MapColor color) {
return this.mapColor(color);
}
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(DyeColor)}
*/
@Deprecated
public FabricBlockSettings materialColor(DyeColor color) {
return this.mapColor(color);
}
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(DyeColor)}
*/
@Deprecated
public FabricBlockSettings mapColor(DyeColor color) {
return this.mapColor(color.getMapColor());
}
@Deprecated
public FabricBlockSettings collidable(boolean collidable) {
((AbstractBlockSettingsAccessor) this).setCollidable(collidable);
return this;
}
}

View file

@ -51,15 +51,6 @@ public interface FabricEntityType {
throw new AssertionError("Implemented in Mixin");
}
/**
* Build the entity type from the builder. Same as {@link EntityType.Builder#build(String)} but without an id.
*
* @return the entity type instance
*/
default EntityType<T> build() {
throw new AssertionError("Implemented in Mixin");
}
/**
* Creates an entity type builder for a living entity.
*

View file

@ -33,6 +33,7 @@ import net.minecraft.entity.SpawnLocation;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
@ -306,10 +307,10 @@ public class FabricEntityTypeBuilder<T extends Entity> {
* Creates the entity type.
*
* @return a new {@link EntityType}
* @deprecated use {@link EntityType.Builder#build()}
* @deprecated use {@link EntityType.Builder#build(net.minecraft.registry.RegistryKey)}
*/
@Deprecated
public EntityType<T> build() {
public EntityType<T> build(RegistryKey<EntityType<?>> key) {
EntityType.Builder<T> builder = EntityType.Builder.create(this.factory, this.spawnGroup)
.allowSpawningInside(specificSpawnBlocks.toArray(Block[]::new))
.maxTrackingRange(this.trackRange)
@ -340,7 +341,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
builder = builder.alwaysUpdateVelocity(this.forceTrackedVelocityUpdates);
}
return builder.build(null);
return builder.build(key);
}
/**
@ -476,8 +477,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
@Deprecated
@Override
public EntityType<T> build() {
final EntityType<T> type = super.build();
public EntityType<T> build(RegistryKey<EntityType<?>> key) {
final EntityType<T> type = super.build(key);
if (this.defaultAttributeBuilder != null) {
FabricDefaultAttributeRegistry.register(type, this.defaultAttributeBuilder.get());
@ -617,8 +618,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
}
@Override
public EntityType<T> build() {
EntityType<T> type = super.build();
public EntityType<T> build(RegistryKey<EntityType<?>> key) {
EntityType<T> type = super.build(key);
if (this.spawnPredicate != null) {
SpawnRestriction.register(type, this.spawnLocation, this.restrictionHeightmap, this.spawnPredicate);

View file

@ -1,180 +0,0 @@
/*
* 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.object.builder;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.loot.LootTable;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.sound.BlockSoundGroup;
@Mixin(AbstractBlock.Settings.class)
public interface AbstractBlockSettingsAccessor {
/* GETTERS */
@Accessor
float getHardness();
@Accessor
float getResistance();
@Accessor
boolean getCollidable();
@Accessor
boolean getRandomTicks();
@Accessor("luminance")
ToIntFunction<BlockState> getLuminance();
@Accessor
Function<BlockState, MapColor> getMapColorProvider();
@Accessor
BlockSoundGroup getSoundGroup();
@Accessor
float getSlipperiness();
@Accessor
float getVelocityMultiplier();
@Accessor
float getJumpVelocityMultiplier();
@Accessor
boolean getDynamicBounds();
@Accessor
boolean getOpaque();
@Accessor
boolean getIsAir();
@Accessor
boolean isToolRequired();
@Accessor
AbstractBlock.TypedContextPredicate<EntityType<?>> getAllowsSpawningPredicate();
@Accessor
AbstractBlock.ContextPredicate getSolidBlockPredicate();
@Accessor
AbstractBlock.ContextPredicate getSuffocationPredicate();
@Accessor
AbstractBlock.ContextPredicate getBlockVisionPredicate();
@Accessor
AbstractBlock.ContextPredicate getPostProcessPredicate();
@Accessor
AbstractBlock.ContextPredicate getEmissiveLightingPredicate();
@Accessor
AbstractBlock.Offsetter getOffsetter();
@Accessor
RegistryKey<LootTable> getLootTableKey();
@Accessor
boolean getBlockBreakParticles();
@Accessor
FeatureSet getRequiredFeatures();
@Accessor
boolean getBurnable();
@Accessor
boolean getLiquid();
@Accessor
boolean getForceNotSolid();
@Accessor
boolean getForceSolid();
@Accessor
PistonBehavior getPistonBehavior();
@Accessor
NoteBlockInstrument getInstrument();
@Accessor
boolean getReplaceable();
/* SETTERS */
@Accessor
void setCollidable(boolean collidable);
@Accessor
void setRandomTicks(boolean ticksRandomly);
@Accessor
void setMapColorProvider(Function<BlockState, MapColor> mapColorProvider);
@Accessor
void setDynamicBounds(boolean dynamicBounds);
@Accessor
void setOpaque(boolean opaque);
@Accessor
void setIsAir(boolean isAir);
@Accessor
void setLootTableKey(RegistryKey<LootTable> lootTableKey);
@Accessor
void setToolRequired(boolean toolRequired);
@Accessor
void setBlockBreakParticles(boolean blockBreakParticles);
@Accessor
void setRequiredFeatures(FeatureSet requiredFeatures);
@Accessor
void setOffsetter(AbstractBlock.Offsetter offsetter);
@Accessor
void setBurnable(boolean burnable);
@Accessor
void setLiquid(boolean liquid);
@Accessor
void setForceNotSolid(boolean forceNotSolid);
@Accessor
void setForceSolid(boolean forceSolid);
@Accessor
void setReplaceable(boolean replaceable);
}

View file

@ -34,6 +34,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.registry.RegistryKey;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl;
@ -41,7 +42,7 @@ import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl;
@Mixin(EntityType.Builder.class)
public abstract class EntityTypeBuilderMixin<T extends Entity> implements FabricEntityType.Builder<T>, FabricEntityTypeImpl.Builder {
@Shadow
public abstract EntityType<T> build(String id);
public abstract EntityType<T> build(RegistryKey<EntityType<?>> registryKey);
@Unique
private Boolean alwaysUpdateVelocity = null;
@ -57,13 +58,8 @@ public abstract class EntityTypeBuilderMixin<T extends Entity> implements Fabric
return (EntityType.Builder<T>) (Object) this;
}
@Override
public EntityType<T> build() {
return build(null);
}
@Inject(method = "build", at = @At("RETURN"))
private void applyChildBuilders(String id, CallbackInfoReturnable<EntityType<T>> cir) {
private void applyChildBuilders(RegistryKey<EntityType<?>> registryKey, CallbackInfoReturnable<EntityType<T>> cir) {
if (!(cir.getReturnValue() instanceof FabricEntityTypeImpl entityType)) {
throw new IllegalStateException();
}

View file

@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"AbstractBlockAccessor",
"AbstractBlockSettingsAccessor",
"BlockEntityTypeMixin",
"DefaultAttributeRegistryAccessor",
"DefaultAttributeRegistryMixin",

View file

@ -36,6 +36,9 @@ import net.minecraft.entity.attribute.DefaultAttributeRegistry;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.PigEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.Heightmap;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
@ -51,7 +54,7 @@ public class FabricEntityTypeTest {
void buildEntityType() {
EntityType<Entity> type = EntityType.Builder.create(SpawnGroup.MISC)
.alwaysUpdateVelocity(true)
.build();
.build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test")));
assertNotNull(type);
assertTrue(type.alwaysUpdateVelocity());
@ -61,7 +64,7 @@ public class FabricEntityTypeTest {
void buildLivingEntityType() {
EntityType<LivingEntity> type = FabricEntityType.Builder.createLiving((t, w) -> null, SpawnGroup.MISC, living -> living
.defaultAttributes(FabricEntityTypeTest::createAttributes)
).build();
).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test2")));
assertNotNull(type);
assertNotNull(DefaultAttributeRegistry.get(type));
@ -72,7 +75,7 @@ public class FabricEntityTypeTest {
EntityType<MobEntity> type = FabricEntityType.Builder.createMob((t, w) -> null, SpawnGroup.MISC, mob -> mob
.spawnRestriction(SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, PigEntity::canMobSpawn)
.defaultAttributes(FabricEntityTypeTest::createAttributes)
).build();
).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test3")));
assertNotNull(type);
assertEquals(SpawnLocationTypes.ON_GROUND, SpawnRestriction.getLocation(type));

View file

@ -29,6 +29,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
@ -40,19 +41,19 @@ import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
public class BlockEntityTypeBuilderTest implements ModInitializer {
private static final Identifier INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("initial_betrayal_block");
static final Block INITIAL_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.BLUE);
private static final RegistryKey<Block> INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("initial_betrayal_block");
static final Block INITIAL_BETRAYAL_BLOCK = createBetrayalBlock(INITIAL_BETRAYAL_BLOCK_ID, MapColor.BLUE);
private static final Identifier ADDED_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("added_betrayal_block");
static final Block ADDED_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.GREEN);
private static final RegistryKey<Block> ADDED_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("added_betrayal_block");
static final Block ADDED_BETRAYAL_BLOCK = createBetrayalBlock(ADDED_BETRAYAL_BLOCK_ID, MapColor.GREEN);
private static final Identifier FIRST_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("first_multi_betrayal_block");
static final Block FIRST_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.RED);
private static final RegistryKey<Block> FIRST_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("first_multi_betrayal_block");
static final Block FIRST_MULTI_BETRAYAL_BLOCK = createBetrayalBlock(FIRST_MULTI_BETRAYAL_BLOCK_ID, MapColor.RED);
private static final Identifier SECOND_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("second_multi_betrayal_block");
static final Block SECOND_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.YELLOW);
private static final RegistryKey<Block> SECOND_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("second_multi_betrayal_block");
static final Block SECOND_MULTI_BETRAYAL_BLOCK = createBetrayalBlock(SECOND_MULTI_BETRAYAL_BLOCK_ID, MapColor.YELLOW);
private static final Identifier BLOCK_ENTITY_TYPE_ID = ObjectBuilderTestConstants.id("betrayal_block");
private static final RegistryKey<Block> BLOCK_ENTITY_TYPE_ID = ObjectBuilderTestConstants.block("betrayal_block");
public static final BlockEntityType<?> BLOCK_ENTITY_TYPE = FabricBlockEntityTypeBuilder.create(BetrayalBlockEntity::new, INITIAL_BETRAYAL_BLOCK, ADDED_BETRAYAL_BLOCK, FIRST_MULTI_BETRAYAL_BLOCK, SECOND_MULTI_BETRAYAL_BLOCK).build();
@Override
@ -62,19 +63,23 @@ public class BlockEntityTypeBuilderTest implements ModInitializer {
register(FIRST_MULTI_BETRAYAL_BLOCK_ID, FIRST_MULTI_BETRAYAL_BLOCK);
register(SECOND_MULTI_BETRAYAL_BLOCK_ID, SECOND_MULTI_BETRAYAL_BLOCK);
Registry.register(Registries.BLOCK_ENTITY_TYPE, BLOCK_ENTITY_TYPE_ID, BLOCK_ENTITY_TYPE);
Registry.register(Registries.BLOCK_ENTITY_TYPE, BLOCK_ENTITY_TYPE_ID.getValue(), BLOCK_ENTITY_TYPE);
}
private static void register(Identifier id, Block block) {
private static Block createBetrayalBlock(RegistryKey<Block> key, MapColor color) {
return new BetrayalBlock(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color).registryKey(key));
}
private static void register(RegistryKey<Block> id, Block block) {
Registry.register(Registries.BLOCK, id, block);
Item item = new BlockItem(block, new Item.Settings());
Registry.register(Registries.ITEM, id, item);
Registry.register(Registries.ITEM, id.getValue(), item);
}
private static class BetrayalBlock extends Block implements BlockEntityProvider {
private BetrayalBlock(MapColor color) {
super(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color));
private BetrayalBlock(AbstractBlock.Settings settings) {
super(settings);
}
@Override

View file

@ -25,31 +25,35 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Arm;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
// This test is intentionally not an entrypoint to verify the generics of the entity type builder propagate properly
final class EntityTypeBuilderGenericsTest {
static EntityType<Entity> ENTITY_1 = FabricEntityTypeBuilder.create().build();
static EntityType<LivingEntity> LIVING_ENTITY_1 = FabricEntityTypeBuilder.createLiving().build();
static RegistryKey<EntityType<?>> DUMMY = RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "dummy"));
static EntityType<Entity> ENTITY_1 = FabricEntityTypeBuilder.create().build(DUMMY);
static EntityType<LivingEntity> LIVING_ENTITY_1 = FabricEntityTypeBuilder.createLiving().build(DUMMY);
static EntityType<TestEntity> TEST_ENTITY_1 = FabricEntityTypeBuilder.createLiving()
.entityFactory(TestEntity::new)
.spawnGroup(SpawnGroup.CREATURE)
.build();
.build(DUMMY);
static EntityType<TestEntity> OLD_TEST = FabricEntityTypeBuilder.<TestEntity>createLiving()
.entityFactory(TestEntity::new)
.spawnGroup(SpawnGroup.CREATURE)
.build();
.build(DUMMY);
static EntityType<TestMob> OLD_MOB = FabricEntityTypeBuilder.<TestMob>createMob()
.disableSaving()
.entityFactory(TestMob::new)
.build();
.build(DUMMY);
static EntityType<TestMob> MOB_TEST = FabricEntityTypeBuilder.createMob()
.disableSaving()
.entityFactory(TestMob::new)
.build();
.build(DUMMY);
private static class TestEntity extends LivingEntity {
protected TestEntity(EntityType<? extends LivingEntity> entityType, World world) {

View file

@ -1,57 +0,0 @@
/*
* 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));
}
}

View file

@ -19,6 +19,9 @@ package net.fabricmc.fabric.test.object.builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
public final class ObjectBuilderTestConstants {
@ -28,4 +31,8 @@ public final class ObjectBuilderTestConstants {
public static Identifier id(String name) {
return Identifier.of(MOD_ID, name);
}
public static RegistryKey<Block> block(String name) {
return RegistryKey.of(RegistryKeys.BLOCK, id(name));
}
}

View file

@ -17,6 +17,7 @@
package net.fabricmc.fabric.test.object.builder;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSetType;
import net.minecraft.block.Blocks;
import net.minecraft.block.HangingSignBlock;
@ -30,6 +31,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.SignItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer;
@ -40,10 +42,14 @@ public class TealSignTest implements ModInitializer {
public static final Identifier TEAL_TYPE_ID = ObjectBuilderTestConstants.id("teal");
public static final BlockSetType TEAL_BLOCK_SET_TYPE = BlockSetTypeBuilder.copyOf(BlockSetType.OAK).build(TEAL_TYPE_ID);
public static final WoodType TEAL_WOOD_TYPE = WoodTypeBuilder.copyOf(WoodType.OAK).build(TEAL_TYPE_ID, TEAL_BLOCK_SET_TYPE);
public static final SignBlock TEAL_SIGN = new SignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN));
public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN));
public static final HangingSignBlock TEAL_HANGING_SIGN = new HangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN));
public static final WallHangingSignBlock TEAL_WALL_HANGING_SIGN = new WallHangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN));
public static final RegistryKey<Block> TEAL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_sign");
public static final SignBlock TEAL_SIGN = new SignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEAL_SIGN_KEY));
public static final RegistryKey<Block> TEAL_WALL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_wall_sign");
public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEAL_WALL_SIGN_KEY));
public static final RegistryKey<Block> TEAL_HANGING_SIGN_KEY = ObjectBuilderTestConstants.block("teal_hanging_sign");
public static final HangingSignBlock TEAL_HANGING_SIGN = new HangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN).registryKey(TEAL_HANGING_SIGN_KEY));
public static final RegistryKey<Block> TEAL_WALL_HANGING_SIGN_KEY = ObjectBuilderTestConstants.block("teal_wall_hanging_sign");
public static final WallHangingSignBlock TEAL_WALL_HANGING_SIGN = new WallHangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN).registryKey(TEAL_WALL_HANGING_SIGN_KEY));
public static final SignItem TEAL_SIGN_ITEM = new SignItem(new Item.Settings(), TEAL_SIGN, TEAL_WALL_SIGN);
public static final HangingSignItem TEAL_HANGING_SIGN_ITEM = new HangingSignItem(TEAL_HANGING_SIGN, TEAL_WALL_HANGING_SIGN, new Item.Settings());
@ -51,13 +57,13 @@ public class TealSignTest implements ModInitializer {
public void onInitialize() {
WoodType.register(TEAL_WOOD_TYPE);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_sign"), TEAL_WALL_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_hanging_sign"), TEAL_WALL_HANGING_SIGN);
Registry.register(Registries.BLOCK, TEAL_SIGN_KEY, TEAL_SIGN);
Registry.register(Registries.BLOCK, TEAL_WALL_SIGN_KEY, TEAL_WALL_SIGN);
Registry.register(Registries.BLOCK, TEAL_HANGING_SIGN_KEY, TEAL_HANGING_SIGN);
Registry.register(Registries.BLOCK, TEAL_WALL_HANGING_SIGN_KEY, TEAL_WALL_HANGING_SIGN);
Registry.register(Registries.ITEM, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN_ITEM);
Registry.register(Registries.ITEM, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN_ITEM);
Registry.register(Registries.ITEM, TEAL_SIGN_KEY.getValue(), TEAL_SIGN_ITEM);
Registry.register(Registries.ITEM, TEAL_HANGING_SIGN_KEY.getValue(), TEAL_HANGING_SIGN_ITEM);
BlockEntityType.SIGN.addSupportedBlock(TEAL_SIGN);
BlockEntityType.HANGING_SIGN.addSupportedBlock(TEAL_HANGING_SIGN);

View file

@ -23,7 +23,6 @@
"entrypoints": {
"main": [
"net.fabricmc.fabric.test.object.builder.BlockEntityTypeBuilderTest",
"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",