Jump to content

squidlex

Members
  • Posts

    183
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

squidlex's Achievements

Creeper Killer

Creeper Killer (4/8)

4

Reputation

  1. I'm looking to move the player camera down vertically for a couple ticks but don't know where to start with it. Thank you!
  2. It used to be possible to determine if the Local Player was moving forwards or strafing using ClientPlayer.moveStrafing and ClientPlayer.moveForward, is this feature gone and if-so is there an alternative? Thank you very much for your help
  3. 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.
  4. 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?
  5. 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.
  6. 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
  7. I see, thank you! It was called that because I was misunderstanding the method's purpose. It now works, thanks
  8. 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();
  9. I am following the read the docs article here but am struggling to get my head around it. 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!
  10. As Walls seem to use Tags, I'm trying to work out if a given block is a wall (e.g Cobblestone Wall), does anyone know a good way to go about doing this? Thank you!
  11. I'm working with AABBs and was wondering if anyone knows a simple way to make them visible? Thanks for your help!
  12. 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!
  13. Hi there! Essentially, I was wondering if there's anyway to check if the world is running (as in not paused) on the server side? Thanks for your help!
  14. 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!
×
×
  • Create New...

Important Information

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