Skip to content

Commit

Permalink
(Block)EntityType builders use @nullable Booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Dec 18, 2024
1 parent ac4f4b0 commit d70d2c0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,8 +30,10 @@
@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)
Expand All @@ -48,12 +51,12 @@ public void onCanPotentiallyExecuteCommands(CallbackInfoReturnable<Boolean> cir)
}

@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;
}
}

0 comments on commit d70d2c0

Please sign in to comment.