-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7abb61
commit 3966314
Showing
13 changed files
with
891 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/slimeist/server_mobs/mixin/SoulFireBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.slimeist.server_mobs.mixin; | ||
|
||
import com.slimeist.server_mobs.ServerMobsMod; | ||
import com.slimeist.server_mobs.pentagram.StructureTester; | ||
import net.minecraft.block.AbstractFireBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.SoulFireBlock; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(SoulFireBlock.class) | ||
public abstract class SoulFireBlockMixin extends AbstractFireBlock { | ||
private SoulFireBlockMixin(Settings settings, float damage) { | ||
super(settings, damage); | ||
} | ||
|
||
@Inject(method = "getStateForNeighborUpdate", at = @At("RETURN"), cancellable = true) | ||
private void maybeSpawnPentagram(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, | ||
BlockPos pos, BlockPos neighborPos, CallbackInfoReturnable<BlockState> cir) { | ||
if (!cir.getReturnValue().isAir()) { | ||
if (world instanceof ServerWorld serverWorld && new StructureTester(serverWorld, pos.down()).test()) { | ||
cir.setReturnValue(ServerMobsMod.PENTAGRAM_CORE_BLOCK.getDefaultState()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) { | ||
super.onBlockAdded(state, world, pos, oldState, notify); | ||
if (world instanceof ServerWorld serverWorld && new StructureTester(serverWorld, pos.down()).test()) { | ||
serverWorld.setBlockState(pos, ServerMobsMod.PENTAGRAM_CORE_BLOCK.getDefaultState()); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/slimeist/server_mobs/pentagram/ExpectedBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.slimeist.server_mobs.pentagram; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.CandleBlock; | ||
import net.minecraft.predicate.BlockPredicate; | ||
import net.minecraft.predicate.NbtPredicate; | ||
import net.minecraft.predicate.StatePredicate; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.tag.BlockTags; | ||
import net.minecraft.tag.TagKey; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction.Axis; | ||
|
||
public record ExpectedBlock(int xOffset, int yOffset, int zOffset, BlockPredicate predicate) { | ||
public static ExpectedBlock of(int xOffset, int yOffset, int zOffset, TagKey<Block> tag) { | ||
return new ExpectedBlock(xOffset, yOffset, zOffset, new BlockPredicate(tag, null, StatePredicate.ANY, NbtPredicate.ANY)); | ||
} | ||
|
||
public static ExpectedBlock of(int xOffset, int yOffset, int zOffset, Block... blocks) { | ||
return new ExpectedBlock(xOffset, yOffset, zOffset, new BlockPredicate(null, ImmutableSet.copyOf(blocks), StatePredicate.ANY, NbtPredicate.ANY)); | ||
} | ||
|
||
public static ExpectedBlock of(int xOffset, int yOffset, int zOffset, Axis axis, Block... blocks) { | ||
return new ExpectedBlock(xOffset, yOffset, zOffset, new BlockPredicate(null, ImmutableSet.copyOf(blocks), | ||
StatePredicate.Builder.create().exactMatch(Properties.AXIS, axis).build(), NbtPredicate.ANY)); | ||
} | ||
|
||
public static ExpectedBlock candle(int xOffset, int yOffset, int zOffset, int count, boolean lit) { | ||
return new ExpectedBlock(xOffset, yOffset, zOffset, new BlockPredicate(BlockTags.CANDLES, null, | ||
StatePredicate.Builder.create().exactMatch(CandleBlock.CANDLES, count).exactMatch(CandleBlock.LIT, lit).build(), | ||
NbtPredicate.ANY)); | ||
} | ||
|
||
public boolean test(ServerWorld world, BlockPos basePos) { | ||
return predicate.test(world, basePos.add(xOffset, yOffset, zOffset)); | ||
} | ||
} |
Oops, something went wrong.