Skip to content

Commit

Permalink
Fix entities sometimes spawning in chest, Closes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jun 23, 2024
1 parent c9e1b24 commit 143b480
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/cyclops/colossalchests/block/ChestWall.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -24,6 +25,9 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.eventbus.api.Event;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.block.multi.CubeDetector;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
Expand All @@ -47,6 +51,14 @@ public ChestWall(Block.Properties properties, ChestMaterial material) {

this.registerDefaultState(this.stateDefinition.any()
.setValue(ENABLED, false));
MinecraftForge.EVENT_BUS.addListener(this::onLivingSpawn);
}

public void onLivingSpawn(LivingSpawnEvent.CheckSpawn event) {
// Only isValidSpawn is insufficient in some cases, so we add this forceful check as well.
if (event.getSpawnReason() != MobSpawnType.CHUNK_GENERATION && event.getEntity().getBlockStateOn().getBlock() == this) {
event.setResult(Event.Result.DENY);
}
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/cyclops/colossalchests/block/ColossalChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -41,6 +42,9 @@
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.eventbus.api.Event;
import org.cyclops.colossalchests.Advancements;
import org.cyclops.colossalchests.RegistryEntries;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
Expand Down Expand Up @@ -75,6 +79,14 @@ public ColossalChest(Properties properties, ChestMaterial material) {

this.registerDefaultState(this.stateDefinition.any()
.setValue(ENABLED, false));
MinecraftForge.EVENT_BUS.addListener(this::onLivingSpawn);
}

public void onLivingSpawn(LivingSpawnEvent.CheckSpawn event) {
// Only isValidSpawn is insufficient in some cases, so we add this forceful check as well.
if (event.getSpawnReason() != MobSpawnType.CHUNK_GENERATION && event.getEntity().getBlockStateOn().getBlock() == this) {
event.setResult(Event.Result.DENY);
}
}

@org.jetbrains.annotations.Nullable
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/cyclops/colossalchests/block/Interface.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -24,6 +25,9 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.eventbus.api.Event;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.colossalchests.blockentity.BlockEntityInterface;
import org.cyclops.cyclopscore.block.BlockWithEntity;
Expand All @@ -50,6 +54,14 @@ public Interface(Block.Properties properties, ChestMaterial material) {

this.registerDefaultState(this.stateDefinition.any()
.setValue(ENABLED, false));
MinecraftForge.EVENT_BUS.addListener(this::onLivingSpawn);
}

public void onLivingSpawn(LivingSpawnEvent.CheckSpawn event) {
// Only isValidSpawn is insufficient in some cases, so we add this forceful check as well.
if (event.getSpawnReason() != MobSpawnType.CHUNK_GENERATION && event.getEntity().getBlockStateOn().getBlock() == this) {
event.setResult(Event.Result.DENY);
}
}

@Override
Expand Down

0 comments on commit 143b480

Please sign in to comment.