Skip to content

Commit

Permalink
Re-implemented pyramids
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed May 9, 2023
1 parent 1160327 commit 4be7be8
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 235 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/teammetallurgy/atum/Atum.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private void setupCommon(FMLCommonSetupEvent event) {
if (AtumConfig.SANDSTORM.sandstormEnabled.get()) {
MinecraftForge.EVENT_BUS.register(SandstormHandler.INSTANCE);
}
// MinecraftForge.EVENT_BUS.register(AtumStructures.PYRAMID_STRUCTURE); //TODO Require structures functioning
KhnumiteFaceBlock.addDispenserSupport();
NetworkHandler.initialize();
IntegrationHandler.INSTANCE.setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teammetallurgy.atum.blocks.lighting;

import com.google.common.collect.Maps;
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.misc.StackHelper;
import net.minecraft.core.BlockPos;
Expand All @@ -20,13 +21,16 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.RegistryObject;

import javax.annotation.Nonnull;
import java.util.Map;
import java.util.function.Supplier;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class AtumTorchUnlitBlock extends AtumTorchBlock {
private final Supplier<? extends Block> lit;
public static final Map<RegistryObject<Block>, RegistryObject<Block>> UNLIT = Maps.newHashMap();

public AtumTorchUnlitBlock(Supplier<? extends Block> lit) {
super(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.teammetallurgy.atum.entity.animal;

import com.teammetallurgy.atum.entity.undead.UndeadBaseEntity;
import com.teammetallurgy.atum.init.AtumStructures;
import com.teammetallurgy.atum.world.gen.structure.StructureHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand Down Expand Up @@ -63,7 +65,7 @@ public boolean checkSpawnRules(@Nonnull LevelAccessor level, @Nonnull MobSpawnTy

public static boolean canSpawn(EntityType<? extends TarantulaEntity> tarantula, ServerLevelAccessor level, MobSpawnType spawnReason, BlockPos pos, RandomSource random) {
return (spawnReason == MobSpawnType.SPAWNER || pos.getY() >= 40 && pos.getY() <= 62 && !level.canSeeSkyFromBelowWater(pos.below())) && checkMonsterSpawnRules(tarantula, level, spawnReason, pos, random) &&
level instanceof ServerLevel /*&& !StructureHelper.doesChunkHaveStructure((ServerLevel) level, pos, AtumStructures.PYRAMID_STRUCTURE)*/; //TODO Uncomment when structures are re-added
level instanceof ServerLevel && !StructureHelper.doesChunkHaveStructure((ServerLevel) level, pos, AtumStructures.PYRAMID_KEY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.teammetallurgy.atum.entity.bandit.BanditBaseEntity;
import com.teammetallurgy.atum.entity.undead.UndeadBaseEntity;
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumStructures;
import com.teammetallurgy.atum.world.gen.structure.StructureHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
Expand Down Expand Up @@ -194,8 +196,8 @@ public static boolean isValidLightLevel(LevelAccessor level, @Nonnull BlockPos p
}

public static boolean canSpawn(EntityType<? extends StoneBaseEntity> stoneBase, LevelAccessor level, MobSpawnType spawnReason, BlockPos pos, RandomSource random) {
return isValidLightLevel(level, pos, random) && checkAnyLightMonsterSpawnRules(stoneBase, level, spawnReason, pos, random) && level instanceof ServerLevel /*&&
!StructureHelper.doesChunkHaveStructure((ServerLevel) level, pos, AtumStructures.PYRAMID_STRUCTURE)*/; //TODO Uncomment when structures are re-added
return isValidLightLevel(level, pos, random) && checkAnyLightMonsterSpawnRules(stoneBase, level, spawnReason, pos, random) && level instanceof ServerLevel &&
!StructureHelper.doesChunkHaveStructure((ServerLevel) level, pos, AtumStructures.PYRAMID_KEY);
}

boolean isPlayerCreated() {
Expand Down

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/main/java/com/teammetallurgy/atum/init/AtumBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState sta
public static final RegistryObject<Block> LIMESTONE_CRACKED_BRICK_DOOR = registerBlock(() -> new DoorAtumBlock(copy(LIMESTONE_BRICK_CRACKED_BRICK.get()), AtumBlockSetType.LIMESTONE), "limestone_brick_cracked_brick_door");
public static final RegistryObject<Block> LIMESTONE_BRICK_CHISELED_DOOR = registerBlock(() -> new DoorAtumBlock(copy(LIMESTONE_BRICK_CHISELED.get()), AtumBlockSetType.LIMESTONE), "limestone_brick_chiseled_door");
public static final RegistryObject<Block> LIMESTONE_BRICK_CARVED_DOOR = registerBlock(() -> new DoorAtumBlock(copy(LIMESTONE_BRICK_CARVED.get()), AtumBlockSetType.LIMESTONE), "limestone_brick_carved_door");
public static final RegistryObject<Block> KARST = registerBlock(() -> new Block(copy(LIMESTONE.get()).strength(3.0F, 6.0F)), "karst");
public static final RegistryObject<Block> KARST = registerBlock(() -> new Block(copy(LIMESTONE.get()).strength(2.0F, 6.0F)), "karst");
public static final RegistryObject<Block> ALABASTER = registerBlock(() -> new Block(of(Material.STONE, MaterialColor.QUARTZ).strength(2.0F, 8.0F)), "alabaster");
public static final RegistryObject<Block> ALABASTER_BRICK_SMOOTH = registerBlock(() -> new Block(copy(ALABASTER.get())), "alabaster_brick_smooth");
public static final RegistryObject<Block> ALABASTER_BRICK_POLISHED = registerBlock(() -> new Block(copy(ALABASTER.get())), "alabaster_brick_polished");
Expand Down Expand Up @@ -601,6 +601,7 @@ public static RegistryObject<Block> registerTorchWithUnlit(@Nonnull Supplier<Blo
RegistryObject<Block> wallTorchUnlit = registerBaseBlock(() -> new AtumWallTorchUnlitBlock(wallTorchLit.get(), Block.Properties.copy(unlitTorch.get()).lootFrom(unlitTorch)), "wall_" + name + "_unlit");
AtumItems.registerItem(() -> new StandingAndWallBlockItem(unlitTorch.get(), wallTorchUnlit.get(), new Item.Properties(), Direction.DOWN), name + "_unlit");
RegistryObject<Item> litTorchItem = AtumItems.registerItem(() -> new StandingAndWallBlockItem(litTorch.get(), wallTorchLit.get(), new Item.Properties(), Direction.DOWN), name);
AtumTorchUnlitBlock.UNLIT.put(litTorch, unlitTorch);
AtumItems.ITEMS_FOR_TAB_LIST.add(litTorchItem);
return litTorch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class AtumEffects {
public static final DeferredRegister<MobEffect> MOB_EFFECT_DEFERRED = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, Atum.MOD_ID);
public static final RegistryObject<MobEffect> MARKED_FOR_DEATH = register("marked_for_death", new MarkedForDeathEffect());
public static final RegistryObject<MobEffect> MARKED_FOR_DEATH = register("marked_for_death", new MarkedForDeathEffect()); //TODO Fix, crashes

public static RegistryObject<MobEffect> register(String name, MobEffect effect) {
MinecraftForge.EVENT_BUS.register(effect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.world.gen.structure.girafitomb.GirafiTombPieces;
import com.teammetallurgy.atum.world.gen.structure.pyramid.PyramidPieces;
import com.teammetallurgy.atum.world.gen.structure.ruins.RuinPieces;
import com.teammetallurgy.atum.world.gen.structure.tomb.TombPieces;
import net.minecraft.core.registries.Registries;
Expand All @@ -14,8 +15,8 @@ public class AtumStructurePieces {
public static final RegistryObject<StructurePieceType> GIRAFI_TOMB = register(GirafiTombPieces.GirafiTombTemplate::new, "girafi_tomb");
public static final RegistryObject<StructurePieceType> TOMB = register(TombPieces.TombTemplate::new, "tomb");
public static final RegistryObject<StructurePieceType> RUIN = register(RuinPieces.RuinTemplate::new, "ruin");
//public static final StructurePieceType PYRAMID = register(PyramidPieces.PyramidTemplate::new, "pyramid");
//public static final StructurePieceType PYRAMID_MAZE = register(PyramidPieces.Maze::new, "maze");
public static final RegistryObject<StructurePieceType> PYRAMID = register(PyramidPieces.PyramidTemplate::new, "pyramid");
public static final RegistryObject<StructurePieceType> PYRAMID_MAZE = register((manager, nbt) -> new PyramidPieces.Maze(nbt), "pyramid_maze");
//public static final StructurePieceType MINESHAFT_CORRIDOR = register(AtumMineshaftPieces.Corridor::new, "mineshaft_corridor");
//public static final StructurePieceType MINESHAFT_CROSSING = register(AtumMineshaftPieces.Cross::new, "mineshaft_crossing");
//public static final StructurePieceType MINESHAFT_ROOM = register(AtumMineshaftPieces.Room::new, "mineshaft_room");
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/teammetallurgy/atum/init/AtumStructures.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import com.mojang.serialization.Codec;
import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.world.gen.structure.girafitomb.GirafiTombStructure;
import com.teammetallurgy.atum.world.gen.structure.pyramid.PyramidStructure;
import com.teammetallurgy.atum.world.gen.structure.ruins.RuinStructure;
import com.teammetallurgy.atum.world.gen.structure.tomb.TombStructure;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureType;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

Expand All @@ -16,17 +20,24 @@ public class AtumStructures {
public static final RegistryObject<StructureType<GirafiTombStructure>> GIRAFI_TOMB = register("girafi_tomb", GirafiTombStructure.CODEC);
public static final RegistryObject<StructureType<TombStructure>> TOMB = register("tomb", TombStructure.CODEC);
public static final RegistryObject<StructureType<RuinStructure>> RUIN = register("ruin", RuinStructure.CODEC);
public static final RegistryObject<StructureType<PyramidStructure>> PYRAMID = register("pyramid", PyramidStructure.CODEC);

//Structure Resource Keys (Only used in certain instance, only add if needed)
public static final ResourceKey<Structure> PYRAMID_KEY = createKey("pyramid");

private static <S extends Structure> RegistryObject<StructureType<S>> register(String name, Codec<S> codec) {
return STRUCTURE_TYPE_DEFERRED.register(name, () -> structureTypeFromCodec(codec));
}

private static ResourceKey<Structure> createKey(String name) {
return ResourceKey.create(Registries.STRUCTURE, new ResourceLocation(Atum.MOD_ID, name));
}

private static <T extends Structure> StructureType<T> structureTypeFromCodec(Codec<T> structureCodec) {
return () -> structureCodec;
}

//Structures /TODO Remove. Kept for reference for now
// public static final Structure PYRAMID = register("pyramid", new PyramidStructure(NoneFeatureConfiguration.CODEC));
// public static final Structure<AtumMineshaftConfig> MINESHAFT_STRUCTURE = register("mineshaft", new AtumMineshaftStructure(AtumMineshaftConfig.CODEC));
// public static final Structure<JigsawConfiguration> GATEHOUSE = register("gatehouse", new GatehouseStructure(JigsawConfiguration.CODEC));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static AtumDimensionData load(@Nonnull CompoundTag nbt) {

/*ListTag listNBT = nbt.getList("PyramidBoxes", 10);
for (int i = 0; i < listNBT.size(); ++i) {
data.beatenPyramids.add(new BoundingBox(listNBT.getIntArray(i))); //TODO Fix. Is this needed still?
data.beatenPyramids.add(new BoundingBox(listNBT.getIntArray(i))); //TODO Fix.
}*/
return data;
}
Expand All @@ -32,7 +32,7 @@ public CompoundTag save(@Nonnull CompoundTag nbt) {
nbt.putBoolean("HasStartStructureSpawned", this.hasStartStructureSpawned);
nbt.putBoolean("IsStorming", this.isStorming);

/*f (!this.beatenPyramids.isEmpty()) { //TODO Fix. Is this needed still?
/*f (!this.beatenPyramids.isEmpty()) { //TODO Fix.
ListTag listNBT = new ListTag();
for (BoundingBox box : this.beatenPyramids) {
listNBT.add(box.createTag());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.teammetallurgy.atum.world.gen.structure;

import com.teammetallurgy.atum.init.AtumBlocks;
import com.teammetallurgy.atum.init.AtumStructures;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer;

Expand All @@ -29,13 +31,16 @@ public void afterPlace(WorldGenLevel genLevel, @Nonnull StructureManager manager
for (int x = boundingBox.minX(); x <= boundingBox.maxX(); ++x) {
for (int z = boundingBox.minZ(); z <= boundingBox.maxZ(); ++z) {
mutablePos.set(x, calculateBoundingBoxminY, z);
if (!genLevel.isEmptyBlock(mutablePos) && calculateBoundingBox.isInside(mutablePos) && piecesContainer.isInsidePiece(mutablePos)) {
for (int i1 = calculateBoundingBoxminY - 1; i1 > minBuild; --i1) {
mutablePos.setY(i1);
if (!genLevel.isEmptyBlock(mutablePos) && !genLevel.getBlockState(mutablePos).getMaterial().isLiquid()) {
break;

if (!StructureHelper.doesChunkHaveStructure(genLevel.getLevel(), mutablePos, AtumStructures.PYRAMID_KEY)) {
if (!genLevel.isEmptyBlock(mutablePos) && calculateBoundingBox.isInside(mutablePos) && piecesContainer.isInsidePiece(mutablePos)) {
for (int i1 = calculateBoundingBoxminY - 1; i1 > minBuild; --i1) {
mutablePos.setY(i1);
if (!genLevel.isEmptyBlock(mutablePos) && !genLevel.getBlockState(mutablePos).getMaterial().isLiquid()) {
break;
}
setBelowStructureBlock(genLevel, mutablePos, random); //Same as vanilla, but use Limestone instead
}
setBelowStructureBlock(genLevel, mutablePos, random); //Same as vanilla, but use Limestone instead
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
package com.teammetallurgy.atum.world.gen.structure;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.Structure;

public class StructureHelper {

/*public static Direction getDirectionFromRotation(Rotation rotation) { //TODO Is this still needed?
public static boolean doesChunkHaveStructure(ServerLevel serverLevel, BlockPos pos, ResourceKey<Structure> structureResourceKey) {
StructureManager structureManager = serverLevel.structureManager();
Structure structure = structureManager.registryAccess().registryOrThrow(Registries.STRUCTURE).get(structureResourceKey);
return structure != null && structureManager.getStructureAt(pos, structure).isValid();
}

public static Direction getDirectionFromRotation(Rotation rotation) {
return switch (rotation) {
case CLOCKWISE_90 -> Direction.WEST;
case CLOCKWISE_180 -> Direction.NORTH;
case COUNTERCLOCKWISE_90 -> Direction.EAST;
default -> Direction.SOUTH;
};
}*/
}
}

0 comments on commit 4be7be8

Please sign in to comment.