Jump to content

squidlex

Members
  • Posts

    183
  • Joined

  • Last visited

Posts posted by squidlex

  1. Sorry, I should have been more clear.

    I am checking my field on the client side in an interaction result, where if they are their default value of -1 I randomly generate a new value:

    	@Override
    	public InteractionResult interactAt(Player player, Vec3 position, InteractionHand hand) {
    		if (level.isClientSide()) {
    			if(this.nameId < 0) {
    			this.nameId = level.random.nextInt(10);
    		}
    			GuiWrapper.openGUI(level, player, this);
    			System.out.println("Client: " + this.nameId); // I know this is inefficient but just for testing purposes
    		} 
    		
    		return super.interactAt(player, position, hand);
    	}

    And here is the field:

    	private int nameId = -1;

    The issue is that every time I close and open the world, they reset to -1 and a new value is generated.

  2. Thanks for the tip! I've now got:

    	@Override
    	public void readAdditionalSaveData(CompoundTag pCompound) {
    		super.readAdditionalSaveData(pCompound);
    		this.nameId = pCompound.getInt("nameId");
    	}
    	
    	@Override
    	public void addAdditionalSaveData(CompoundTag pCompound) {
    		super.addAdditionalSaveData(pCompound);
    		pCompound.putInt("nameId", this.nameId);
    	}

    but this is not saving correctly. Do I need to call these methods myself?

  3. Thank you for your help! I'm only using the accessors for my own Entity and I'm implementing INBTSerializable in my provider so this shouldn't cause any issues.

    I'm trying to access my capability in my Entity's constructor but it isn't working, however it works if I try to access it in another method such as interactAt(). Do you know if there is a way I can access my attached capability when my entity is being constructed? Thanks again.

     

  4. I was wondering what the best way to store persistent data in an entity is.

    Right now, I'm attaching a custom capability to my entity and attempting to store the capability's data in EntityDataAccessors  every time the Entity is constructed.

    This isn't working, and I was wondering if there was a better way of doing this?

    Thank you!

     

    Edit: By non-volatile I mean saves the data to the specific instance of the entity even when the game is restarted

  5. 2 hours ago, diesieben07 said:

    You need to call generateFile (not sure why you named it like that) whenever you want access to your data. You do not need WorldEvent.Save or WorldEvent.Load.

    I see, thank you! It was called that because I was misunderstanding the method's purpose.

    It now works, thanks :)

  6. 1 hour ago, diesieben07 said:

    Create fields in your class holding the data you want to save. In your case an integer. Then you need to save the data to the provided CompoundTag in the save method. Your load, create and generateFile methods need to be static. In load you then load the data and apply it to the newly created instance.

    Whenever you change anything about the data you need to call setDirty, so that Minecraft knows your data needs saving.

    Thank you for your help! Sorry to trouble you, but there's a couple things I still don't understand.

    Here's my updated class:

    import net.minecraft.nbt.CompoundTag;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.world.level.saveddata.SavedData;
    
    public class FactionSavedData extends SavedData {
    	
    	private int test = 2;
    
    	public int getTest() {
    		return this.test;
    	}
    
    	public void setTest(int test) {
    		this.test = test;
    		this.setDirty();
    	}
    
    	public static FactionSavedData create() {
    		return new FactionSavedData();
    	}
    	
    	public static FactionSavedData load(CompoundTag tag) {
    		FactionSavedData data = create();
    		int testInt = tag.getInt("test");
    		data.test = testInt;
    		return data;
    	}
    
    	public CompoundTag save(CompoundTag tag) {
    		tag.putInt("test", test);
    		return tag;
    	}
    
    	public static void generateFile(MinecraftServer server) {
    		server.overworld().getDataStorage().computeIfAbsent(FactionSavedData::load, FactionSavedData::create, "faction");
    	}
    	
    }

    I'm not sure if the first parameter of tag.putInt() is an identifying factor that I can set as anything or if it has to be a numerical Id.

    From here I'm not sure when to run the generateFile method, right now I'm doing it here which is most likely incorrect:

    @Mod.EventBusSubscriber(modid = Minetopia.MODID, bus = Bus.FORGE)
    public class DataStorageEvents {
    
    	@SubscribeEvent
    	public static void worldSave(WorldEvent.Save event) {
    		FactionSavedData.generateFile(event.getWorld().getServer());
    	}
    	
    	@SubscribeEvent
    	public static void worldLoad(WorldEvent.Load event) {
    		
    	}
    	
    }

    and I'm trying to access my saved data as such as I'm not sure what to pass into the load method:

    CompoundTag tag = new CompoundTag();
    FactionSavedData test = FactionSavedData.load(tag);
    int testInt = test.getTest();

     

  7. I am following the read the docs article here but am struggling to get my head around it.

    Quote

    Each SD implementation must subtype the WorldSavedData class.

    I'm replacing it with the SavedData class which I believe is what I'm after.

    Here's my class so far:

    import net.minecraft.nbt.CompoundTag;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.world.level.saveddata.SavedData;
    
    public class FactionSavedData extends SavedData {
    
    	public FactionSavedData create() {
    		return new FactionSavedData();
    
    	}
    	
    	public FactionSavedData load(CompoundTag tag) {
    		FactionSavedData data = this.create();
    		return data;
    	}
    
    	@Override
    	public CompoundTag save(CompoundTag tag) {
    		return tag;
    	}
    
    	public void generateFile(MinecraftServer server) {
    		server.overworld().getDataStorage().computeIfAbsent(this::load, this::create, "faction");
    	}
    	
    }

    My issue is that I'm not sure how to actually save and load data using this class. For example, say I wanted to save and load an integer value to the overworld.

    Thank you for your help!

  8. Hi there!

    I was wondering if it's possible to temporarily rotate the player's camera, and if so where to start?

    By this I don't mean turning the player, but as in rotating the camera around the center point of the screen, as such that a 180 degrees turn would have the sky in the bottom half and blocks in the top half of the monitor.

     

    Thanks for your help!

  9. Hi there!

    I'm currently trying to stop the player from sprinting using:

    event.player.setSprinting(false);

    in the PlayerTickEvent event. This works for double tapping w, however the player can still sprint by holding Left-Control.

     

    Here is my full Class for reference:

    package com.elenai.elenaihardcore.event;
    
    import com.elenai.elenaidodge2.api.FeathersHelper;
    import com.elenai.elenaihardcore.capability.sprint.SprintProvider;
    
    import net.minecraft.entity.player.ServerPlayerEntity;
    import net.minecraftforge.event.TickEvent;
    import net.minecraftforge.event.TickEvent.PlayerTickEvent;
    import net.minecraftforge.eventbus.api.SubscribeEvent;
    
    public class PlayerEventListener {
    
    	@SubscribeEvent
    	public void playerEventListener(PlayerTickEvent event) {
    		if (event.side.isServer() && event.phase == TickEvent.Phase.START) {
    			event.player.getCapability(SprintProvider.SPRINT_CAP).ifPresent(s -> {
    				if (event.player.isSprinting()) {
    					s.increase(4);
    				}
    			});
    
    			if (FeathersHelper.getFeatherLevel((ServerPlayerEntity) event.player) <= 0) {
    				event.player.setSprinting(false);
    			}
    			
    			event.player.getCapability(SprintProvider.SPRINT_CAP).ifPresent(s -> {
    				if (s.getSprint() >= 20) {
    					s.set(0);
    					FeathersHelper.decreaseFeathers((ServerPlayerEntity) event.player, 1);
    				}
    			});
    		}
    
    	}
    
    }

    ^ I have also tested this without the if conditions or capabilities and it still doesn't work. How would I be able to completely prevent the player from sprinting?

     

    Thanks for your help!

     

  10. Hi!

    I am creating my potion recipes using the BrewingRecipeRegistry.addRecipe() method however I am experiencing some overwriting issues in-game.

    Here is my code:

    BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FEATHERS)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FEATHERS));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FEATHERS)),
    				Ingredient.fromStacks(new ItemStack(Items.GLOWSTONE_DUST)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_FEATHERS));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.AWKWARD)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),FEATHERS));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.THICK)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_FEATHERS));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.MUNDANE)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FEATHERS));
    		
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), ENDURANCE)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_ENDURANCE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), ENDURANCE)),
    				Ingredient.fromStacks(new ItemStack(Items.GLOWSTONE_DUST)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_ENDURANCE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.AWKWARD)),
    				Ingredient.fromStacks(new ItemStack(ItemList.IRON_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),ENDURANCE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.THICK)),
    				Ingredient.fromStacks(new ItemStack(ItemList.IRON_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_ENDURANCE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.MUNDANE)),
    				Ingredient.fromStacks(new ItemStack(ItemList.IRON_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_ENDURANCE));
    		
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), ENDURANCE)),
    				Ingredient.fromStacks(new ItemStack(Items.FERMENTED_SPIDER_EYE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),WEIGHT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), STRONG_ENDURANCE)),
    				Ingredient.fromStacks(new ItemStack(Items.FERMENTED_SPIDER_EYE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_WEIGHT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), LONG_ENDURANCE)),
    				Ingredient.fromStacks(new ItemStack(Items.FERMENTED_SPIDER_EYE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_WEIGHT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), WEIGHT)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_WEIGHT));
    		
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.SWIFTNESS)),
    				Ingredient.fromStacks(new ItemStack(Items.FEATHER)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),FORCEFUL));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.LONG_SWIFTNESS)),
    				Ingredient.fromStacks(new ItemStack(Items.FEATHER)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FORCEFUL));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.STRONG_SWIFTNESS)),
    				Ingredient.fromStacks(new ItemStack(Items.FEATHER)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_FORCEFUL));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FORCEFUL)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FORCEFUL));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FORCEFUL)),
    				Ingredient.fromStacks(new ItemStack(Items.GLOWSTONE_DUST)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_FORCEFUL));
    		
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.SLOWNESS)),
    				Ingredient.fromStacks(new ItemStack(Items.FEATHER)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),FEEBLE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.LONG_SLOWNESS)),
    				Ingredient.fromStacks(new ItemStack(Items.FEATHER)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FEEBLE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FEEBLE)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_FEEBLE));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), FEEBLE)),
    				Ingredient.fromStacks(new ItemStack(Items.GLOWSTONE_DUST)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_FEEBLE));
    
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.REGENERATION)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),REPLENISHMENT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.LONG_REGENERATION)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_REPLENISHMENT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.STRONG_REGENERATION)),
    				Ingredient.fromStacks(new ItemStack(ItemList.GOLDEN_FEATHER.get())), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_REPLENISHMENT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), REPLENISHMENT)),
    				Ingredient.fromStacks(new ItemStack(Items.REDSTONE)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),LONG_REPLENISHMENT));
    		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), REPLENISHMENT)),
    				Ingredient.fromStacks(new ItemStack(Items.GLOWSTONE_DUST)), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION),STRONG_REPLENISHMENT));
    		

    For whatever reason, almost all of my potion effects are being overwritten by the 'feathery' potion at the top. Examples of this include upgrading an endurance potion to long or strong, or updating a weight potion to long or strong. An example of what I mean by this is that when using the recipe for say, 'long_endurance', 'feathery' is being produced instead.

    I think I may be understanding how this method works, so any help would be greatly appreciated!

  11. Hi there!

     

    I have a mod that stores values inside the player as Capabilities and am thinking of switching over to using attributes instead.

    It currently stores integer values for weight, stamina and stamina regeneration for each player, which are accessed on both the Client and Server frequently for GUI and Logic.

     

    I'm not too familiar on the attributes system so if anyone has the time to answer these questions I would really appreciate it!

     

    1. Is it worth switching from Capabilities to Attributes for these values?
    2. How would I go about creating custom attributes for the player?
    3. Do attributes automatically sync for the Client and Server? With capabilities I have to send packets myself somewhat frequently.
    4. Do attributes reset when the Player dies or enters another Dimension?

     

    Thank you so much for your time!

    Note: I am aware you can add attributes to the player using a Mixin, but I would rather avoid doing this.

  12. I have imported my project from GitHub in order to streamline my development, however I am experiencing the above issue.

     

    My mods.toml file is as such:

    modLoader="javafml"
    loaderVersion="[35,)"
    license="All rights reserved"
    [[mods]]
    modId="elenaidodge"
    version="2.0.4"
    displayName="Elenai Dodge 2"
    #displayURL="https://www.curseforge.com/minecraft/mc-mods/elenai-dodge-2"
    credits="ElenaiDev"
    authors="Elenai"
    description='''
    Placeholder
    '''
    [[dependencies.elenaidodge]]
        modId="forge" #mandatory
        mandatory=true #mandatory
        versionRange="[35,)" #mandatory
        ordering="NONE"
        side="BOTH"
    [[dependencies.elenaidodge]]
        modId="minecraft"
        mandatory=true
        versionRange="[1.16.4,1.17)"
        ordering="NONE"
        side="BOTH"

     

    And my main class is simply:

    @Mod(ElenaiDodge.MODID)
    public class ElenaiDodge {
    
    	public static final Logger LOGGER = LogManager.getLogger();
    	public static final String NAME = "Elenai Dodge";
    	public static final String MODID = "elenaidodge";
    	
    	public static final Logger LOG = LogManager.getLogger("ElenaiDodge");
    	
    	public ElenaiDodge() {
    		
    		ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigHandler.CLIENT_SPEC);
    		ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHandler.COMMON_SPEC);
    		
    		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
    		bus.addListener(this::setup);
    
    		ItemList.ITEMS.register(bus);
    	   }
    	private void setup(final FMLCommonSetupEvent event) {
    
    	}
    }

     It's unusual as I have run my gradle setup commands again and this was working fine before I uploaded it to github. Any help would be greatly appreciated!

     

    EDIT: I fixed this by reinstalling the entire MDK and replacing the src

  13. 6 minutes ago, diesieben07 said:

    You should be able to use a compileOnly dependency.

    Thank you and I thought as much, however when I do this the mod is still present at runtime.

    repositories {
        maven {
            name = "CurseForge"
            url = "https://minecraft.curseforge.com/api/maven/"
        }
    }
    
    dependencies {
        minecraft 'net.minecraftforge:forge:1.16.5-36.0.42'
        compileOnly "tough-as-nails:ToughAsNails-1.16.5:4.0.1.14:universal"
    }

    This wouldn't matter, however I'm experiencing an issue where my workspace is refusing to import access transformers from other mods, so when tough as nails is run as a dependency I get a crash.

  14. 1 minute ago, diesieben07 said:

    There is no space assignment system in the HUD

    I see, thank you. What I meant was I'm calculating how high to render my GUI by using this.

    int rows = MathHelper.ceil(dodges / 20.0F);
    int rowHeight = Math.min(Math.max(10 - (rows - 2), 3), 10);
    int top = (screenHeight - ForgeIngameGui.right_height) - ((rows * rowHeight) - 10);

    Which seems to make room for other mods.

     

    Is there a way to maintain this effect whilst not having my GUI cancelled when the render event is canceled if it is ElementType.FOOD?

×
×
  • Create New...

Important Information

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