Skip to content

Commit

Permalink
Fixed loading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Aug 28, 2022
1 parent 1860e3e commit 9560800
Showing 1 changed file with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.majruszsdifficulty.gamemodifiers.list;

import com.majruszsdifficulty.Registries;
import com.majruszsdifficulty.config.GameStageStringListConfig;
import com.mlib.gamemodifiers.GameModifier;import com.majruszsdifficulty.Registries;
import com.mlib.Utility;
import com.mlib.gamemodifiers.GameModifier;
import com.mlib.gamemodifiers.contexts.OnCheckSpawnContext;
import com.mlib.gamemodifiers.data.OnCheckSpawnData;
import com.mlib.levels.LevelHelper;
import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.StructureTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.monster.Illusioner;
import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.Event;

public class SpawnBlocker extends GameModifier {
Expand All @@ -22,9 +18,7 @@ public SpawnBlocker() {
super( Registries.Modifiers.DEFAULT, "SpawnBlocker", "Blocks certain mobs from spawning when given game stage is active." );

OnCheckSpawnContext onCheckSpawn = new OnCheckSpawnContext( this::blockSpawn );
onCheckSpawn.addCondition( data->data.entity instanceof Illusioner && isVillageNearby( data.entity ) )
.addCondition( data->this.isForbidden( data.entity ) )
.addConfig( this.forbiddenEntities );
onCheckSpawn.addCondition( data->this.isForbidden( data.entity ) ).addConfig( this.forbiddenEntities );

this.addContext( onCheckSpawn );
}
Expand All @@ -34,13 +28,6 @@ private void blockSpawn( OnCheckSpawnData data ) {
}

private boolean isForbidden( Entity entity ) {
return this.forbiddenEntities.getCurrentGameStageValue().contains( Registry.ENTITY_TYPE.getKey( entity.getType() ).toString() );
}

private static boolean isVillageNearby( Entity entity ) {
if( !( entity.level instanceof ServerLevel level ) || !LevelHelper.isEntityIn( entity, Level.OVERWORLD ) )
return false;

return level.findNearestMapStructure( StructureTags.VILLAGE, entity.blockPosition(), 100, false ) != null;
return this.forbiddenEntities.getCurrentGameStageValue().contains( Utility.getRegistryString( entity.getType() ) );
}
}

0 comments on commit 9560800

Please sign in to comment.