Jump to content

Tut

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by Tut

  1. Slight update - I had a bug in my code that caused minecraft to hang. Pretty sure directly registering it with Registry.register would have worked; but my question of how to do it the "right" way still stands. Right now the access transformer works as intended.
  2. I see now Astral is able to do that since they use an access transformer for that function. https://github.com/HellFirePvP/AstralSorcery/blob/e8434f1a09356632babefee1925626dc3deefb2a/src/main/resources/META-INF/accesstransformer.cfg#L12 Is that the only way to do this?
  3. Hi, I'm trying to register a new LootFunction to use in my loot table data generator. I was loosely basing it off of Astral Sorcery's loot table data generators, since I'm trying to achieve a similar effect. Here's my loot table provider: package org.tutmods.shungite.data; import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Pair; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.data.DataGenerator; import net.minecraft.data.LootTableProvider; import net.minecraft.data.loot.BlockLootTables; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.loot.ItemLootEntry; import net.minecraft.loot.LootParameterSet; import net.minecraft.loot.LootParameterSets; import net.minecraft.loot.LootPool; import net.minecraft.loot.LootTable; import net.minecraft.loot.LootTableManager; import net.minecraft.loot.RandomValueRange; import net.minecraft.loot.ValidationTracker; import net.minecraft.loot.functions.ApplyBonus; import net.minecraft.loot.functions.ExplosionDecay; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.RegistryObject; import org.tutmods.shungite.loot.ShungiteCrystalPropertiesLoot; import org.tutmods.shungite.setup.ModBlocks; import org.tutmods.shungite.setup.ModItems; import org.tutmods.shungite.setup.Registration; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; public class ModLootTableProvider extends LootTableProvider { public ModLootTableProvider(DataGenerator generator) { super(generator); } @Override protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootParameterSet>> getTables() { return ImmutableList.of(Pair.of(ModBlockLootTables::new, LootParameterSets.BLOCK)); } @Override protected void validate(Map<ResourceLocation, LootTable> map, ValidationTracker validationtracker) { map.forEach( (one, two) -> LootTableManager.validate(validationtracker, one, two)); } public static class ModBlockLootTables extends BlockLootTables { @Override protected void addTables() { this.add(ModBlocks.SHUNGITE_CRYSTAL_ORE.get(), (block) -> LootTable.lootTable() .withPool(LootPool.lootPool() .setRolls(RandomValueRange.between(2F, 5F)) .add(ItemLootEntry.lootTableItem(ModItems.SHUNGITE.get()) .apply(ExplosionDecay.explosionDecay()) .apply(ShungiteCrystalPropertiesLoot.builder())) )); } @Override protected Iterable<Block> getKnownBlocks() { return Registration.BLOCK_DEFERRED_REGISTER.getEntries() .stream().map(RegistryObject::get).collect(Collectors.toList()); } } } And the loot function I want to add: package org.tutmods.shungite.loot; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import net.minecraft.item.ItemStack; import net.minecraft.loot.LootContext; import net.minecraft.loot.LootFunction; import net.minecraft.loot.LootFunctionType; import net.minecraft.loot.conditions.ILootCondition; import org.tutmods.shungite.items.crystal.ShungiteCrystal; import org.tutmods.shungite.items.crystal.properties.ShungiteCrystalProperties; import org.tutmods.shungite.util.crystal.CrystalUtils; public class ShungiteCrystalPropertiesLoot extends LootFunction { protected ShungiteCrystalPropertiesLoot(ILootCondition[] conditions) { super(conditions); } @Override protected ItemStack run(ItemStack stack, LootContext lootContext) { if (stack.getItem() instanceof ShungiteCrystal) { final ShungiteCrystalProperties properties = CrystalPropertyGenerator.getRandomNewCrystalProperties(); CrystalUtils.putProperties(stack, properties); } return stack; } public static LootFunction.Builder<?> builder() { return simpleBuilder(ShungiteCrystalPropertiesLoot::new); } @Override public LootFunctionType getType() { return Functions.ShungiteCrystalsLoot; } public static class Functions { public static LootFunctionType ShungiteCrystalsLoot; } public static class Serializer extends LootFunction.Serializer<ShungiteCrystalPropertiesLoot> { @Override public ShungiteCrystalPropertiesLoot deserialize(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext, ILootCondition[] iLootConditions) { return new ShungiteCrystalPropertiesLoot(iLootConditions); } } } I see Astral doing similar things here: https://github.com/HellFirePvP/AstralSorcery/blob/1.16-indev/src/main/java/hellfirepvp/astralsorcery/common/loot/RandomCrystalProperty.java https://github.com/HellFirePvP/AstralSorcery/blob/e8434f1a09356632babefee1925626dc3deefb2a/src/main/java/hellfirepvp/astralsorcery/datagen/data/loot/BlockLootTableProvider.java#L77 However, my trouble comes when running the data generator. I can't register the serializer as Astral does here https://github.com/HellFirePvP/AstralSorcery/blob/e8434f1a09356632babefee1925626dc3deefb2a/src/main/java/hellfirepvp/astralsorcery/common/registry/RegistryLoot.java#L49, since LootFunctionManager.register is private. Is there a new way of doing this? I tried just calling Registry.register as LootFunctionManager.register does itself, and I was able to generate JSON with that, however my game hung as soon as I broke the block; so I assume I'm doing something wrong. I saw there's a new DeferredRegister for LootModifiers, but I'm not sure if that fulfills the same role as a LootFunction? So I guess I have two questions: How do I register my serializer for my LootFunction correctly? What's the difference between a LootFunction and a LootModifier?
  4. I guess I was just confused as to how things were getting handled when something is updated on the server. Not sure how I didn't see it before, thanks all.
  5. I see the issue. But I'm not sure why being on the server means the client isn't being updated, if the setBlock event should update the client?
  6. Here's the whole class. public class ShungiteDowsingRod extends Item implements IForgeItem { public ShungiteDowsingRod(Properties properties) { super(properties); } @Override public ActionResultType useOn(ItemUseContext itemUseContext) { final World world = itemUseContext.getLevel(); if (!world.isClientSide()) { final Stream<BlockPos> blocksBetweenPlayerLookingAndDowsingEffect = BlockPos.betweenClosedStream( WorldHelper.getAABBInDirectionWithOffset( itemUseContext.getClickedPos(), itemUseContext.getClickedFace(), 0, 1, 1 ) ); blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> { world.setBlock(blockPos, Blocks.CYAN_WOOL.defaultBlockState(), ( Constants.BlockFlags.DEFAULT_AND_RERENDER ) ); }); } return super.useOn(itemUseContext); } }
  7. Thank you for letting me know! Unfortunately still having issues. I'm not sure why this code isn't working.. blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> { world.setBlock(blockPos, Blocks.CYAN_WOOL.defaultBlockState(), ( Constants.BlockFlags.DEFAULT_AND_RERENDER ) ); }); Here's an example of the behavior I'm experiencing.. https://files.catbox.moe/z4ov1m.m4v
  8. setBlockAndUpdate uses flag 3, but I've tried 1, 2, and 4 with no success. Is there any documentation on what these flags do? I found this thread but since I'm using the mojang mappings I don't think I have the same javadocs.
  9. Hi, I have an AABB that I want to set all of the blocks in to a different block. final Stream<BlockPos> blocksBetweenPlayerLookingAndDowsingEffect = BlockPos.betweenClosedStream( WorldHelper.getAABBInDirectionWithOffset( itemUseContext.getClickedPos(), itemUseContext.getClickedFace(), 0, 1, 1 ) ); blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> { world.setBlockAndUpdate(blockPos, Blocks.CYAN_WOOL.defaultBlockState()); }); I think there were different names for both of betweenClosedStream and setBlockAndUpdate in the MCP mappings. So it's been hard to find exactly the fix I'm looking for. The problem I'm facing now is that when I call setBlockAndUpdate, only the first clicked on block updates. The rest don't update until I restart the world. I assume this has something to do with being used in a stream, or the flag that's used on setBlock? I'm not entirely sure. Thanks!
  10. Alright, one more question now that I've realized my issues. If I want to set the inventory of any TileEntity, I can do it straight from HuskItem's method? Are there any examples I can look at where syncing the inventory between client and server is necessary then? I think I'm just confused about when and where to use packets, I guess.
  11. Holy shit I'm dumb. This is what I get for copy/pasting. Edit: Will do what you said as well. I can't believe that I haven't seen that though.
  12. Alright, rebuilt how the item works now. I think it's much better this time around, but I'm having a strange crash. Is there some sort of limit on what I can write / read from the buffer? Or am I still doing something wrong and dumb? The code in the main post has been updated to the newest version. Crash log:
  13. Ah. I'm really dumb. Got logical and physical confused. Thanks for making me not dumb.
  14. Ok, I understand the last two points. However, I'm not sure how I would be on the server when I send the packet. I could be thinking about it all wrong, but from what I understand I am sending the packet on line 103 of the HuskItem class. How could I be on the server when I send the packet? Once again, I'm probably wrong here but FMLCommonHandler.getSide() returns that (when I'm sending the packet) I'm calling it from the client. Am I seeing something the wrong way?
  15. I just don't know why it's null. Is there something within Java that I just don't understand here? Edit: I think I got it. Trying some stuff now.
  16. I'm having some trouble with the fromBytes method when I'm implementing my own packet. The packet is supposed to combine two chest's inventories into one. Here's the code. Specifically, my issue regards line 43 of the tutmodMessage class. I'm getting a NullPointerException when accessing the newList List, and I'm not sure why. The toBytes method works completely fine, and the HuskItem class has nothing that would clear the newlist List before the fromByte method would access it. Weird part is, that line of code worked before I implemented a large part of code in the handle() method. The previous working code can be seen here. (the array of chestPos and the for loop in fromBytes should be 3 in length. I was still figuring out how I was going to clear the chest contents.) Here's the crash log as well. Am I just not understanding how the implementation of iMessage works? Or is something wrong in my constructor? Am I doing the whole reading and writing from the buffer wrong? Still trying to grasp how to use custom packets. Feel free to tell me other things I'm doing wrong. Thanks!
  17. Alright. Seems to have fixed my issue. One more question: Since it seems that the code from the Message is actually performed on the server after the OnItemUseFirst method is completed, should I just move the ClearChestStorage functionality to the Message class? The code was working before I made the Message class but it doesn't work afterward, and even so, I feel like it would be reaching across sides. Am I correct in assuming this or would I just be doing too much computation in the handle method? Edit: Forgot to say thanks for the help!
  18. I'm not sure. Like I said, I'm not exactly sure how I would accomplish what I'm looking to do. I get now that it's where you would actually send the data, I'm just lost on how you would turn the three variables that I'm using to store information into a usable format for the buf.
  19. With this item, I'm trying to combine two chest's inventories into one list, then put both lists into a chest. I know that this code is probably very, very wrong. I have a moderate understanding of Java, but at this point, I'm basically just praying that someone else has had the same issues as me, I barely passed my APCS exam last year. I know this has a lot of bad coding practice, and I'm a bit embarrassed to show it, but here's a git repo with the working code that I have so far. (I know I set it up wrong too. I'm working on one thing at a time. ) Specifically, the issue is on line 104 of the HuskItem class. tutmodPacketHandler.INSTANCE.sendToServer(new tutmodMessage(locatedChest, newlist, airList)); I've tried so many things to deposit the itemstacks in the newlist List into the chest. I've tried some different solutions, but nothing I've done will get the items to appear in the Chest. I'm not sure if it's just really bad logic on my part because my code is so bad, or if I'm using something wrong. I'm not even sure if I got the sending and receiving of packets right. I'll work on the other issues after I get this one fixed, I'd just like to know how I can take the itemstacks from the newlist List and deposit them into locatedChest. I'd like as much help as one can give - I know I did a lot wrong. Just trying to learn, after all. Thank you!
  20. Ah, okay. I was specifically talking about defining a mod item, wasn't sure how to do that, sorry!
  21. I'm attempting to use the well-known "Coordinate Cache" item to assign NBT values to another item. Here's the Coordinate Cache item Class: package com.example.ubiquity.items; import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class SwordCache extends Item{ @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if(!playerIn.isSneaking()){ if(stack.getTagCompound() == null ){ stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound posnbt = new NBTTagCompound(); posnbt.setInteger("posX", pos.getX()); posnbt.setInteger("posY", pos.getY()); posnbt.setInteger("posZ", pos.getZ()); stack.getTagCompound().setTag("coords", posnbt); stack.setStackDisplayName(EnumChatFormatting.GOLD + "Ubiquitous Link"); }return true; } @Override public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn){ if (playerIn.isSneaking()){ if(stack.getTagCompound() != null){ stack.getTagCompound().removeTag("coords"); stack.clearCustomName(); } } return stack; } @Override @SideOnly(Side.CLIENT) @SuppressWarnings("unchecked") public void addInformation(ItemStack stack, EntityPlayer playerIn, List list, boolean advanced){ if(stack.getTagCompound() != null){ if(stack.getTagCompound().hasKey("coords")){ NBTTagCompound posnbt = (NBTTagCompound) stack.getTagCompound().getTag("coords"); int posX = posnbt.getInteger("posX"); int posY = posnbt.getInteger("posY"); int posZ = posnbt.getInteger("posZ"); list.add("This item is bound to"); list.add("X: " + posX + " Y: " + posY + " Z: " + posZ); } } } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack){ NBTTagCompound nbtTagCompound = stack.getTagCompound(); if(nbtTagCompound != null){ return stack.getTagCompound().hasKey("coords"); } return stack.isItemEnchanted(); } } My question is about this line in the OnItemUse method... if(!playerIn.isSneaking()){ How can I change this to see if the player has another item, called "Coordinate Key", and then store the following NBT information in said item?
×
×
  • Create New...

Important Information

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