Jump to content

FizixRichard

Members
  • Posts

    16
  • Joined

  • Last visited

Posts posted by FizixRichard

  1. NullPointerExceptions mean that you're trying to use a property (variable) that hasn't been set. In other words, you have a variable that's empty.

     

    I've been experimenting with structure gen and have gotten structure generation working, I made a thread on this page and the source is there if you need something working as a reference. I wouldn't say its particularly elegant code but it works.

  2. Figured this out and I thought I'd update this in case anyone else is trying to figure structure generation stuff out.

     

     

    public class TestStructurePieces
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
        private static String pathIn = "test_structure";
        private static String pieceLocation = "test/test_structure";
        private static IStructurePieceType pieceStructureIn = CeStructurePieces.TEST_STRUCTURE;
    
    
        public static void register()
        {
            JigsawManager.REGISTRY.register(new JigsawPattern(
                    new ResourceLocation(
                            Ce.MODID,
                            pathIn
                    ),
                    new ResourceLocation("empty"),
                    ImmutableList.of(
                                    Pair.of(new SingleJigsawPiece(Ce.MODID + ":" + pieceLocation), 1)                         
                                    ),
                    JigsawPattern.PlacementBehaviour.RIGID)
            );
        }
    
        public static void create(ChunkGenerator<?> generator, TemplateManager templateManager, BlockPos position, List<StructurePiece> pieces, SharedSeedRandom random) {
    
            JigsawManager.addPieces(new ResourceLocation(Ce.MODID, pathIn), 7, Piece::new, generator, templateManager, position, pieces, random);
        }
    
    
    
    
        public static class Piece extends AbstractVillagePiece
        {
            private TemplateManager templateManager;
    
            public Piece(TemplateManager templateManager, JigsawPiece jigsawPiece, BlockPos position, int groundLevelDelta, Rotation rotation, MutableBoundingBox bounds) {
    
                super(pieceStructureIn, templateManager, jigsawPiece, position, groundLevelDelta, rotation, bounds);
                this.templateManager = templateManager;
            }
    
            public Piece(TemplateManager templateManager, CompoundNBT compoundNBT) {
                super(templateManager, compoundNBT, pieceStructureIn);
    
                this.templateManager = templateManager;
            }
    
    
            @Override
            public boolean create(IWorld worldIn, ChunkGenerator<?> chunkGeneratorIn, Random randomIn, MutableBoundingBox mutableBoundingBoxIn, ChunkPos chunkPosIn) {
    
                BlockPos position = this.getPos();
    
                
    
                // Foundation Fill Process
                for(int x = this.boundingBox.minX; x < this.boundingBox.maxX; ++x) {
                    for(int z = this.boundingBox.minZ; z < this.boundingBox.maxZ; ++z) {
                        this.replaceAirAndLiquidDownwards(worldIn, Blocks.SANDSTONE.getDefaultState(), x, position.getY() - 1, z, mutableBoundingBoxIn);
                    }
                }
    
                return this.jigsawPiece.place(this.templateManager, worldIn, chunkGeneratorIn, this.pos, this.rotation, mutableBoundingBoxIn, randomIn);
            }
    
    
            protected void replaceAirAndLiquidDownwards(IWorld worldIn, BlockState blockstateIn, int x, int y, int z, MutableBoundingBox boundingboxIn) {
    
                int j = y;
    
                if (boundingboxIn.isVecInside(new BlockPos(x, j, z)))
                {
                    while((worldIn.isAirBlock(new BlockPos(x, j, z)) || worldIn.getBlockState(new BlockPos(x, j, z)).getMaterial().isLiquid()) && j > 1) {
                        worldIn.setBlockState(new BlockPos(x, j, z), blockstateIn, 2);
                        --j;
                    }
               }
            }
    
        }
    }

     

  3. I'm figuring out structures atm myself. You have to check that the terrain elevation is within an allowed range. If you look at the minecraft source you'll find the code to do this.

     

    Call a surface height range checker during the canBeGenerated method of your structure class:

     

    protected boolean surfaceCheck(@Nonnull ChunkGenerator<?> chunkGenerator, int chunkX, int chunkZ)
        {        
            int offset = getSize() * 16;
            int xStart = (chunkX << 4);
            int zStart = (chunkZ << 4);
    
           
            int c1 = chunkGenerator.func_222531_c(xStart, zStart, Heightmap.Type.WORLD_SURFACE_WG);
            int c2 = chunkGenerator.func_222531_c(xStart, zStart + offset, Heightmap.Type.WORLD_SURFACE_WG);
            int c3 = chunkGenerator.func_222531_c(xStart + offset, zStart, Heightmap.Type.WORLD_SURFACE_WG);
            int c4 = chunkGenerator.func_222531_c(xStart + offset, zStart + offset, Heightmap.Type.WORLD_SURFACE_WG);
    
          
            int lowerHeight = Math.min(Math.min(c1, c2), Math.min(c3, c4));
            int upperHeight = Math.max(Math.max(c1, c2), Math.max(c3, c4));
    
            LOGGER.info("Area Height Range" + lowerHeight + " to " + upperHeight);
    
            boolean isFlat = Math.abs(upperHeight - lowerHeight) <= getHeightDelta(); 
      
      // getHeightDelta() should just return the maximum elevation change you want to allow your structure to generate on (this can be a property at the top of the class and set on a per-structure basis). A value of 3 will allow for your structure to generate over a 3 block elevation change, lower numbers require flatter terrain but will (depending on the size of your structure) reduce the opportunities for the structure to spawn.
    
            return isFlat;
        }

     

     

    Call it something like this:

    In canBeGenerated method:
    
    if (surfaceCheck(chunkGenerator, chunkX, chunkZ))
    {
       ... Continue with other checks
    }

     

     

    The other option, which I'm trying to figure out, is generating blocks underneath the structure if they are air or water (which Minecraft does for certain structures). Not that I have figured out how to implement that.

  4. I thought I'd add the full source.

     

    Registries:

     

    SetupWorldGen

    public class setupWorldGen
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
    
        public static void setupWorldGen()
        {
            for (Biome biome : ForgeRegistries.BIOMES)
            {
                // Add structures ignoring Oceans
                if (!biome.getCategory() == Biome.Category.OCEAN)
                {
                    addSurfaceStructure(biome, CeStructures.TEST_STRUCTURE);
                }
            }
        }
    
    
    
    
        private static void addSurfaceStructure(Biome biome, Structure<NoFeatureConfig> structure) {
            biome.addStructure(structure.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG));
            biome.addFeature(GenerationStage.Decoration.SURFACE_STRUCTURES, structure.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
        }
    
    
    }

     

     

    CEStructures

    public class CeStructures
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
    
        // Declare structures
        public static final Structure<NoFeatureConfig> TEST_STRUCTURE = create(TestStructure.SHORT_NAME, new TestStructure(NoFeatureConfig::deserialize));
    
    
        @SubscribeEvent
        public static void createStructures(RegistryEvent.Register<Feature<?>> event)
        {
            // Register Structure Pieces
            CeStructurePieces.registerPieces();
    
    
            // Register Structures
            IForgeRegistry<Feature<?>> registry = event.getRegistry();
    
            registry.register(TEST_STRUCTURE);
    
        }
    
    
        private static @Nonnull
        <T extends Feature<?>> T create(String name, T feature) {
            feature.setRegistryName(CE.MODID, name.toLowerCase(Locale.ROOT));
            return feature;
        }
    
    
    }

     

     

    CeStructurePieces

    public class CeStructurePieces
    {
    
        private static final Logger LOGGER = LogManager.getLogger();
    
    
        // Declare Structure Pieces
        public static final IStructurePieceType TEST_STRUCTURE = TestStructurePieces.Piece::new;
    
    
    
        public static void registerPieces()
        {
            // Register The Jigsaw Pieces
            TestStructurePieces.register();
    
    
    
            // Register Structure Pieces
            register(TestStructure.SHORT_NAME, TEST_STRUCTURE);
    
        }
    
    
        @SuppressWarnings("UnusedReturnValue")
        private static @Nonnull
        IStructurePieceType register(String name, IStructurePieceType type) {
            return Registry.register(Registry.STRUCTURE_PIECE, new ResourceLocation(CE.MODID, name.toLowerCase(Locale.ROOT)), type);
        }
    
    
    }

     

     

    Structure and Structure Piece Classes:

     

    TestStructure

    public class TestStructure extends AbstractStructure
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
        // Properties
        public static final String SHORT_NAME = "test_structure";
        public static final String LONG_NAME = CE.MODID + ":" + SHORT_NAME;
        private static final int SEED_MODIFIER = 165745296;
        private static final int STRUCTURE_SIZE = 3;
        private static final int STRUCTURE_DISTANCE = 10;
        private static final int STRUCTURE_SEPARATION = 5;
        private static final int HEIGHT_DELTA = 3;
        private static final double SPAWN_CHANCE = 0.7;
    
    
    
        public TestStructure(Function<Dynamic<?>, ? extends NoFeatureConfig> configFactoryIn) {
            super(configFactoryIn, SHORT_NAME, STRUCTURE_SIZE, HEIGHT_DELTA);        
        }
    
    
        @Override
        protected int getSeedModifier() {
            return SEED_MODIFIER;
        }
    
        @Override
        public @Nonnull
        String getStructureName() {
            return LONG_NAME;
        }
    
        @Override
        public int getSize() {
            return STRUCTURE_SIZE;
        }
    
        @Override
        public int getHeightDelta() {
            return HEIGHT_DELTA;
        }
    
        @Override
        protected int getFeatureDistance(ChunkGenerator<?> generator) { return STRUCTURE_DISTANCE; }
    
        @Override
        protected int getFeatureSeparation(ChunkGenerator<?> generator) { return STRUCTURE_SEPARATION; }
    
        @Override
        protected double getSpawnChance() { return SPAWN_CHANCE; }
    
    
    
        @Override
        public @Nonnull
        IStartFactory getStartFactory() {
            return Start::new;
        }
    
    
        public static class Start extends MarginedStructureStart {
    
            public Start(Structure<?> structure, int chunkX, int chunkZ, MutableBoundingBox bounds, int reference, long seed) {
                super(structure, chunkX, chunkZ, bounds, reference, seed);
            }
    
            @Override
            public void init(@Nonnull ChunkGenerator<?> chunkGenerator, @Nonnull TemplateManager templateManager, int chunkX, int chunkZ, @Nonnull Biome biome) {
                Rotation rotation = Rotation.values()[this.rand.nextInt(Rotation.values().length)];
                BlockPos position = getSurfaceStructurePosition(chunkGenerator, 3, rotation, chunkX, chunkZ);
    
                
                TestStructurePieces.create(chunkGenerator, templateManager, position, this.components, this.rand);
    
                this.recalculateStructureSize();
            }
          
          
          public BlockPos getSurfaceStructurePosition(@Nonnull ChunkGenerator generator, int size, Rotation rotation, int chunkX, int chunkZ) {
                int xOffset = size * 16;
                int zOffset = size * 16;
    
                int x = (chunkX << 4);
                int z = (chunkZ << 4);
    
               
                BlockPos adjustedPos = new BlockPos(x, 0, z);
    
                return adjustedPos;            
            }
        }
    
    }

     

    AbstractStruture

    public abstract class AbstractStructure extends ScatteredStructure<NoFeatureConfig> {
        private static final Logger LOGGER = LogManager.getLogger();
      
        private final String name;
        private final int size;
        private final int heightdelta;
    
    
        public AbstractStructure(Function<Dynamic<?>, ? extends NoFeatureConfig> configFactoryIn, String name, int size, int heightdelta) {
            super(configFactoryIn);
            this.name = name;
            this.size = size;
            this.heightdelta = heightdelta;
        }
    
        protected abstract double getSpawnChance();
    
        @Override
        public int getSize() {
            return this.size;
        }
    
    
        public int getHeightDelta() {
            return this.heightdelta;
        }
    
        @Override
        protected int getBiomeFeatureDistance(ChunkGenerator<?> chunkGenerator) {
            return getFeatureDistance(chunkGenerator);
        }
    
        protected abstract int getFeatureDistance(ChunkGenerator<?> chunkGenerator);
    
        @Override
        protected int getBiomeFeatureSeparation(ChunkGenerator<?> chunkGenerator) {
            return getFeatureSeparation(chunkGenerator);
        }
    
        protected abstract int getFeatureSeparation(ChunkGenerator<?> chunkGenerator);
    
    
        @Override
        @Nonnull
        public String getStructureName() {
            return new ResourceLocation(CE.MODID, name).toString();
        }
    
    
        @Override
        public boolean canBeGenerated(BiomeManager biomeManager, @Nonnull ChunkGenerator<?> chunkGenerator, @Nonnull Random randIn, int chunkX, int chunkZ, @Nonnull Biome biomeIn)
        {
    
            /* original
            ChunkPos chunkpos = this.getStartPositionForPosition(generatorIn, randIn, chunkX, chunkZ, 0, 0);
          return chunkX == chunkpos.x && chunkZ == chunkpos.z && generatorIn.hasStructure(biomeIn, this);
             */
            
    
            ChunkPos chunkpos = getStartPositionForPosition(chunkGenerator, randIn, chunkX, chunkZ, 0, 0);
    
            
            if (chunkX == chunkpos.x && chunkZ == chunkpos.z)
            {
                // Is the surface where we want to generate flat enough
                if (surfaceCheck(chunkGenerator, chunkX, chunkZ))
                {
    
                    
                    for (int x = chunkX - getSize(); x <= chunkX + getSize(); x++) {
                        for (int z = chunkZ - getSize(); z <= chunkZ + getSize(); z++)
                        {
                            if (!chunkGenerator.hasStructure(biomeIn, this)) {
    
                                return false;
                            }
                        }
                    }
                  
    
                    // Check how far from villages we are            
                    for (int x2 = chunkX - 5; x2 <= chunkX + 5; ++x2) {
                        for (int z2 = chunkZ - 5; z2 <= chunkZ + 5; ++z2) {
                            BlockPos position = new BlockPos((x2 << 4) + 9, 0, (z2 << 4) + 9);
                            if (Feature.VILLAGE.canBeGenerated(biomeManager, chunkGenerator, randIn, x2, z2, biomeManager.getBiome(position))) {
                                
                                return false;
                            }
                        }
                    }
    
                    // Apply spawn chance               
                    int x3 = chunkX >> 4;
                    int z3 = chunkZ >> 4;
                    randIn.setSeed((long) (x3 ^ z3 << 4) ^ chunkGenerator.getSeed());
                    randIn.nextInt();
    
                    Double randVal = randIn.nextDouble();
                    boolean chanceCheck = randVal < getSpawnChance();               
    
                    return chanceCheck;
    
                }
            }
    
            return false;
        }
    
    
    
        @Override
        @Nonnull
        protected ChunkPos getStartPositionForPosition(ChunkGenerator<?> chunkGenerator, Random random, int x, int z, int spacingOffsetsX, int spacingOffsetsZ)
        {
            
            int featureDistance = this.getBiomeFeatureDistance(chunkGenerator);
            int featureSeparation = this.getBiomeFeatureSeparation(chunkGenerator);
            int xPos = x + featureDistance * spacingOffsetsX;
            int zPos = z + featureDistance * spacingOffsetsZ;
            int i1 = xPos < 0 ? xPos - featureDistance + 1 : xPos;
            int j1 = zPos < 0 ? zPos - featureDistance + 1 : zPos;
            int validChunkX = i1 / featureDistance;
            int validChunkZ = j1 / featureDistance;
    
            ((SharedSeedRandom) random).setLargeFeatureSeedWithSalt(chunkGenerator.getSeed(), validChunkX, validChunkZ, getSeedModifier());
    
            validChunkX = validChunkX * featureDistance;
            validChunkZ = validChunkZ * featureDistance;
            validChunkX = validChunkX + random.nextInt(featureDistance - featureSeparation);
            validChunkZ = validChunkZ + random.nextInt(featureDistance - featureSeparation);
            return new ChunkPos(validChunkX, validChunkZ);
        }
    
    
    
    
        protected boolean surfaceCheck(@Nonnull ChunkGenerator<?> chunkGenerator, int chunkX, int chunkZ)
        {      
    
            int offset = getSize() * 16;
            int xStart = (chunkX << 4);
            int zStart = (chunkZ << 4);
    
            
            int c1 = chunkGenerator.func_222531_c(xStart, zStart, Heightmap.Type.WORLD_SURFACE_WG);
            int c2 = chunkGenerator.func_222531_c(xStart, zStart + offset, Heightmap.Type.WORLD_SURFACE_WG);
            int c3 = chunkGenerator.func_222531_c(xStart + offset, zStart, Heightmap.Type.WORLD_SURFACE_WG);
            int c4 = chunkGenerator.func_222531_c(xStart + offset, zStart + offset, Heightmap.Type.WORLD_SURFACE_WG);
    
    
            int lowerHeight = Math.min(Math.min(c1, c2), Math.min(c3, c4));
            int upperHeight = Math.max(Math.max(c1, c2), Math.max(c3, c4));
    
            //LOGGER.info("Area Height Range: " + lowerHeight + " to " + upperHeight);
    
            boolean isFlat = Math.abs(upperHeight - lowerHeight) <= getHeightDelta();      
    
            return isFlat;
        }
    }

     

     

    TestStructurePiece

    public class TestStructurePieces
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
        private static String pathIn = "test_structure";
        private static String pieceLocation = "test/test_structure";
        private static IStructurePieceType pieceStructureIn = CeStructurePieces.TEST_STRUCTURE;
        private static IWorld iWorldIn;
        private static int size = 3;
    
        public static void register()
        {
    
    
            JigsawManager.REGISTRY.register(new JigsawPattern(
                    new ResourceLocation(
                            CE.MODID,
                            pathIn
                    ),
                    new ResourceLocation("empty"),
                    ImmutableList.of(
                                    Pair.of(new SingleJigsawPiece(CE.MODID + ":" + pieceLocation), 1)
                                    ),
                    JigsawPattern.PlacementBehaviour.RIGID)
            );
    
    
    
    
        }
    
        public static void create(ChunkGenerator<?> generator, TemplateManager templateManager, BlockPos position, List<StructurePiece> pieces, SharedSeedRandom random) {
    
            // Set the world from chunk generator (not sure how else to get world from here)
            iWorldIn = ObfuscationReflectionHelper.getPrivateValue(ChunkGenerator.class, generator, "field_222540_a");
    
            LOGGER.info("Adding Pieces: " + position);
           
            JigsawManager.addPieces(new ResourceLocation(CE.MODID, pathIn), 7, Piece::new, generator, templateManager, position, pieces, random);
        }
    
    
    
    
        public static class Piece extends AbstractVillagePiece {
        
            public Piece(TemplateManager templateManager, JigsawPiece jigsawPiece, BlockPos position, int groundLevelDelta, Rotation rotation, MutableBoundingBox bounds) {
    
                super(pieceStructureIn, templateManager, jigsawPiece, position, groundLevelDelta, rotation, bounds);
    
                          
                // Fill underside
              	int yStart = 100;
              	int xPos = position.getX();            
                int zPos = position.getZ();            
              
              	int xPosMax = xPos + bounds.getXSize();
                int zPosMax = zPos + bounds.getZSize();
    		
                // Tried various ways of getting yStart here, the bounding box returns 0, I fixed to 100 for testing
              
                for(int x = xPos; x < xPosMax; ++x) {
                    for(int z = zPos; z < zPosMax; ++z) {
                        //int k = -5;
                        this.replaceAirAndLiquidDownwards(iWorldIn, Blocks.SANDSTONE.getDefaultState(), x,  yStart, z, bounds);
                    }
                }
    
    
            }
    
            public Piece(TemplateManager templateManager, CompoundNBT compoundNBT) {
                super(templateManager, compoundNBT, pieceStructureIn);
            }
    
    
            /**
             * Replaces air and liquid from given position downwards. Stops when hitting anything else than air or liquid
             */
            protected void replaceAirAndLiquidDownwards(IWorld worldIn, BlockState blockstateIn, int x, int y, int z, MutableBoundingBox boundingboxIn)
            {            
               int i = this.getXWithOffset(x, z);
               int j = this.getYWithOffset(y);
          		int k = this.getZWithOffset(x, z);
              
              // If I output data to console here, I get 4 blocks inside the bounding box (the structure is 7 high), and everything is air. It appears like the blocks arent set yet???
          		if (boundingboxIn.isVecInside(new BlockPos(i, j, k))) {
             while((worldIn.isAirBlock(new BlockPos(i, j, k)) || worldIn.getBlockState(new BlockPos(i, j, k)).getMaterial().isLiquid()) && j > 1) {
                worldIn.setBlockState(new BlockPos(i, j, k), blockstateIn, 2);
                --j;
             }
    
          }
            }
         }
      }
    }

     

     

     

     

     

  5. Hey all,

     

    I'm currently playing with structure generation in MC 1.15.2 and have largely gotten everything working. My custom structures generate and I can control how they're placed which is cool. However, there are some quirks I'd like to fix but I'm struggling to find answers.

     

    The big one is when the structure overhangs surface elevation changes or water (so there are air or water blocks below part of the structure. I've got a method that checks chunk elevation and will only spawn if the elevation is changes within certain bounds, but this still allows for air or water below parts of the structure (unless I tell it to only spawn on a completely flat chunk, which limits spawn possibilities on larger structures). What I would like to do is to fill any air or water blocks underneath the custom structure with a solid block, which I've found code for within some of the vanilla structures, however I cannot get these functions to work within my custom structure piece.

     

    When I implement them, they appeared to do nothing, outputting to the console it appears all blocks in the vertical column are air and if I try to replace an air block with sandstone, the generator hangs.

     

    public class TestStructurePieces
    {
        private static final Logger LOGGER = LogManager.getLogger();
    
        private static String pathIn = "test_structure";
        private static String pieceLocation = "test/test_structure";
        private static IStructurePieceType pieceStructureIn = CeStructurePieces.TEST_STRUCTURE;
        private static IWorld iWorldIn;
        private static int size = 3;
    
        public static void register()
        {
    
    
            JigsawManager.REGISTRY.register(new JigsawPattern(
                    new ResourceLocation(
                            CE.MODID,
                            pathIn
                    ),
                    new ResourceLocation("empty"),
                    ImmutableList.of(
                                    Pair.of(new SingleJigsawPiece(CE.MODID + ":" + pieceLocation), 1)
                                    ),
                    JigsawPattern.PlacementBehaviour.RIGID)
            );
    
    
    
    
        }
    
        public static void create(ChunkGenerator<?> generator, TemplateManager templateManager, BlockPos position, List<StructurePiece> pieces, SharedSeedRandom random) {
    
            // Set the world from chunk generator (not sure how else to get world from here)
            iWorldIn = ObfuscationReflectionHelper.getPrivateValue(ChunkGenerator.class, generator, "field_222540_a");
    
            LOGGER.info("Adding Pieces: " + position);
           
            JigsawManager.addPieces(new ResourceLocation(CE.MODID, pathIn), 7, Piece::new, generator, templateManager, position, pieces, random);
        }
    
    
    
    
        public static class Piece extends AbstractVillagePiece {
        
            public Piece(TemplateManager templateManager, JigsawPiece jigsawPiece, BlockPos position, int groundLevelDelta, Rotation rotation, MutableBoundingBox bounds) {
    
                super(pieceStructureIn, templateManager, jigsawPiece, position, groundLevelDelta, rotation, bounds);
    
                          
                // Fill underside
              	int yStart = 100;
              	int xPos = position.getX();            
                int zPos = position.getZ();            
              
              	int xPosMax = xPos + bounds.getXSize();
                int zPosMax = zPos + bounds.getZSize();
    		
                // Tried various ways of getting yStart here, the bounding box returns 0, I fixed to 100 for testing
              
                for(int x = xPos; x < xPosMax; ++x) {
                    for(int z = zPos; z < zPosMax; ++z) {
                        //int k = -5;
                        this.replaceAirAndLiquidDownwards(iWorldIn, Blocks.SANDSTONE.getDefaultState(), x,  yStart, z, bounds);
                    }
                }
    
    
            }
    
            public Piece(TemplateManager templateManager, CompoundNBT compoundNBT) {
                super(templateManager, compoundNBT, pieceStructureIn);
            }
    
    
            /**
             * Replaces air and liquid from given position downwards. Stops when hitting anything else than air or liquid
             */
            protected void replaceAirAndLiquidDownwards(IWorld worldIn, BlockState blockstateIn, int x, int y, int z, MutableBoundingBox boundingboxIn)
            {            
               int i = this.getXWithOffset(x, z);
               int j = this.getYWithOffset(y);
          		int k = this.getZWithOffset(x, z);
              
              // If I output data to console here, I get 4 blocks inside the bounding box (the structure is 7 high), and everything is air. It appears like the blocks arent set yet???
          		if (boundingboxIn.isVecInside(new BlockPos(i, j, k))) {
             while((worldIn.isAirBlock(new BlockPos(i, j, k)) || worldIn.getBlockState(new BlockPos(i, j, k)).getMaterial().isLiquid()) && j > 1) {
                worldIn.setBlockState(new BlockPos(i, j, k), blockstateIn, 2);
                --j;
             }
    
          }
            }
         }
      }
    }

     

     

    Anyone have any idea whats going on and how to get this working?

     

     

    My other question is, is it possible to have a structure generate partially underground, for example a house with a basement?

     

     

     

  6. Hi,

     

    I’ve created various custom equipment such as weapons, armour and tools.

     

    I want these items to increase in performance as you use them. So, I want to modify the attributes of these custom items after creation. For example, increase its durability or attack power. This is for that one instance of the item in your inventory, not for the item family.

     

    Whats the best way of going about this? I’m still a beginner so a simpler method may be best for me.

     

     

  7. Today a weird problem has occurred.

     

    I'm using Intellij Idea. I opened my mod project to find various imports were't resolving. Namely:

     

    import net.minecraftforge.fml.loading.FMLPaths;

     

    FMLPaths is red

     

    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;

     

    LogManager and Logger are red.

     

    Then within my script the logger is red, and events on the loading listeners are red. I tried refreshing dependencies, and reimporting the build.gradle to no avail. Even more strangely... if I attempt to run the mod, it works as though nothing were wrong.

     

    I opened some of my other mod projects, same thing happens. It's affecting all of them. It appears to exist in the IDE only.

     

     

    Additionally, I just opened one of my classes that appeared fine (wasn't highlighted in red in the IDE project tree) and its not showing errors on

     

    import net.minecraftforge.eventbus.api.SubscribeEvent;

     

    SubscribeEvent is in red.

     

     

    Here is my build.gradle in case it helps:

     

     

    buildscript {
        repositories {
            maven { url = 'https://files.minecraftforge.net/maven' }
            jcenter()
            mavenCentral()
        }
        dependencies {
            classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
        }
    }
    apply plugin: 'net.minecraftforge.gradle'
    // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
    apply plugin: 'eclipse'
    apply plugin: 'maven-publish'
    
    
    version = modMinecraftVersion + "-" + modVersion;
    group = modGroup
    archivesBaseName = modFileName + "-" + version;
    sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
    
    minecraft {
        mappings channel: mappingsChannel, version: mappingsVersion
        // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
        // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
    
        // Default run configurations.
        // These can be tweaked, removed, or duplicated as needed.
        runs {
            client {
                workingDirectory project.file('run')
    
                // Recommended logging data for a userdev environment
                property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
    
                // Recommended logging level for the console
                property 'forge.logging.console.level', 'debug'
    
                mods {
                    examplemod {
                        source sourceSets.main
                    }
                }
            }
    
            server {
                workingDirectory project.file('run')
    
                // Recommended logging data for a userdev environment
                property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
    
                // Recommended logging level for the console
                property 'forge.logging.console.level', 'debug'
    
                mods {
                    examplemod {
                        source sourceSets.main
                    }
                }
            }
    
            data {
                workingDirectory project.file('run')
    
                // Recommended logging data for a userdev environment
                property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
    
                // Recommended logging level for the console
                property 'forge.logging.console.level', 'debug'
    
                args '--mod', 'cerulean', '--all', '--output', file('src/generated/resources/')
    
                mods {
                    examplemod {
                        source sourceSets.main
                    }
                }
            }
        }
    }
    
    repositories {
        maven {url "http://tehnut.info/maven"}    
    }
    
    dependencies {
        minecraft "net.minecraftforge:forge:" + modMinecraftVersion + "-" + modForgeVersion
    
        // You may put jars on which you depend on in ./libs or you may define them like so..
        compile fg.deobf("mcp.mobius.waila:Hwyla:1.10.6-B67_1.14.4")  
    }
    
    // Example for how to get properties into the manifest for reading by the runtime..
    jar {
        manifest {
            attributes([
                "Specification-Title": modID,
                "Specification-Vendor": modGroup,
                "Specification-Version": "1", // We are version 1 of ourselves
                "Implementation-Title": project.name,
                "Implementation-Version": "${version}",
                "Implementation-Vendor" : modGroup,
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
            ])
        }
    }
    
    // Example configuration to allow publishing using the maven-publish task
    // we define a custom artifact that is sourced from the reobfJar output task
    // and then declare that to be published
    // Note you'll need to add a repository here
    def reobfFile = file("$buildDir/reobfJar/output.jar")
    def reobfArtifact = artifacts.add('default', reobfFile) {
        type 'jar'
        builtBy 'reobfJar'
    }
    publishing {
        publications {
            mavenJava(MavenPublication) {
                artifact reobfArtifact
            }
        }
        repositories {
            maven {
                url "file:///${project.projectDir}/mcmodsrepo"
            }
        }
    }

     

     

    My gradle.properties

    # Sets default memory used for gradle commands. Can be overridden by user or command line properties.
    # This is required to provide enough memory for the Minecraft decompilation process.
    org.gradle.jvmargs=-Xmx3G
    org.gradle.daemon=false
    
    modID = cerulean
    modGroup = com.fizix.cerulean
    modVersion = 1.0.0
    modFileName = Cerulean
    modMinecraftVersion = 1.14.4
    modForgeVersion = 28.1.0
    mappingsChannel = snapshot
    mappingsVersion = 20190916-1.14.3
    

     

     

    And the mods.toml

     

    modLoader="javafml"
    
    loaderVersion="[28,)" #mandatory (28 is current forge version)
    #issueTrackerURL="http://my.issue.tracker/" #optional
    
    [[mods]]
    modId="cerulean"
    version = "1.0.0"
    displayName="Cerulean"
    #updateJSONURL="http://myurl.me/"
    displayURL="http://example.com/"
    #logoFile="examplemod.png" #optional
    credits="Thanks for this example mod goes to Java"
    authors="Love, Cheese and small house plants"
    description='''
     Description / info
    '''
    
    # Dependencies
    [[dependencies.cerulean]]
        modId="forge"
        mandatory=true
        versionRange="[28,)"
        ordering="NONE"
        side="BOTH"
    
    [[dependencies.cerulean]]
        modId="minecraft"
        mandatory=true
        versionRange="[1.14.4]"
        ordering="NONE"
        side="BOTH"
    

     

     

     

  8. Done.

     

    Could this have something to do with it?

     

    lootcontext > lootTableManager > registeredLootTables > {ResourceLocation@18432} "minecraft:empty" -> {LootTable@15258}

    lootcontext > lootTables = {LinkedHashSet@18751} size = 0

     

    It's registered to minecraft:empty. "LootTable@15258" is the loottable, loot tables under lootcontext is 0, pools is empty, path is empty.

     

     

     

  9. I've checked the debugger and it's not throwing any errors.

     

    If I check to see whether LOOT_TABLE is set, it's fine.

     

    Check 1: reads "Loot table exists"

    Check 2: reads "Item Stack List contains 0 records"

     

     

    if (LOOT_TABLE == LootTables.EMPTY)
    {
        LOGGER.debug("Loot table is empty");
    }
    else
    {
        LOGGER.debug("Loot table exists");
    }
    
    
    LootContext.Builder builder = new LootContext.Builder((ServerWorld) world);
    LootTable loottable = ServerLifecycleHooks.getCurrentServer().getLootTableManager().getLootTableFromLocation(LOOT_TABLE);
    LootContext lootcontext = builder.withParameter(LootParameters.POSITION, player.getPosition()).withParameter(LootParameters.THIS_ENTITY, player).build(LootParameterSets.GIFT);
    
    List<ItemStack> itemstacklist = loottable.generate(lootcontext);
    
    LOGGER.debug("Item Stack List contains " + itemstacklist.size() + " records");

     

     

    I've tried this with various parameter sets and it returns the same. If there is anything wrong with the loot table json, it would throw an error or warning wouldn't it?

     

     

  10. Thanks. I have checked the classes, but I'm not sure what to set. Sorry.

     

    When I try with EMPTY the for loop doesn't fire. It's just a standard loot table with a list of items.

     

    for(ItemStack itemstack : loottable.generate(builder.build(LootParameterSets.EMPTY)))
    {
        LOGGER.debug("Spawning Loot");
    
        ItemEntity entityitem = new ItemEntity(world, player.posX, player.posY + 1.5D, player.posZ, itemstack);
        world.addEntity(entityitem);
    }
  11. Thank you. I understand what you're saying now. But, I'm not finding any information anywhere.

     

    I can't figure out how to set the LootParameterSet for this. I'm still learning, but I don't think this is something complicated. I'm clearly missing something obvious, but without any documentation or guides, I'm finding myself going around in circles. :/

     

     

    Does anyone know how to declare the LootParameterSet for builder.build() to generate the ItemStack?

     

    LootContext.Builder builder = new LootContext.Builder((ServerWorld) world);
    LootTable loottable = ServerLifecycleHooks.getCurrentServer().getLootTableManager().getLootTableFromLocation(LOOT_TABLE);
    
    for(ItemStack itemstack : loottable.generate(builder.build(???)))
    {
        ItemEntity entityitem = new ItemEntity(world, player.posX, player.posY + 1.5D, player.posZ, itemstack);
        world.addEntity(entityitem);
    }
  12. Thanks for the reply.

     

    I'm a beginner so I'm struggling a bit here. How do I use LootTable.generate()? I'm not finding any examples or documentation online.

     

    Updated code to:

     

    LootTable loottable = ServerLifecycleHooks.getCurrentServer().getLootTableManager().getLootTableFromLocation(LOOT_TABLE);
    LootContext.Builder builder = new LootContext.Builder((ServerWorld) world);
    
    for (ItemStack itemstack : loottable.generate(world.rand, builder.build()))

     

    with:

    for (ItemStack itemstack : loottable.generate(world.rand, builder.build()))

     

    builder.build() isn't accepted.

  13. Hi all,

     

    I'm creating a custom item, which when the player uses it, gives the player random items from a loot table.

     

    I'm generating the custom item which appears in game, I have a loot table setup, and can use the item.

     

    Where I'm struggling is getting random loot from the loot table and giving it to the player. When I look online I can see how to do it the 1.12 way, which uses loottable.generateLootForPools(). But, this doesn't work in 1.14, generateLootForPools() doesn't appear to exist.

     

    Something like this in 1.12:

    for (ItemStack itemstack : loottable.generateLootForPools(world.rand, builder.build())){    ItemEntity entityitem = new ItemEntity(world, player.posX, player.posY + 1.5D, player.posZ, itemstack);    world.spawnEntity(entityitem);}
    	

     

    Does anyone know how to do this in 1.14?

     

     

    Here is the relevant code from my custom item's class...

     

    I'm setting the loot table resource:

    private static final ResourceLocation LOOT_TABLE = new ResourceLocation("mymod:mymod_loot");
    	

     

     

    I have an action for when  the player right clicks the item in their hand, which destroys the item and calls "generateLoot()"

    @Overridepublic ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn){    LOGGER.debug("Right Clicked");    ItemStack itemstack = playerIn.getHeldItem(handIn);    // Remove item    itemstack.shrink(1);       if (!worldIn.isRemote)    {        generateLoot(worldIn, playerIn);    }    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);}
    	

     

     

    The generateLoot method:

     

        private void generateLoot(World world,PlayerEntity player)    {        LootTable table = ServerLifecycleHooks.getCurrentServer().getLootTableManager().getLootTableFromLocation(LOOT_TABLE);        LootContext.Builder builder = new LootContext.Builder((ServerWorld) world);        // Here is where I need to generate random loot from loot table and give to player(???)           }
    	

     

     

    Any help would be greatly appreciated :)

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.