diff --git a/build.gradle b/build.gradle index e4d2647f5..25aea1cc8 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,10 @@ repositories { name = "HYWLA" url = "https://maven.tehnut.info/" } + maven { + name = 'Earthcomputer Mods' + url = 'https://dl.bintray.com/earthcomputer/mods' + } } sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 @@ -100,6 +104,9 @@ dependencies { implementation 'com.google.code.findbugs:jsr305:3.0.2' + modImplementation 'net.earthcomputer:libstructure:1.3' // Or the latest version + include 'net.earthcomputer:libstructure:1.3' + // unit test dependencies testCompile "junit:junit:4.13" } diff --git a/src/main/java/appeng/block/storage/SkyChestBlock.java b/src/main/java/appeng/block/storage/SkyChestBlock.java index 726946b20..34b0aa97c 100644 --- a/src/main/java/appeng/block/storage/SkyChestBlock.java +++ b/src/main/java/appeng/block/storage/SkyChestBlock.java @@ -20,6 +20,9 @@ package appeng.block.storage; import javax.annotation.Nullable; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.SkyChestContainer; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; @@ -76,8 +79,7 @@ public class SkyChestBlock extends AEBaseTileBlock { return ActionResult.PASS; } - throw new IllegalStateException(); - // FIXME FABRIC ContainerOpener.openContainer(SkyChestContainer.TYPE, player, ContainerLocator.forTileEntity(tile)); + ContainerOpener.openContainer(SkyChestContainer.TYPE, player, ContainerLocator.forTileEntity(tile)); } return ActionResult.SUCCESS; diff --git a/src/main/java/appeng/core/AppEngBase.java b/src/main/java/appeng/core/AppEngBase.java index 4706a1c6b..8fdcb2a6b 100644 --- a/src/main/java/appeng/core/AppEngBase.java +++ b/src/main/java/appeng/core/AppEngBase.java @@ -35,6 +35,8 @@ import appeng.mixins.CriteriaRegisterMixin; import appeng.recipes.handlers.*; import appeng.worldgen.ChargedQuartzOreConfig; import appeng.worldgen.ChargedQuartzOreFeature; +import appeng.worldgen.meteorite.MeteoriteStructure; +import net.earthcomputer.libstructure.LibStructure; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.BlockState; @@ -50,11 +52,11 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.chunk.StructureConfig; import net.minecraft.world.gen.decorator.Decorator; import net.minecraft.world.gen.decorator.NopeDecoratorConfig; import net.minecraft.world.gen.decorator.RangeDecoratorConfig; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.OreFeatureConfig; +import net.minecraft.world.gen.feature.*; import java.util.function.Consumer; @@ -295,14 +297,33 @@ public abstract class AppEngBase implements AppEng { } private void registerWorldGen() { + LibStructure.registerStructure( + MeteoriteStructure.ID, + MeteoriteStructure.INSTANCE, + GenerationStep.Feature.TOP_LAYER_MODIFICATION, + new StructureConfig(32, 8, 124895654), + new MeteoriteStructure(DefaultFeatureConfig.CODEC).configure(DefaultFeatureConfig.INSTANCE) + ); Registry.register(Registry.FEATURE, AppEng.makeId("charged_quartz_ore"), new ChargedQuartzOreFeature(ChargedQuartzOreConfig.CODEC)); Biome.BIOMES.forEach(b -> { -// FIXME FABRIC addMeteoriteWorldGen(b); + addMeteoriteWorldGen(b); addQuartzWorldGen(b); }); } + private static void addMeteoriteWorldGen(Biome b) { + if (!AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) { + return; + } + + if (b.getCategory() == Biome.Category.THEEND || b.getCategory() == Biome.Category.NETHER) { + return; + } + + b.addStructureFeature(MeteoriteStructure.INSTANCE.configure(FeatureConfig.DEFAULT)); + } + private static void addQuartzWorldGen(Biome b) { if (!AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) { return; diff --git a/src/main/java/appeng/decorative/solid/SkyStoneBlock.java b/src/main/java/appeng/decorative/solid/SkyStoneBlock.java index d55ddf852..66278765d 100644 --- a/src/main/java/appeng/decorative/solid/SkyStoneBlock.java +++ b/src/main/java/appeng/decorative/solid/SkyStoneBlock.java @@ -60,8 +60,7 @@ public class SkyStoneBlock extends AEBaseBlock { BlockPos currentPos, BlockPos facingPos) { if (worldIn instanceof ServerWorld) { ServerWorld serverWorld = (ServerWorld) worldIn; - WorldData.instance().compassData().service().updateArea(serverWorld, new ChunkPos(currentPos), - currentPos.getY()); + WorldData.instance().compassData().service().notifyBlockChange(serverWorld, currentPos); } return super.getStateForNeighborUpdate(stateIn, facing, facingState, worldIn, currentPos, facingPos); @@ -79,7 +78,7 @@ public class SkyStoneBlock extends AEBaseBlock { if (w instanceof ServerWorld) { ServerWorld serverWorld = (ServerWorld) w; - WorldData.instance().compassData().service().updateArea(serverWorld, new ChunkPos(pos), pos.getY()); + WorldData.instance().compassData().service().notifyBlockChange(serverWorld, pos); } } diff --git a/src/main/java/appeng/services/CompassService.java b/src/main/java/appeng/services/CompassService.java index 40edfd4f2..bcd1a1a5a 100644 --- a/src/main/java/appeng/services/CompassService.java +++ b/src/main/java/appeng/services/CompassService.java @@ -31,6 +31,7 @@ import net.minecraft.block.Block; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; import net.minecraft.world.chunk.Chunk; @@ -90,38 +91,52 @@ public final class CompassService { public void tryUpdateArea(final WorldAccess w, ChunkPos chunkPos) { // If this seems weird: during worldgen, WorldAccess is a specific region, but getWorld is - // still the server world + // still the server world. We do need to use the world access to get the chunk in question + // though, since during worldgen, it's not comitted to the actual world yet. World world = w.getWorld(); if (!(world instanceof ServerWorld)) { return; } - updateArea((ServerWorld) world, chunkPos); + Chunk chunk = w.getChunk(chunkPos.x, chunkPos.z); + updateArea((ServerWorld) world, chunk); } public void updateArea(final ServerWorld w, ChunkPos chunkPos) { - this.updateArea(w, chunkPos, CHUNK_SIZE); - this.updateArea(w, chunkPos, CHUNK_SIZE + 32); - this.updateArea(w, chunkPos, CHUNK_SIZE + 64); - this.updateArea(w, chunkPos, CHUNK_SIZE + 96); - - this.updateArea(w, chunkPos, CHUNK_SIZE + 128); - this.updateArea(w, chunkPos, CHUNK_SIZE + 160); - this.updateArea(w, chunkPos, CHUNK_SIZE + 192); - this.updateArea(w, chunkPos, CHUNK_SIZE + 224); + Chunk chunk = w.getChunk(chunkPos.x, chunkPos.z); + updateArea(w, chunk); } - public Future updateArea(final ServerWorld w, ChunkPos chunkPos, int y) { + public void updateArea(final ServerWorld w, Chunk chunk) { + this.updateArea(w, chunk, CHUNK_SIZE); + this.updateArea(w, chunk, CHUNK_SIZE + 32); + this.updateArea(w, chunk, CHUNK_SIZE + 64); + this.updateArea(w, chunk, CHUNK_SIZE + 96); + + this.updateArea(w, chunk, CHUNK_SIZE + 128); + this.updateArea(w, chunk, CHUNK_SIZE + 160); + this.updateArea(w, chunk, CHUNK_SIZE + 192); + this.updateArea(w, chunk, CHUNK_SIZE + 224); + } + + /** + * Notifies the compass service that a skystone block has either been placed or replaced + * at the give position. + */ + public void notifyBlockChange(final ServerWorld w, BlockPos pos) { + Chunk chunk = w.getChunk(pos); + updateArea(w, chunk, pos.getY()); + } + + private Future updateArea(final ServerWorld w, Chunk c, int y) { this.jobSize++; - final int cx = chunkPos.x; final int cdy = y >> 5; - final int cz = chunkPos.z; - final int low_y = cdy << 5; final int hi_y = low_y + 32; // lower level... - final Chunk c = w.getChunk(cx, cz); + int cx = c.getPos().x; + int cz = c.getPos().z; Block skyStoneBlock = AEApi.instance().definitions().blocks().skyStoneBlock().block(); BlockPos.Mutable pos = new BlockPos.Mutable(); diff --git a/src/main/java/appeng/util/InventoryAdaptor.java b/src/main/java/appeng/util/InventoryAdaptor.java index ec2025b60..1e02f3298 100644 --- a/src/main/java/appeng/util/InventoryAdaptor.java +++ b/src/main/java/appeng/util/InventoryAdaptor.java @@ -39,7 +39,6 @@ import net.minecraft.util.math.Direction; */ public abstract class InventoryAdaptor implements Iterable { public static InventoryAdaptor getAdaptor(final BlockEntity te, final Direction d) { - FixedItemInv inv = ItemAttributes.FIXED_INV.get(te.getWorld(), te.getPos().offset(d), SearchOptions.inDirection(d.getOpposite())); if (inv == ItemAttributes.FIXED_INV.defaultValue) { diff --git a/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java b/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java index 8203dafda..23427474e 100644 --- a/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java +++ b/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java @@ -21,6 +21,12 @@ package appeng.worldgen.meteorite; import java.util.ArrayList; import java.util.List; +import alexiil.mc.lib.attributes.AttributeList; +import alexiil.mc.lib.attributes.AttributeProvider; +import alexiil.mc.lib.attributes.AttributeUtil; +import alexiil.mc.lib.attributes.item.ItemAttributes; +import appeng.tile.storage.SkyChestBlockEntity; +import appeng.util.inv.AdaptorFixedInv; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -203,8 +209,12 @@ public final class MeteoritePlacer { if (AEConfig.instance().isFeatureEnabled(AEFeature.SPAWN_PRESSES_IN_METEORITES)) { this.putter.put(world, pos, this.skyChestDefinition.block().getDefaultState()); - final BlockEntity te = world.getBlockEntity(pos); // FIXME: this is also probably a band-aid for another issue - final InventoryAdaptor ap = InventoryAdaptor.getAdaptor(te, Direction.UP); + final SkyChestBlockEntity te = (SkyChestBlockEntity) world.getBlockEntity(pos); + InventoryAdaptor ap = null; + if (te != null) { + ap = new AdaptorFixedInv(te.getInternalInventory()); + } + if (ap != null && !ap.containsItems()) // FIXME: band-aid for meteorites being generated multiple times { // TODO: loot tables would be better diff --git a/src/main/java/appeng/worldgen/meteorite/MeteoriteStructure.java b/src/main/java/appeng/worldgen/meteorite/MeteoriteStructure.java index 6f834c6b9..4e93d5e71 100644 --- a/src/main/java/appeng/worldgen/meteorite/MeteoriteStructure.java +++ b/src/main/java/appeng/worldgen/meteorite/MeteoriteStructure.java @@ -23,18 +23,9 @@ public class MeteoriteStructure extends StructureFeature { @Override public boolean shouldStartAt(ChunkGenerator generator, BiomeSource biomeSource, long seed, ChunkRandom randIn, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos2, DefaultFeatureConfig featureConfig) { - int i = chunkX >> 4; - int j = chunkZ >> 4; - randIn.setSeed((long) (i ^ j << 4) ^ seed); - randIn.nextInt(); return randIn.nextBoolean(); } - @Override - public String getName() { - return ID.toString(); - } - @Override public StructureStartFactory getStructureStartFactory() { return MeteoriteStructureStart::new; diff --git a/src/main/java/appeng/worldgen/meteorite/PlacedMeteoriteSettings.java b/src/main/java/appeng/worldgen/meteorite/PlacedMeteoriteSettings.java index abbcbdf01..45914c7b5 100644 --- a/src/main/java/appeng/worldgen/meteorite/PlacedMeteoriteSettings.java +++ b/src/main/java/appeng/worldgen/meteorite/PlacedMeteoriteSettings.java @@ -71,7 +71,7 @@ public final class PlacedMeteoriteSettings { } public CompoundTag write(CompoundTag tag) { - tag.putLong(Constants.TAG_POS, pos.toLong()); + tag.putLong(Constants.TAG_POS, pos.asLong()); tag.putFloat(Constants.TAG_RADIUS, meteoriteRadius); tag.putByte(Constants.TAG_CRATER, (byte) craterType.ordinal()); diff --git a/src/unported/java/appeng/core/Registration.java b/src/unported/java/appeng/core/Registration.java index 078ff2f63..2eea0c3c3 100644 --- a/src/unported/java/appeng/core/Registration.java +++ b/src/unported/java/appeng/core/Registration.java @@ -267,20 +267,6 @@ final class Registration { }); } - private static void addMeteoriteWorldGen(Biome b) { - if (!AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) { - return; - } - - if (b.getCategory() == Biome.Category.THEEND || b.getCategory() == Biome.Category.NETHER) { - return; - } - - b.addStructureFeature(MeteoriteStructure.INSTANCE.configure(FeatureConfig.DEFAULT)); - b.addFeature(GenerationStep.Feature.TOP_LAYER_MODIFICATION, - MeteoriteStructure.INSTANCE.configure(FeatureConfig.DEFAULT)); - } - public void registerWorldGen(RegistryEvent.Register> evt) { IForgeRegistry> r = evt.getRegistry();