TheXFactor117
Forge Modder-
Posts
82 -
Joined
-
Last visited
Everything posted by TheXFactor117
-
I'm looking to dynamically alter the number of monsters that are spawning in the world dependent on a few different factors, however, I can't seem to find a working solution. It seems that this might be hardcoded into the game, perhaps in WorldEntitySpawner. Essentially, my goal is to have certain custom monsters be able to spawn during the day, though ideally, monsters wouldn't be as common during the day. There are also some other factors that would go into this, though they don't pertain to the issue. I've tried adding different restrictions which would either stop the entity from spawning in its canSpawnHere method or canceling a spawning event. The is only prolongs the time it takes for Minecraft to spawn what appears to be the max cap of entities that can spawn around the player (which looks like it gets set to 70 for entities of the monster type). Regardless of my checks and restrictions, eventually there will be the same amount of monsters spawned as their typically would be at night. If anyone knows of a way to limit this that I have perhaps looked over, I would appreciate that. To me, it looks like it's hardcoded into the game, but maybe there is a way.
-
Use Minecraft's Structure Blocks to save a structure to NBT, which you can then use in code to load the structure. Create a new Template instance with the resource location of your structure.nbt file, and call Template#addBlocksToWorld to spawn the structure. You can do this in your WorldGenerator class.
- 1 reply
-
- 5
-
You didn't read what I said earlier.
-
Without looking at your code, I'd imagine it's an issue with naming. In your IDE, uppercase/lowercase doesn't necessarily matter, so you'll have textures fine in your IDE. But once you build it, names of items or textures need to be lowercase. If you have upper case names, it won't load properly. If you do have lowercase names and such, than you know the issue is elsewhere. Post your code to GitHub too - not everyone is going to download a random zip file.
-
Well it is pretty easy actually. You do everything the algorithm normally would but you don't place any blocks and you store the position and individual structure into a map or whatever. Whenever new chunks are generated, you check to see if your positions of the structures are in it and you generate if so. Seems to make since to me, so I'll try and implement this soon. I think Minecraft does this by checking if a given structure is inside of the bounding box of the chunk, and if so, it generates. So that's the kinda check you would need.
-
Potential solution: When I go to generate the dungeon, instead of building each individual room during generation, I'm thinking I can just generate the positions of each individual structure and store the position and template into a map. If the bounding box of the structure intersects with the current chunk (which has an offset), generate the corresponding room. If it's outside of the currently generated chunks, it won't generate. As new chunks are generated through the WorldGenerator, I'm thinking about looping through all the pending structures, checking to see if the bounding box of the structure intersects with the current chunk and if it does, generate it and remove it from the map. I'm not sure if this will work properly, so if anyone happens to find a flaw in it, I'd like to hear it before I try and implement it. If it sounds good, I'll work on implementing it.
-
I don't think that's the best solution, at least in terms of what I'm trying to do. I've been digging around in vanilla world generation (Stronghold/Village generation) to figure out how they generate structures without causing runaway chunk generation. It looks like vanilla generation (say a Stronghold) will generate the positions of the Stronghold and store them somehow (MapGenStronghold#generatePositions looks like it does this, but I don't see how this works fully). Somehow the Stronghold's StructureStart gets a list of components to be generated and builds them out. Anyways, I think my conclusion is vanilla world generation is a mess and is hard to trace and track down how everything works. As for how to fix this, I'm thinking the easiest thing is to generate a "virtual" dungeon through the algorithm, but not to build anything during this time and storing each structure in a map. Then I would generate it when chunks are loaded and everything is ok for it to generate. The problem is, how would I go about generating it this way? Is it even possible?
-
In one of my projects, I have a simple procedurally generating dungeon algorithm which generates the mod's dungeons. I've recently decided to rewrite to be more complex and accommodate more features than before. Before I do this though, I wanted to generate it in a way that it won't cause cascading world generation, which the current algorithm doesn't prevent. Right now it works kind of like this: I'll generate a structure on the surface somewhere, which will spawn staircases underneath it. From there, rooms can branch off of these staircases, and each room can generate new rooms off of it and so on until it reaches the maximum amount of "tries". This is done through recursion which is simple enough to do. So I've been trying to come up with a way to prevent the cascading generation from happening because it's not as simple as just adding an offset. I won't know how many chunks the dungeon will take up until after I generate it. I'm wondering about what the easiest solution to this would be. Could I generate all of the parts of the structure that are in loaded chunks only and then generate the others once those chunks have been loaded? I think that's the fundamental solution but how would you go about knowing/storing where a structure should be, and then generating that structure when the chunk is loaded? Maybe this isn't entirely right and there is another way around it, I'm not sure. Anyways, any help on solving this issue would be much appreciated.
-
LivingHurtEvent perhaps?
-
Check to see if the modifier is applied - if not, apply it, else, don't. Remove it in the onUnequipped method.
-
Yes, that should work.
-
Use AttributeModifiers to modify the damage. This won't work for bows so you'll have to find a workaround (unless bow damage is influenced by the players attack damage which I don't think it is).
-
[1.12] Generated structure from template is empty
TheXFactor117 replied to Zerom69's topic in Modder Support
Your ResourceLocation doesn't need structures in the path name (unless you made a second structures package). You also don't need to include .nbt at the end of the name. Try that and see what happens. -
[1.12] Generated structure from template is empty
TheXFactor117 replied to Zerom69's topic in Modder Support
What are your outputs? Does it fail to generate? Is the position spit out in the console? -
I am trying to store data on a player and have this data manipulated by mainhand weapons, armor, and stuff like that. The issue I'm trying to tackle is updating this information when these items change and such. Originally I was thinking of updating this information in a player tick event - check to see if the item held/worn is the right type and has the right data, take this data and add it to the player's data. If the item changes, remove it. All of this in a tick event is kinda tricky to handle but is doable. So I started to look into other ways of handling this, and I figured Attributes work similar to how I want to handle this. When you hold a sword, damage goes up and speed goes down when in your mainhand. But this would require making a new attribute for the player and item, and looking into that, people have said that making attributes for a player isn't the right way to handle it. Is the case all the time in that you should always save data in a capability, or is it possible in this case? To explain what I'm trying to do if it helps, every player has a set of stats. Some weapons have these stats too. When you are using a weapon/wearing armor that has one of these stats, I need to update the information in the player to get the correct totals. Edit: I just worked this up and it works like I want - might not be the most efficient way of doing things. private int ticks; private ItemStack mainhand; private ItemStack helmet; private ItemStack chestplate; private ItemStack leggings; private ItemStack boots; /* Called ever second to check for slots and update stat bonuses. Might need to be re-worked. */ @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { if (event.phase == Phase.START && !event.player.getEntityWorld().isRemote) { if (ticks % 20 == 0) { IPlayerInformation playerInfo = event.player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null); if (playerInfo != null) { if (event.player.inventory.getCurrentItem() != mainhand) { updateStats(event.player, playerInfo); mainhand = event.player.inventory.getCurrentItem(); } for (ItemStack stack : event.player.inventory.armorInventory) { if (stack.getItem() instanceof ItemArmor) { if (((ItemArmor) stack.getItem()).getEquipmentSlot() == EntityEquipmentSlot.HEAD && stack != helmet) { updateStats(event.player, playerInfo); helmet = stack; } else if (((ItemArmor) stack.getItem()).getEquipmentSlot() == EntityEquipmentSlot.CHEST && stack != chestplate) { updateStats(event.player, playerInfo); chestplate = stack; } else if (((ItemArmor) stack.getItem()).getEquipmentSlot() == EntityEquipmentSlot.LEGS && stack != leggings) { updateStats(event.player, playerInfo); leggings = stack; } else if (((ItemArmor) stack.getItem()).getEquipmentSlot() == EntityEquipmentSlot.FEET && stack != boots) { updateStats(event.player, playerInfo); boots = stack; } } } } ticks = 0; } ticks++; } } private void updateStats(EntityPlayer player, IPlayerInformation info) { info.removeBonusStats(); if (player.inventory.getCurrentItem().getItem() instanceof ItemSword) { NBTTagCompound nbt = NBTHelper.loadStackNBT(player.inventory.getCurrentItem()); if (WeaponAttribute.STRENGTH.hasAttribute(nbt)) info.setBonusStrengthStat(info.getBonusStrengthStat() + (int) WeaponAttribute.STRENGTH.getAmount(nbt)); if (WeaponAttribute.AGILITY.hasAttribute(nbt)) info.setBonusAgilityStat(info.getBonusAgilityStat() + (int) WeaponAttribute.AGILITY.getAmount(nbt)); if (WeaponAttribute.DEXTERITY.hasAttribute(nbt)) info.setBonusDexterityStat(info.getBonusDexterityStat() + (int) WeaponAttribute.DEXTERITY.getAmount(nbt)); if (WeaponAttribute.INTELLIGENCE.hasAttribute(nbt)) info.setBonusIntelligenceStat(info.getBonusIntelligenceStat() + (int) WeaponAttribute.INTELLIGENCE.getAmount(nbt)); if (WeaponAttribute.WISDOM.hasAttribute(nbt)) info.setBonusWisdomStat(info.getBonusWisdomStat() + (int) WeaponAttribute.WISDOM.getAmount(nbt)); if (WeaponAttribute.FORTITUDE.hasAttribute(nbt)) info.setBonusFortitudeStat(info.getBonusFortitudeStat() + (int) WeaponAttribute.FORTITUDE.getAmount(nbt)); } for (ItemStack stack : player.inventory.armorInventory) { NBTTagCompound nbt = NBTHelper.loadStackNBT(stack); if (ArmorAttribute.STRENGTH.hasAttribute(nbt)) info.setBonusStrengthStat(info.getBonusStrengthStat() + (int) ArmorAttribute.STRENGTH.getAmount(nbt)); if (ArmorAttribute.AGILITY.hasAttribute(nbt)) info.setBonusAgilityStat(info.getBonusAgilityStat() + (int) ArmorAttribute.AGILITY.getAmount(nbt)); if (ArmorAttribute.DEXTERITY.hasAttribute(nbt)) info.setBonusDexterityStat(info.getBonusDexterityStat() + (int) ArmorAttribute.DEXTERITY.getAmount(nbt)); if (ArmorAttribute.INTELLIGENCE.hasAttribute(nbt)) info.setBonusIntelligenceStat(info.getBonusIntelligenceStat() + (int) ArmorAttribute.INTELLIGENCE.getAmount(nbt)); if (ArmorAttribute.WISDOM.hasAttribute(nbt)) info.setBonusWisdomStat(info.getBonusWisdomStat() + (int) ArmorAttribute.WISDOM.getAmount(nbt)); if (ArmorAttribute.FORTITUDE.hasAttribute(nbt)) info.setBonusFortitudeStat(info.getBonusFortitudeStat() + (int) ArmorAttribute.FORTITUDE.getAmount(nbt)); } LostEclipse.network.sendTo(new PacketUpdatePlayerStats(info), (EntityPlayerMP) player); }
-
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
When saving your structure, place a monster spawner (the default one) and place a data block on top of it and name it like monster_spawner or something. When you add the blocks to the world, you can call a method which will handle the data blocks. Here is my method for handling data blocks for an example. Essentially you just need to loop through all data blocks in the structure - if the data block name matches the one you are looking for, you can do stuff with the block underneath. For example in my structures, I'm setting the loot table for the chest. For monster spawners, you can get an instance of the Tile Entity and modify it there. After you are done modifying it, simply set the data block to an air block or whatever block you want (or else it'll spawn a random block based on where it is located). -
[1.12] [Solved] Generating Structures with nbt files
TheXFactor117 replied to GooberGunter's topic in Modder Support
As I said in the other thread, you need to create a Template variable. It takes a TemplateManager (which you can get from WorldServer) and a ResourceLocation for your NBT file (and maybe a couple other parameters). Once you have this, just call the addBlocksToWorld method when you want to generate the structure. I have an example here, though this is kinda complicated code. Just look for Templates in it and it should give you an idea. -
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
It's there for a reason - it's just as easy to spawn multiple structures in next to each other too. -
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
You don't need a structure class. Create a Template variable which loads your NBT file through a ResourceLocation. Once you have a template, just call addBlocksToWorld or whatever the method is called. -
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
Yes, I believe structure blocks were added in 1.10. As for randomization, what exactly do you want randomized? One draw back of loading from NBT that I found is you can't change the blocks that are saved in the NBT. I haven't looked into it too much though, so there might be a way. You can use Data Blocks to put on top of chests or other important blocks to load loot tables for example too. -
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
Yes - instead of having a bunch of setBlockState calls specifying every single block in your structure, you can load your structure from NBT in a very few lines of code. Just call the template method to set the blocks in the world in your WorldGenerator class. -
[1.11.2] How to generate structures bigger than a chunk
TheXFactor117 replied to GooberGunter's topic in Modder Support
Use Structure Blocks. You can look at Igloos and newer Minecraft structures for example. Basically, all you need to do is build your structure, save it to NBT using Structure Blocks, and load it in through a Template. If you want a structure bigger than 32x32, you can make multiple Structure Blocks and when you spawn the structure in you can the multiple files in and just offset positions depending on the piece. I have some code on my GitHub as well using Structure Blocks. -
I got it working now - though one thing isn't working properly and it's the fact that the NBT data isn't actually saving properly. I have a helper method which creates the data and adds it to the stack which gets called properly from within my function. However, this data doesn't actually make it for whatever reason because the tooltip doesn't display anything and the NBT doesn't actually have any of the data. The data gets saved on the server - outputs, when it's in your inventory, show no data is on it, also on the server. I looked into the SetNBT function and they essentially create a new NBTTagCompound and merge it with the existing (if it's available). Though that doesn't really help. I don't really know what's happening or how to fix it so any insight would be helpful. I've fixed everything now - my helper method for loading/saving NBT compounds wasn't working properly. Thanks for all the help!
-
I'll mess with this when I get a chance. Just to make sure I'm understanding this correctly, when I load my own loot table, I need to create a new instance of my own LootTable class? I didn't really understand what you meant be check for that class in your pools - I'm assuming if a loot table is loaded as an instance of my LootTable class, it'll use my own LootContext which can store the chest position. I just need to make sure I'm loading everything properly because obviously I'm doing something wrong.