Jump to content

LogicTechCorp

Forge Modder
  • Posts

    260
  • Joined

  • Last visited

Posts posted by LogicTechCorp

  1. On 4/14/2017 at 2:13 AM, diesieben07 said:

    They look alright.

    The TradeOffer class has to contain the fields that are present in the offer section of your JSON. You will have to write a custom deserializer for ItemStack.

     

    And again, read the user guide. It answers all your questions.

    I have it working now. Do you have any suggestions on how I can improve it?

    https://github.com/LogicTechCorp/NetherEx/blob/715c79aec5b060b52800e8fb9f0cc6f027fcc5e4/src/main/java/nex/trade/TradeListManager.java

  2. I am adding an entity with a trading ability to my mod. The trades are defined using Json and I would like some help trying to figure out how to deserialize the file. I have looked through the Minecraft source to see how they do it and have googled, but I still do not understand how to do it. All help is appreciated.

     

    Here is an example of how the Json is structured:

    {
        "name": "Example Trade List",
        "professions": [
            {
                "name": "blacksmith",
                "careers": [
                    {
                        "name": "toolsmith",
                        "offers": [
                            {
                                "output": {"id": "minecraft:golden_pickaxe", "meta": 0, "count": {"min": 1, "max": 4},
                                    "tag":
                                    {
                                        "ench": [{"id": 34, "level": 3}, {"id": 70, "level": 1}],
                                        "display": {"name": "Golden Pickaxe", "color": "FFFF55", "lore": ["A Golden Pickaxe", "Forged with magic"]}
                                    }
                                },
                                "inputA": {"id": "minecraft:gold_ingot", "meta": 0, "count": {"min": 3, "max": 3}},
                                "inputB": {"id": "minecraft:stick", "meta": 0, "count": {"min": 2, "max": 2}},
                                "level": 0,
                                "stock": {"min": 2, "max": 4}
                            }
                        ]
                    }
                ]
            }
        ]
    }

     

  3. On 2/11/2017 at 8:51 AM, Choonster said:

    I don't think this is currently possible using the vanilla passive spawning system.

     

    When WorldEntitySpawner#findChunksForSpawning tries to spawn an entity, it calls WorldServer#canCreatureTypeSpawnHere and WorldEntitySpawner#canCreatureTypeSpawnAtLocation and only proceeds if they both return true. You can use WorldEvent.PotentialSpawns to change the result of the former, but the latter is hardcoded to check for water if the entity uses EntityLiving.SpawnPlacementType.IN_WATER and call Block#canCreatureSpawn (which calls (Block#isSideSolid with EnumFacing.UP) for any other EntityLiving.SpawnPlacementType.

     

    Lava isn't water or a solid block, so entities won't be spawned in it.

     

    I think Forge would need to add an event in WorldEntitySpawner#canCreatureTypeSpawnAtLocation to allow the result of the method to be changed.

    @Choonster Do you have any recommendations on what the event should be? I am going to try and see what I can come up with but would like to know where to start. 

  4. Hello, I have a few question about biome generation. First off can anyone help me understand how to only allow certain biomes to spawn next to each other. For example, hot by warm, warm by cool, and cool by cold. I know Vanilla does this but I do not understand it. Second, how do sub-biomes work? Thank you, all help is appreciated.

     

    Here is my current biome gen system:

     

    Registry

    https://github.com/LogicTechCorp/NetherEx/blob/71dc6f68dcdca6905617e189956b621a23d9ea0c/src/main/java/nex/init/NetherExBiomes.java

     

    GenLayers

    https://github.com/LogicTechCorp/NetherEx/blob/71dc6f68dcdca6905617e189956b621a23d9ea0c/src/main/java/nex/world/gen/layer/GenLayerAddBiomes.java

    https://github.com/LogicTechCorp/NetherEx/blob/71dc6f68dcdca6905617e189956b621a23d9ea0c/src/main/java/nex/world/gen/layer/GenLayerNether.java

  5. 9 hours ago, Choonster said:

    You're using the blocks Field twice and casting the value of the second call to List<Template.EntityInfo> instead of using the entities Field. This will throw a ClassCastException at runtime.

     

    It also looks like you're not actually using the size Field.

     

    I recommend following Java naming conventions by using CONSTANT_CASE for constant fields.

    Thanks, I didn't see that. Also, the size Field wasn't needed after all since the class has a getSize method.

  6. 1 minute ago, Choonster said:

    Use ReflectionHelper.findField or ReflectionHelper.findMethod to get a Field/Method object for the field/method and store it in a private static final field. You'll need to provide both the MCP and SRG names of the field/method.

     

    Use Field#get or Field#set to get or set the value of a field. If it's an instance field, pass the instance as the first argument. If it's a static field, pass null as the first argument instead.

     

    Use Method#invoke to call a method. If it's an instance method, pass the instance as the first argument. If it's a static method, pass null as the first argument instead. Pass the method's arguments as the vararg argument.

    Thank you! I will work on it and come back if I have any issues.

  7. I am trying to spawn a structure in the Nether. The structure is supposed to spawn in the air but it does not work correctly.

     

    Here is the code I am using:

        public boolean generate(World world, Random rand, BlockPos pos)
        {
            rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
    
            Mirror[] mirrors = Mirror.values();
            Rotation[] rotations = Rotation.values();
            Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
            Rotation rotation = rotations[rand.nextInt(rotations.length)];
            MinecraftServer server = world.getMinecraftServer();
            TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
            Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
    
            PlacementSettings settings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
            BlockPos structureSize = template.transformedSize(rotation);
            BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX(), 96, pos.getZ() - structureSize.getZ());
            BlockPos spawnPos = getSuitableAirPos(world, template.getZeroPositionWithTransform(newPos, mirror, rotation), structureSize);
    
            if(spawnPos != BlockPos.ORIGIN)
            {
                template.addBlocksToWorld(world, spawnPos, settings, 3);
                return true;
            }
            return false;
        }
    
        private static BlockPos getSuitableAirPos(World world, BlockPos pos, BlockPos structureSize)
        {
            while(pos.getY() > 32)
            {
                float sizeX = structureSize.getX();
                float sizeZ = structureSize.getZ();
                float sizeY = structureSize.getY();
    
                int airBlocks = 0;
    
                for(int x = 0; x <= sizeX; x++)
                {
                    for(int z = 0; z <= sizeZ; z++)
                    {
                        for(int y = 0; y <= sizeY; y++)
                        {
                            BlockPos newPos = pos.add(x, y, z);
    
                            if(world.getBlockState(newPos) == Blocks.AIR.getDefaultState())
                            {
                                airBlocks++;
                            }
                        }
                    }
                }
    
                if(airBlocks == sizeX * sizeY * sizeZ)
                {
                    return pos;
                }
    
                pos = pos.down();
            }
    
            return BlockPos.ORIGIN;
        }
    }

     

    My code is based off of the fossil generation code.

     

    Picture of the issue:

    2017-03-08_21.06.22.png

  8. I have an entity that plays a sound when it is moving. The entity has a cooldown between when it moves. If the sound plays right before it stops moving, the sound plays throughout the cooldown. I would like for this sound to stop playing when the entity stops moving. How do I do this?

  9. I have blocks rendering now. There are a few issues: Blocks are rendered with color on them and the tops of blocks and items are transparent.

     

    Current Code:

    public class RenderSummoningAltar extends FastTESR<TileEntitySummoningAltar>
    {
        @Override
        public void renderTileEntityFast(TileEntitySummoningAltar altar, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer vertexRenderer)
        {
            ItemStack stack = altar.getInventory().getStackInSlot(0);
    
            if(!stack.isEmpty())
            {
                World world = altar.getWorld();
                float time = (world.getTotalWorldTime() + partialTicks) / 20;
    
                IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack, world, null);
                List<BakedQuad> quads;
    
                for(EnumFacing facing : EnumFacing.values())
                {
                    quads = model.getQuads(null, facing, 0L);
    
                    for(BakedQuad quad : quads)
                    {
                        vertexRenderer.addVertexData(quad.getVertexData());
                        vertexRenderer.putPosition(x, y + 1.5D, z);
                    }
                }
    
                quads = model.getQuads(null, null, 0L);
    
                for(BakedQuad quad : quads)
                {
                    vertexRenderer.addVertexData(quad.getVertexData());
                    vertexRenderer.putPosition(x, y + 1.5D, z);
                }
            }
        }
    }

     

    2017-02-20_18.51.32.png

    2017-02-20_18.52.53.png

  10. 6 hours ago, diesieben07 said:

    Look at AnimationTESR.

    I have made some progress. Items now render but blocks do not. How would I render blocks and scale/rotate the model?

     

    Current code:

    public class RenderSummoningAltar extends FastTESR<TileEntitySummoningAltar>
    {
        @Override
        public void renderTileEntityFast(TileEntitySummoningAltar altar, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer vertexRenderer)
        {
            ItemStack stack = altar.getInventory().getStackInSlot(0);
    
            if(!stack.isEmpty())
            {
                World world = altar.getWorld();
    
                IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack, world, null);
                List<BakedQuad> quads = model.getQuads(null, null, 0L);
    
                for(BakedQuad quad : quads)
                {
                    vertexRenderer.addVertexData(quad.getVertexData());
                    vertexRenderer.putPosition(x, y + 1, z);
                }
            }
        }
    }

     

  11. I have the Item rendering but it appears dark. What am I doing wrong?

     

    public class RenderSummoningAltar extends TileEntitySpecialRenderer<TileEntitySummoningAltar>
    {
        @Override
        public void renderTileEntityAt(TileEntitySummoningAltar altar, double x, double y, double z, float partialTicks, int destroyStage)
        {
            if(altar == null)
            {
                return;
            }
    
            ItemStack stack = altar.getInventory().getStackInSlot(0);
    
            if(!stack.isEmpty())
            {
                GlStateManager.pushMatrix();
                GlStateManager.translate(x + 0.5F, y + 1.225F, z + 0.5F);
                GlStateManager.disableLighting();
    
                GlStateManager.rotate((Minecraft.getSystemTime() / 720.0F) * (180.0F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
                GlStateManager.scale(0.5F, 0.5F, 0.5F);
                GlStateManager.pushAttrib();
    
                RenderHelper.enableStandardItemLighting();
                Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
                RenderHelper.disableStandardItemLighting();
    
                GlStateManager.popAttrib();
                GlStateManager.enableLighting();
                GlStateManager.popMatrix();
            }
        }
    }

     

  12. Just now, Draco18s said:

    And you would be wrong. You can use an IModel implementation to get the Item's model and bake it into your block.

    There's a few forum threads on this already.

    The Block has a TileEntity which has an inventory and allows it to store a single item. I would like for this Item to render on top of the Block like an item renders on the ground.

×
×
  • Create New...

Important Information

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