Jump to content


  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

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

GrigLog's Achievements

Tree Puncher

Tree Puncher (2/8)



  1. No. You will have to figure out a lot of stuff yourself.
  2. Exact bit values for people in the future: 1 - MOVE or TARGET (in 1.12 there was no difference between two, now they are split. You will have to think which one you want to use) 2 - LOOK 4 - JUMP
  3. What Im trying to do is to implement a "dash" mechanic on a Shift button. @SubscribeEvent public static void onEvent(InputEvent.KeyInputEvent event){ KeyBinding runBinding = Minecraft.getInstance().gameSettings.keyBindSprint; int key = event.getKey(); int runKey = runBinding.getKey().getKeyCode(); ClientPlayerEntity player = Minecraft.getInstance().player; if (key == runKey){ //some checks, and then: float yaw = player.rotationYaw; float x = -MathHelper.sin(yaw * 0.017453292F); float z = MathHelper.cos(yaw * 0.017453292F); double groundMotion = 5, airMotion = 2; if (player.isOnGround()) player.setMotion(new Vector3d(x * groundMotion, 0, z * groundMotion)); else player.setMotion(new Vector3d(x * airMotion, 0, z * airMotion)); } } And this code works. The problem is, it causes a lot of lag when the setMotion() is called - my fps drops from 60 to 50-40 and the dash movement looks discrete. I wonder why is it so and how it can be improved...
  4. Like this: -Xms128M -Xmx4096M This will limit RAM usage by 4 gb
  5. Im pretty sure you just need to limit your max RAM in java arguments
  6. Im sorry, there was a result actually - on server side capability got copied correctly, I just didn't see it from the game because its not synced. Now, how can I send that data to client? In which event?
  7. Well, thats exactly what Im struggling with. Ive also tried soulNew.setNbt(soul.getNbt()), but with no result The thing is, I actively use input events and I have to send player inputs to server somehow. I should probably make 2 separate capabilities (for mana and for inputs) later SoulCap class: public class SoulCap { public static int CATimerMax = 20; public static int dashWindowMax = 3; public static int dashCDMax = 20; public int parryTimer = 0; public int CATimer = 0; public int dashWindow = 0; public int dashCD = 0; public boolean justParried = false; public boolean rightClicked = false; public boolean leftClicked = false; public double mana = 0; public double maxMana = 10; public HashMap<String, Integer> usedKeyItems = new HashMap<>(); public boolean trySpendMana(double a) { if (mana >= a){ mana -= a; return true; } return false; } public void addMana(double a){ mana += a; if (mana > maxMana) mana = maxMana; } public CompoundNBT getNbt(){ CompoundNBT tag = new CompoundNBT(); tag.putInt("parryTimer", parryTimer); tag.putInt("CATimer", CATimer); tag.putBoolean("justParried", justParried); tag.putBoolean("rightClicked", rightClicked); tag.putBoolean("leftClicked", leftClicked); tag.putDouble("mana", mana); tag.putDouble("maxMana", maxMana); CompoundNBT keyItems = new CompoundNBT(); for (String s : usedKeyItems.keySet()){ keyItems.putInt(s, usedKeyItems.get(s)); } tag.put("usedKeyItems", keyItems); return tag; } public SoulCap setNbt(CompoundNBT nbt){ parryTimer = nbt.getInt("parryTimer"); CATimer= nbt.getInt("CATimer"); justParried = nbt.getBoolean("justParried"); rightClicked = nbt.getBoolean("rightClicked"); leftClicked = nbt.getBoolean("leftClicked"); mana = nbt.getDouble("mana"); maxMana = nbt.getDouble("maxMana"); CompoundNBT keyItems = nbt.getCompound("usedKeyItems"); for (String s : keyItems.keySet()){ usedKeyItems.put(s, keyItems.getInt(s)); } return this; } public static class SoulProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(SoulCap.class) public static Capability<SoulCap> SOUL_CAP; private final LazyOptional<SoulCap> instance = LazyOptional.of(() -> new SoulCap()); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == SOUL_CAP ? instance.cast() : LazyOptional.empty(); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap) { return cap == SOUL_CAP ? instance.cast() : LazyOptional.empty(); } @Override public INBT serializeNBT() { return SOUL_CAP.getStorage().writeNBT(SOUL_CAP, this.instance.resolve().get(), null); } @Override public void deserializeNBT(INBT nbt) { SOUL_CAP.getStorage().readNBT(SOUL_CAP, this.instance.resolve().get(), null, nbt); } } public static class SoulStorage implements Capability.IStorage<SoulCap> { @Override public INBT writeNBT(Capability<SoulCap> capability, SoulCap soulCap, Direction side) { return soulCap.getNbt(); } @Override public void readNBT(Capability<SoulCap> capability, SoulCap soulCap, Direction side, INBT nbt) { soulCap.setNbt((CompoundNBT)nbt); } } }
  8. Forge 1.16.5-36.1.30. Docs say that PlayerEvent.Copy event is helpful for this, but I cant figure out what to do exactly. This is what I wrote and it doesnt work: EventHandler: @SubscribeEvent static void copyPlayerDataOnRespawn(PlayerEvent.Clone event){ SoulCap soul = SF.getSoul(event.getOriginal()); SoulCap soulNew = SF.getSoul(event.getPlayer()); soulNew = soul; SF.sendToClient((ServerPlayerEntity)event.getPlayer(), soulNew); } SF: public static SoulCap getSoul(PlayerEntity player){ return player.getCapability(SoulCap.SoulProvider.SOUL_CAP, null).resolve().orElse(null); } public static void sendToClient(ServerPlayerEntity player, SoulCap cap){ PacketSender.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new SoulPacket(cap)); } SoulPacket: static void handle(SoulPacket p, Supplier<NetworkEvent.Context> ctx){ ctx.get().enqueueWork(() -> { if (ctx.get().getDirection() == NetworkDirection.PLAY_TO_CLIENT) { ClientPlayerEntity player = Minecraft.getInstance().player; SoulCap cap = SF.getSoul(player); cap.setNbt(p.cap.getNbt()); if (cap.justParried) { player.stopActiveHand(); cap.justParried = false; } } else if (ctx.get().getDirection() == NetworkDirection.PLAY_TO_SERVER){ ServerPlayerEntity player = ctx.get().getSender(); SoulCap cap = SF.getSoul(player); cap.setNbt(p.cap.getNbt()); if (cap.justParried) { cap.justParried = false; } } }); ctx.get().setPacketHandled(true); } First of all, the sentToClient side can be easlily removed because at this point in code Minecraft.getInstance().player is still null. But I still have to sync sides somehow... And secondly, the capability is not actually getting copied. I guess its because in this case player.getCapability() only provides a copy of the asked capability, not an assignable reference. But there is no player.setCapability method... So what do I do?
  9. Ive made an armor model in Blockbench (just a bunch of random stripes), exported it as a .java object and binded a texture to it. The problem is, it is not rendered as it should, it just floats with the player. Model code (mostly generated by Blockbench): public class CustomArmorModel extends BipedModel<LivingEntity> { private final ModelRenderer Head; private final ModelRenderer Body; private final ModelRenderer RightArm; private final ModelRenderer LeftArm; private final ModelRenderer RightLeg; private final ModelRenderer LeftLeg; public CustomArmorModel() { super(1); textureWidth = 64; textureHeight = 64; Head = new ModelRenderer(this); Head.setRotationPoint(0.0F, 0.0F, 0.0F); Head.setTextureOffset(32, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, 0.5F, false); Body = new ModelRenderer(this); Body.setRotationPoint(0.0F, 0.0F, 0.0F); Body.setTextureOffset(16, 32).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, 0.25F, false); Body.setTextureOffset(0, 0).addBox(-1.0F, 2.0F, 3.0F, 1.0F, 1.0F, 1.0F, 0.0F, false); Body.setTextureOffset(40, 32).addBox(-8.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, 0.25F, false); RightArm = new ModelRenderer(this); RightArm.setRotationPoint(-5.0F, 2.0F, 0.0F); LeftArm = new ModelRenderer(this); LeftArm.setRotationPoint(5.0F, 2.0F, 0.0F); LeftArm.setTextureOffset(48, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, 0.25F, false); RightLeg = new ModelRenderer(this); RightLeg.setRotationPoint(-1.9F, 12.0F, 0.0F); RightLeg.setTextureOffset(0, 32).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, 0.25F, false); LeftLeg = new ModelRenderer(this); LeftLeg.setRotationPoint(1.9F, 12.0F, 0.0F); LeftLeg.setTextureOffset(0, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, 0.25F, false); } @Override public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){ Head.render(matrixStack, buffer, packedLight, packedOverlay); Body.render(matrixStack, buffer, packedLight, packedOverlay); RightArm.render(matrixStack, buffer, packedLight, packedOverlay); LeftArm.render(matrixStack, buffer, packedLight, packedOverlay); RightLeg.render(matrixStack, buffer, packedLight, packedOverlay); LeftLeg.render(matrixStack, buffer, packedLight, packedOverlay); } } Whats wrong there? And are there other ways to make models, better than Blockbench?
  10. Yes, this time you were right. But how can I sync server with client now? I dont see any Event of (de)serialization
  • Create New...

Important Information

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