Skip to content

Commit

Permalink
pentagram!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Oct 20, 2023
1 parent d7abb61 commit 3966314
Show file tree
Hide file tree
Showing 13 changed files with 891 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/main/java/com/slimeist/server_mobs/ServerMobsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@
import com.slimeist.server_mobs.entities.GustEntity;
import com.slimeist.server_mobs.entities.MissileEntity;
import com.slimeist.server_mobs.items.*;
import com.slimeist.server_mobs.pentagram.PentagramCoreBlock;
import com.slimeist.server_mobs.pentagram.PentagramCoreBlockEntity;
import com.slimeist.server_mobs.pentagram.TestPentagramCommand;
import eu.pb4.polymer.api.block.PolymerBlockUtils;
import eu.pb4.polymer.api.entity.PolymerEntityUtils;
import eu.pb4.polymer.api.item.PolymerItem;
import eu.pb4.polymer.api.resourcepack.PolymerArmorModel;
import eu.pb4.polymer.api.resourcepack.PolymerModelData;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.MapColor;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.item.*;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.entry.LootPoolEntry;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.tag.BiomeTags;
Expand Down Expand Up @@ -62,6 +68,16 @@ public class ServerMobsMod implements DedicatedServerModInitializer {
.maxDamage(25),
Items.CARROT_ON_A_STICK);

public static final PentagramCoreBlock PENTAGRAM_CORE_BLOCK = new PentagramCoreBlock(FabricBlockSettings
.of(Material.FIRE, MapColor.LIGHT_BLUE)
.noCollision()
.breakInstantly()
.luminance(10)
.sounds(BlockSoundGroup.WOOL)
.ticksRandomly());
public static final BlockEntityType<PentagramCoreBlockEntity> PENTAGRAM_CORE_BE = FabricBlockEntityTypeBuilder
.create(PentagramCoreBlockEntity::new, PENTAGRAM_CORE_BLOCK).build();

//ITEMS
public static final MissileItem MISSILE_ITEM = new MissileItem(
new FabricItemSettings()
Expand Down Expand Up @@ -222,6 +238,12 @@ public void onInitializeServer() {
);
}

Registry.register(Registry.BLOCK, id("pentagram_core"), PENTAGRAM_CORE_BLOCK);
Registry.register(Registry.BLOCK_ENTITY_TYPE, id("pentagram_core"), PENTAGRAM_CORE_BE);
PolymerBlockUtils.registerBlockEntity(PENTAGRAM_CORE_BE);

// Events

LootTableEvents.MODIFY.register(((resourceManager, lootManager, id, tableBuilder, source) -> {
if (id.equals(new Identifier("chests/village/village_tannery"))) {
tableBuilder.pool(LootPool.builder()
Expand All @@ -236,6 +258,10 @@ public void onInitializeServer() {
.build());
}
}));

CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> {
dispatcher.register(TestPentagramCommand.register());
}));
}

public static Identifier id(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.slimeist.server_mobs.api.server_rendering.entity.IServerRenderedEntity;
import com.slimeist.server_mobs.api.server_rendering.model.BakedServerEntityModel;
import com.slimeist.server_mobs.mixin.EntityAccessor;
import com.slimeist.server_mobs.pentagram.PentagramParticles;
import eu.pb4.holograms.mixin.accessors.SlimeEntityAccessor;
import eu.pb4.polymer.api.entity.PolymerEntity;
import net.minecraft.block.BlockState;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralTextContent;
Expand Down Expand Up @@ -130,6 +132,9 @@ protected void initGoals() {
public void tick() {
super.tick();
this.getModelInstance().updateHologram();
if (this.world instanceof ServerWorld serverWorld) {
new PentagramParticles(serverWorld, new BlockPos(81, 80, 1)).spawn();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ static TrackedData<EntityPose> getPOSE() {
static TrackedData<Integer> getFROZEN_TICKS() {
throw new AssertionError();
}

@Accessor
void setHasVisualFire(boolean hasVisualFire);
}
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());
}
}
}
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));
}
}
Loading

0 comments on commit 3966314

Please sign in to comment.