Skip to content

Commit

Permalink
Fix EntityType.Builder for 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Apr 10, 2024
1 parent 44e6689 commit 6793dde
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnLocation;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.mob.MobEntity;
Expand Down Expand Up @@ -111,7 +112,7 @@ interface Mob<T extends MobEntity> extends Living<T> {
*
* @return this builder for chaining.
*/
Mob<T> spawnRestriction(SpawnRestriction.Location location, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate);
Mob<T> spawnRestriction(SpawnLocation location, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate);

/**
* Sets the default attributes for a type of mob entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public EntityType<T> build() {
.allowSpawningInside(specificSpawnBlocks.toArray(Block[]::new))
.maxTrackingRange(this.trackRange)
.trackingTickInterval(this.trackedUpdateRate)
.setDimensions(this.dimensions.width, this.dimensions.height);
.dimensions(this.dimensions.width(), this.dimensions.height());

if (!this.saveable) {
builder = builder.disableSaving();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnLocation;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.mob.MobEntity;
Expand Down Expand Up @@ -76,12 +77,12 @@ public void onBuild(EntityType<T> type) {
}

final class Mob<T extends MobEntity> extends Living<T> implements FabricEntityType.Builder.Mob<T> {
private SpawnRestriction.Location restrictionLocation;
private SpawnLocation restrictionLocation;
private Heightmap.Type restrictionHeightmap;
private SpawnRestriction.SpawnPredicate<T> spawnPredicate;

@Override
public FabricEntityType.Builder.Mob<T> spawnRestriction(SpawnRestriction.Location location, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate) {
public FabricEntityType.Builder.Mob<T> spawnRestriction(SpawnLocation location, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate) {
this.restrictionLocation = Objects.requireNonNull(location, "Location cannot be null.");
this.restrictionHeightmap = Objects.requireNonNull(heightmap, "Heightmap type cannot be null.");
this.spawnPredicate = Objects.requireNonNull(spawnPredicate, "Spawn predicate cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import net.minecraft.entity.SpawnLocation;

import net.minecraft.entity.SpawnLocationTypes;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -69,12 +73,12 @@ void buildLivingEntityType() {
@Test
void buildMobEntityType() {
EntityType<MobEntity> type = FabricEntityType.Builder.createMob((t, w) -> null, SpawnGroup.MISC, mob -> mob
.spawnRestriction(SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, PigEntity::canMobSpawn)
.spawnRestriction(SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, PigEntity::canMobSpawn)
.defaultAttributes(FabricEntityTypeTest::createAttributes)
).build();

assertNotNull(type);
assertEquals(SpawnRestriction.Location.ON_GROUND, SpawnRestriction.getLocation(type));
assertEquals(SpawnLocationTypes.ON_GROUND, SpawnRestriction.getLocation(type));
assertNotNull(DefaultAttributeRegistry.get(type));
}

Expand Down

0 comments on commit 6793dde

Please sign in to comment.