Jump to content

andreybadrey

Members
  • Posts

    34
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by andreybadrey

  1. the method displayClientMessage itself outputs only one line you can write your own method for displaying such messages, for example using an overlay. or try overriding the display ClientMessage method so that it accepts and processes List<Component> in my opinion, your own implementation through an overlay will be the simplest way
  2. depending on the context and location of the call, the method of obtaining it may differ significantly, but it is always Level example: the Player parameter is passed to a certain method public boolen anyMethod(ServerPlayer player, par1, par2) {...} you will receive the client side as follows player.getLevel.isClientSide server code is written in a block if (! player.getLevel.isClientSide){///} client code is written in a block if (player.getLevel.isClientSide){///} in some cases, the world can be passed directly to the method, but I don’t remember this in my practice in almost all cases I get the client side from LivingEntity.getLevel.isClientSide example 2: the client side is taken from the event public static void onPlayerJoin(EntityJoinLevelEvent event){ if(!event.getLevel().isClientSide()){ if(event.getEntity() instanceof ServerPlayer player){ val = event; RegisterPlayer registerPlayer = new RegisterPlayer(); registerPlayer.start(); SetupQuestCoreForPlayer setupQuestCoreForPlayer = new SetupQuestCoreForPlayer(); setupQuestCoreForPlayer.start(); } } here you can also get the client side via event.getEntity().getLevel().isClientSide() OR event.getLevel().isClientSide() sorry my ENGLISH is very bad loock this https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/event/CapsEvents.java https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/event/JoinLevel.java https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/event/LivingEntityDeath.java https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/event/LivingEntityHurt.java https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/util/SyncScaner.java its help you!
  3. Wrap it all in a block if(!livingentity instanseof ServerPlayer){ }
  4. a method that allows you to use what you want is called UseOn(), maybe a little differently NOT onItemRightClick
  5. 1 use in yor weapons classes^ @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { return new ProviderItemStak(); } 2 create provider class for capabilit itemstacks: package com.bodryak.gmod.variables.server; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityToken; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.LazyOptional; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class ProviderItemStak implements ICapabilityProvider, INBTSerializable<CompoundTag> { public static Capability<IDS> ITEM_DATA = CapabilityManager.get(new CapabilityToken<IDS>() { }); private IDS data = null; private final LazyOptional<IDS> optional = LazyOptional.of(this::createItemData); private IDS createItemData() { if (this.data == null) { this.data = new IDS(); } return this.data; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ITEM_DATA) { return optional.cast(); } return LazyOptional.empty(); } @Override public CompoundTag serializeNBT() { CompoundTag nbt = new CompoundTag(); createItemData().saveNBTData(nbt); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { createItemData().loadNBTData(nbt); } } package com.bodryak.gmod.variables.server; import net.minecraft.nbt.CompoundTag; public class IDS { private int damage = 1; public int getDamage() { return damage; } public void setDamage(int damage) { this.damage = damage; } public void saveNBTData(CompoundTag nbt) { nbt.putInt("damage", damage); } public void loadNBTData(CompoundTag nbt) { damage = nbt.getInt("damage"); } }
  6. import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Blocks; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber public class TestProcedure { @SubscribeEvent public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) { if(event.getLevel().getBlockState(event.getPos()).getBlock() == Blocks.GRASS){ if(!event.getLevel().isClientSide()){ event.getLevel().setBlock(new BlockPos(event.getPos().getX(), event.getPos().getY() +1, event.getPos().getZ()), Blocks.MOSS_CARPET.defaultBlockState(), 3); } } } }
  7. Yes, you can, but not quite in this way, for this you can use CAPABILITIES https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities/ and on this basis rewrite the damage system here is an example https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/variables/server/MDS.java https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/event/LivingEntityHurt.java
  8. As I understand it, the event occurs 1 time for the right hand, 2 times for the left hand you need to write a code that excludes the action for the left hand if ((cow.getAge() != -1) && event.getEntity().getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(Items.BOWL)) checks for the right hand, but does not preclude execution of the code for the left hand when the right hand condition is true add && hand == InteractionHand.MAIN_HAND in if(!event.getLevel().isClientSide()) should work
  9. method must start with super.init(); to reset buttons this.init(); anywhere in the code loock https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/gui/gui/screen/GuiAlchemistScreen.java#L118C9-L118C22
  10. Hi I want to implement the following mechanic I have an item with a flat square model for all inventory slots and interfaces. I want to program the display of this item as a 3D model, but only for certain states: 1 when the object is on the ground, the 3d model should be displayed 2 when the item is in hand, the 3d model should be displayed in all other cases, the generated flat model should be displayed how can i achieve something like this? gpt chat gave some thoughts, but the methods and classes proposed by the neural network do not exist in the mapping 1.20.1 patchment, they probably exist in the official mapping, but I did not check it, sorry. one word after talking with gpt i just got more confused help me figure this out please
  11. loock https://github.com/andreybadrey/forge/blob/master/src/main/java/com/bodryak/gmod/gui/overlay/HudOverlay.java
  12. Загрузите на github, что есть на данный момент, я посмотрю. I suspect you want to do something similar to JEI. Find items for each mod in a separate tab?
  13. try to display the BAR through the picture GitHub Here is a working example
  14. So it is, having received information about the player, you can send a packet with the necessary data to the client https://github.com/andreybadrey/keymodoverlay something similar is here, this mod was written to test just the possibility of data exchange: Client1 -> server -> client2 -> server -> client1 look it up for 1.16 you need modify this
  15. I'm working on it too at the moment I found a way to dynamically add slots ... I can not delete
  16. In general, as always, I independently found a solution in fact, the topic of multithreading turned out to be very simple to understand and apply in minecraft The point is to output each server action to a separate thread, of course, where possible and safe For those who are interested, I am attaching my first multithread model GITHUB On the example of using packages, I brought each server action to a separate thread through a class with inheritance of the Thread class class MyThread extends Thread { @Override public void run() { any code } } Having trouble defining NetworkEvent.Context. To define it and pass it to a new thread, I defined a static object in the package class public class ByeAppleC2SPacket { public static NetworkEvent.Context val; public ByeAppleC2SPacket() {} } define a variable(object) val in the handler method and Starting the second thread public boolean handle(Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { val = context; MyThread myThread = new MyThread(); myThread.start(); }); return true; } Now in a new thread, we can perform actions on the player through ByeAppleC2SPacket.val.getSender() Also in the stream method run() we can start new threads as a result, after performing each action in a new thread, we give a minimum drawdown on the TPS server and speed up the mod tenfold Before using this model, the code provided in the github gave a huge drawdown of the TPS, and caused the server to crash. Now when spamming at 10 packets per second, and with three operations per packet: Request balance, give an item, update the balance. All operations are parallelized into separate threads, and do not slow down the server Use this if you are interested ... I will ask experienced developers for feedback ...
  17. Hi guys, my Java is BAD, and my English is verry BAD... Therefore, what I will write may not be clear, but I really ask you to try to figure it out and help me if someone knows an alternative or has already done something like this. I am having the following problem with my mod: There is a game store in the mod, how is it? Its alpha version, which will be improved from the current state... And this store is working properly... But, when buying from the store, the entire server stops at the moment the item is received from the store. The reason for this is one thread (Main Thread). Now the purchase code works like this: 1) By pressing the key, GUI opens, information from the player's balance database is loaded into the GUI; 2) When you click on the purchase button, a packet is sent to the server with information that the player pressed the button 3) The server, having received the packet, makes a request to the database with a balance check. If the balance allows, the server issues the item to the player, makes a database query, writing the new balance. I noticed that at the time of requests to the database, the server just sleeps. It stops generating ticks until it receives a response from the database. If you spam multiple clicks on the button, then you can observe a complete stop of the world, at the time of loading requests to the database. As far as I realized myself in Java, I understand that the reason for all this is: the sequence of code execution in the main thread, all operations are performed strictly in order ... So, in order to fix this, based on my knowledge, I assume that you need to move database queries to a separate thread ... What is a thread and how to create it, I know a little, but very little. Of course, I will pump my knowledge in this direction. But I would like to know from you: 1) Where should the new thread be written? 2) Safe syntax for opening a stream, and in which part of the code 3) Methods for transferring information from the second stream to the main one I will be glad if you at least point to actual examples on the github in which this is practiced. Due to my limited knowledge of languages, I experience some difficulties in finding information. I will be glad for any help GitHub
  18. these are so far obvious obstacles that I have seen, try to work with them in a copy of your project, it’s not a fact that this is what you need, but I would do it this way loock my test code GitHub
  19. Most likely because of the event LivingEvent.LivingTickEvent event all data from mod reseting in event you used ModMessages.sendToServer but event going on Server - if(!event.getEntity().getLevel().isClientSide()) I propose to rewrite the logic of processing opportunities in event onAttachCapabilityEntity(AttachCapabilitiesEvent<Entity> event) should check each possibility separately depending on the entity, set values directly in the check block this code is called when the mob spawns, so the need to use the event EntityRespawn not need next in the event onEntityHurt(LivingHurtEvent event) handle all feature changes, and send to all clients INSTANCE.send(PacketDistributor.ALL.noArg(), message); code in packet handle public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { assert Minecraft.getInstance().player != null; Level world = Minecraft.getInstance().player.level; final Vec3 _center = new Vec3(this.pos.getX(), this.pos.getY(), this.pos.getZ()); List<Entity> _entfound = world.getEntitiesOfClass(Entity.class, new AABB(_center, _center).inflate(4 / 2d), e -> true).stream().sorted(Comparator.comparingDouble(_entcnd -> _entcnd.distanceToSqr(_center))).collect(Collectors.toList()); for (Entity entityiterator : _entfound) { if (entityiterator.getUUID().toString().equals(this.entity.toString())){ entityiterator.getCapability(ProviderMDS.MOB_DATA).ifPresent(m -> { m.setHp(this.hp); }); } } }); return true; } after that the client sees the changes through the code Minecraft.getInstance().crosshairPickEntity.getCapability() and write an entity synchronization package that will be sent to clients when a chunk is loaded
  20. 1 issue: some versions need to use event.getOriginal().revive(); in PlayerEvent.Clone event otherwise event.getOriginal().getCapability always null... maybe on your assembly it will work as it should, I did not check 2 issue: onEntityDamage(LivingDamageEvent event) need to be removed event.setCanceled(true); need to be removed from onEntityHurt(LivingHurtEvent event) use instead setAmount(yuo value) in final every event.setCanceled(true); can affect the correctness of calculations, and the entire logic of the custom damage system 3 issue: LivingEvent.LivingTickEvent event should stop using it, your code in this event gives a huge load on both the client and the server in my example, I use getting mob statistics in the overlay code import com.bodryak.gmod.util.RayTrace; import com.bodryak.gmod.variables.client.PDC; import com.bodryak.gmod.variables.server.ProviderMDS; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiComponent; import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.client.event.RenderGuiEvent; import net.minecraftforge.api.distmarker.Dist; import net.minecraft.resources.ResourceLocation; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.Minecraft; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.platform.GlStateManager; @Mod.EventBusSubscriber({Dist.CLIENT}) public class HudOverlay { static final ResourceLocation TARGET_FRAME = new ResourceLocation("gmod:textures/gui/target_frame.png"); static final ResourceLocation TARGET_BAR = new ResourceLocation("gmod:textures/gui/target_bar.png"); static final ResourceLocation HUD = new ResourceLocation("gmod:textures/gui/hud.png"); static final ResourceLocation EXP_BAR = new ResourceLocation("gmod:textures/gui/exp_bar.png"); static final ResourceLocation EXP_F = new ResourceLocation("gmod:textures/gui/exp_bar_f.png"); static final ResourceLocation HP_BAR = new ResourceLocation("gmod:textures/gui/hp_bar.png"); static final ResourceLocation MP_BAR = new ResourceLocation("gmod:textures/gui/mp_bar.png"); static final RayTrace TRACE = new RayTrace(); static int target_bar_x = -70; static int target_hp; @SubscribeEvent(priority = EventPriority.NORMAL) public static void eventHandler(RenderGuiEvent.Pre event) { Font font = Minecraft.getInstance().font; int w = event.getWindow().getGuiScaledWidth(); int h = event.getWindow().getGuiScaledHeight(); int x = 195; int max_w_1 = w-14-x; int all_w = max_w_1 +8; double point = all_w * 0.01; double exp_p = PDC.getExp() / (PDC.getNlv() * 0.01); double exp_w = exp_p * point; double exp_f = 0; if (exp_w > max_w_1){ exp_f = exp_w - max_w_1; exp_w = max_w_1; } double hp_w = (197*0.01) * (PDC.getHp() / (PDC.getMax_hp()*0.01)); double mp_w = (159*0.01) * (PDC.getMana()/ (PDC.getMax_mana()*0.01)); int target_bar_start = -70; int target_bar_x_final = 138; RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.setShaderColor(1, 1, 1, 1); if (true) { RenderSystem.setShaderTexture(0, TARGET_FRAME); GuiComponent.blit(event.getPoseStack(), target_bar_x, 9, 0, 0, 247, 35, 247, 35); RenderSystem.setShaderTexture(0, TARGET_BAR); GuiComponent.blit(event.getPoseStack(), target_bar_x + 28, 14, 0, 0, target_hp, 25, 209, 25); RenderSystem.setShaderTexture(0, HUD); GuiComponent.blit(event.getPoseStack(), 0, 0, 0, 0, 203, 82, 203, 82); RenderSystem.setShaderTexture(0, EXP_BAR); GuiComponent.blit(event.getPoseStack(), 193, 0, 0, 0, w - 203, 10, 1980, 10); GuiComponent.blit(event.getPoseStack(), w - 13, 0, 1980 - 13, 0, 13, 10, 1980, 10); RenderSystem.setShaderTexture(0, EXP_F); GuiComponent.blit(event.getPoseStack(), x, 1, 0, 0,(int) Math.round(exp_w), 8, 1972, 8); GuiComponent.blit(event.getPoseStack(), w-14, 1, 1972-8, 0,(int) Math.round(exp_f), 8, 1972, 8); RenderSystem.setShaderTexture(0, HP_BAR); GuiComponent.blit(event.getPoseStack(), 1, 1, 0, 0, (int) Math.round(hp_w), 19, 197, 19); RenderSystem.setShaderTexture(0, MP_BAR); GuiComponent.blit(event.getPoseStack(), 1, 21, 0, 0, (int) Math.round(mp_w), 19, 159, 19); GuiComponent.drawString(event.getPoseStack(), font, "LVL: " + PDC.getLvl(), 5, 70, -1); LivingEntity target = TRACE.getEntityInCrosshair(1.0f, 20.0D); if (target != null) { if(target_bar_x < target_bar_x_final){ target_bar_x +=16; } target.getCapability(ProviderMDS.MOB_DATA).ifPresent(mds -> { target_hp = (int) ((209*0.01) * (mds.getHp() / (mds.getMax_hp()*0.01))); GuiComponent.drawString(event.getPoseStack(), font, String.valueOf(mds.getHp()), target_bar_x + 53, 25, -1); }); GuiComponent.drawString(event.getPoseStack(), font, target.getDisplayName(), target_bar_x + 53, 15, -1); } else { if(target_bar_x > target_bar_start){ target_bar_x -=16; } } } RenderSystem.depthMask(true); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); RenderSystem.disableBlend(); RenderSystem.setShaderColor(1, 1, 1, 1); } }
  21. Console keeps spamming [12:13:03] [Render thread/WARN] [mojang/BufferBuilder]: Clearing BufferBuilder with unused batches I don't know what it is yet, but it needs to be fixed...
  22. Sorry, you have a very large mod, I can't take the time to study it right now But I heard a little about the synchronization of opportunities a little later I will study your mod, maybe I will see a solution at the moment I want to talk about synchronization in my mod, in order to synchronize the capabilities of an entity that is not a player, I use a similar package import com.bodryak.gmod.variables.server.ProviderMDS; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkEvent; import java.util.Comparator; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; public class MDSyncS2CPacket { private final long hp; private final UUID entity; private BlockPos pos; public MDSyncS2CPacket(long hp, UUID entity, BlockPos pos) { this.hp = hp; this.entity = entity; this.pos = pos; } public MDSyncS2CPacket(FriendlyByteBuf buf){ this.hp = buf.readLong(); this.entity = buf.readUUID(); this.pos = buf.readBlockPos(); } public void toBytes(FriendlyByteBuf buf){ buf.writeLong(this.hp); buf.writeUUID(this.entity); buf.writeBlockPos(this.pos); } public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { assert Minecraft.getInstance().player != null; Level world = Minecraft.getInstance().player.level; final Vec3 _center = new Vec3(this.pos.getX(), this.pos.getY(), this.pos.getZ()); List<Entity> _entfound = world.getEntitiesOfClass(Entity.class, new AABB(_center, _center).inflate(4 / 2d), e -> true).stream().sorted(Comparator.comparingDouble(_entcnd -> _entcnd.distanceToSqr(_center))).collect(Collectors.toList()); for (Entity entityiterator : _entfound) { if (entityiterator.getUUID().toString().equals(this.entity.toString())){ entityiterator.getCapability(ProviderMDS.MOB_DATA).ifPresent(m -> { m.setHp(this.hp); }); } } }); return true; } } this package is sent to all clients, and synchronizes the capabilities of downloaded creatures on all clients but still need to synchronize entities when loading a chunk I haven't worked on it yet, it's just to come in my mod try to use event when chunk is loaded and send the package via public static <MSG> void sendToClients(MSG message) { INSTANCE.send(PacketDistributor.ALL.noArg(), message); } perhaps this post will not be relevant, but later, when I study your mod, I will try to find a clearer solution
  23. it is also possible that all the values that you change change on the server, but remain the same on the client, especially if you use capability, this is relevant for you... If this case is possible, then you have two options... option 1: duplicate your server code for the client side... option 2: write a sync system that will send batches of changes each time it changes... Now I suspect that you simply do not synchronize data with the server
  24. Hello, please upload the project to github, and give a link I'm going to do the same in my mod, and I'll try to help you Also try to use the trigger when the item is crafted in the item procedures public class TestItem extends Item { public TestItem() { super(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(64).rarity(Rarity.COMMON)); } @Override public void onCraftedBy(ItemStack itemstack, Level world, Player entity) { super.onCraftedBy(itemstack, world, entity); customcode.execute(world, entity.getX(), entity.getY(), entity.getZ()); } } I also suspect that the event when an item is crafted, from player events, is being listened to in the crafting grid of the player's inventory window, but I could be wrong Also try to display the values you need through tooltips
×
×
  • Create New...

Important Information

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