(Block)EntityType builders use @Nullable Booleans

This commit is contained in:
modmuss50 2024-12-18 18:42:55 +00:00
parent ac4f4b07c0
commit d70d2c06bb
5 changed files with 18 additions and 9 deletions
fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric

View file

@ -38,7 +38,8 @@ import net.fabricmc.fabric.impl.object.builder.ExtendedBlockEntityType;
public final class FabricBlockEntityTypeBuilder<T extends BlockEntity> {
private final Factory<? extends T> factory;
private final Set<Block> blocks = new HashSet<>();
private boolean canPotentiallyExecuteCommands = false;
@Nullable
private Boolean canPotentiallyExecuteCommands = null;
private FabricBlockEntityTypeBuilder(Factory<? extends T> factory) {
this.factory = factory;

View file

@ -18,22 +18,25 @@ package net.fabricmc.fabric.impl.object.builder;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
public class ExtendedBlockEntityType<T extends BlockEntity> extends BlockEntityType<T> {
private final boolean canPotentiallyExecuteCommands;
@Nullable
private final Boolean canPotentiallyExecuteCommands;
public ExtendedBlockEntityType(BlockEntityFactory<? extends T> factory, Set<Block> blocks, boolean canPotentiallyExecuteCommands) {
public ExtendedBlockEntityType(BlockEntityFactory<? extends T> factory, Set<Block> blocks, @Nullable Boolean canPotentiallyExecuteCommands) {
super(factory, blocks);
this.canPotentiallyExecuteCommands = canPotentiallyExecuteCommands;
}
@Override
public boolean canPotentiallyExecuteCommands() {
if (canPotentiallyExecuteCommands) {
return true;
if (canPotentiallyExecuteCommands != null) {
return canPotentiallyExecuteCommands;
}
return super.canPotentiallyExecuteCommands();

View file

@ -35,9 +35,9 @@ import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRe
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
public interface FabricEntityTypeImpl {
void fabric_setAlwaysUpdateVelocity(Boolean alwaysUpdateVelocity);
void fabric_setAlwaysUpdateVelocity(@Nullable Boolean alwaysUpdateVelocity);
void fabric_setCanPotentiallyExecuteCommands(Boolean canPotentiallyExecuteCommands);
void fabric_setCanPotentiallyExecuteCommands(@Nullable Boolean canPotentiallyExecuteCommands);
interface Builder {
void fabric_setLivingEntityBuilder(Living<? extends LivingEntity> livingBuilder);

View file

@ -47,8 +47,10 @@ public abstract class EntityTypeBuilderMixin<T extends Entity> implements Fabric
public abstract EntityType<T> build(RegistryKey<EntityType<?>> registryKey);
@Unique
@Nullable
private Boolean alwaysUpdateVelocity = null;
@Unique
@Nullable
private Boolean canPotentiallyExecuteCommands = null;
@Unique

View file

@ -16,6 +16,7 @@
package net.fabricmc.fabric.mixin.object.builder;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@ -29,8 +30,10 @@ import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl;
@Mixin(EntityType.class)
public abstract class EntityTypeMixin implements FabricEntityTypeImpl {
@Unique
@Nullable
private Boolean alwaysUpdateVelocity;
@Unique
@Nullable
private Boolean canPotentiallyExecuteCommands;
@Inject(method = "alwaysUpdateVelocity", at = @At("HEAD"), cancellable = true)
@ -48,12 +51,12 @@ public abstract class EntityTypeMixin implements FabricEntityTypeImpl {
}
@Override
public void fabric_setAlwaysUpdateVelocity(Boolean alwaysUpdateVelocity) {
public void fabric_setAlwaysUpdateVelocity(@Nullable Boolean alwaysUpdateVelocity) {
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
}
@Override
public void fabric_setCanPotentiallyExecuteCommands(Boolean canPotentiallyExecuteCommands) {
public void fabric_setCanPotentiallyExecuteCommands(@Nullable Boolean canPotentiallyExecuteCommands) {
this.canPotentiallyExecuteCommands = canPotentiallyExecuteCommands;
}
}