Jump to content

4sterism

Members
  • Posts

    31
  • Joined

  • Last visited

Posts posted by 4sterism

  1. 4 hours ago, robertx555 said:

    Is this mod released somewhere? If so that's against my permission as i reserved all rights. I only allowed private use of modified code.

     

    Also the 1.12.2 version has a crapton of my spaghetti code which is mostly ironed out in 1.14.4 as i spent months reworking most things. Yes, months to rework things, so i don't suggest you try fix.

     

    Also sorry sieben for the problems.

     

     

     

    Its not relased anywhere, its just for a group of small friends. I have no interest in releasing it anywhere.

  2. 6 hours ago, diesieben07 said:

    This is terrible in so many ways.

     

    1. It spawns a new thread every time. Spawning threads is very expensive.
    2. It does not properly dispose the created ExecutorService. Guava does this for you in this case through the finalize method (which is also just terrible, because it makes the GC work much harder to clean up this object), but it's still bad coding style.
    3. It's accessing MInecraft code from a completely random thread. Minecraft code must (99% of the time) only be accessed from it's main thread.

    By the way, where should I read up on how to improve this for future reference?

  3. 1 minute ago, diesieben07 said:

    Sorry, but I am not playing around for hours in game trying to get this to happen... You need to spend some time and isolate it.

    Ok. I will do that. On server, fighting mosnters can usually cause crashes. Testing on client doesnt cause crashes though, which is telling.

  4. 1 minute ago, diesieben07 said:

    Which monsters? I can't even fight the slimes in superflat, their attacks are one-hit kills and things like regen don't work.

    I don't know whats causing the crashes exactly. And yh, I think I need to nerf slime dmg. We dont encounter lots of slimes. Regen happens every second. Ive never seen a problem with regen.

  5. 14 minutes ago, diesieben07 said:

    Where is RecalculateStats called from?

    In general, is it possible to post a Git repository of the mod?

    https://github.com/ndrwln/Mine-and-Slash-modified

    Its just open source code I modified so...

    I also think the baubles jar is a forked version someone changed so that it would send an event when equipment changed. So that my mod could catch it and recalculate the stats. Its in the lib folder. The original implementation of the mod would not recalc stats when a bauble equip was changed -_-.

     

    The crash doesnt occur when changing equipment, though. Sometimes we can go 40 minutes without a crash. Other times its constant crashing,

  6. Thank you for taking your time. Ok, I will try to upload a repository. RecalculateStats is called int he same class and another class. That has a method called recalculateStats, that checks if the unit is null or if there is a need to recalc the stats. That method is called in a number of places.

  7. 3 minutes ago, diesieben07 said:

    This is terrible in so many ways.

     

    1. It spawns a new thread every time. Spawning threads is very expensive.
    2. It does not properly dispose the created ExecutorService. Guava does this for you in this case through the finalize method (which is also just terrible, because it makes the GC work much harder to clean up this object), but it's still bad coding style.
    3. It's accessing MInecraft code from a completely random thread. Minecraft code must (99% of the time) only be accessed from it's main thread.

    I'll leave out the fact that just dumping the whole capability NBT down the network is stupid (only sync what you need and don't use NBT for it if you can help it).

    That error means that something is trying to read one byte (length 1), but there are 0 bytes available (because both readerIndex and writerIndex are 31). Read the Javadoc on ByteBuf, it explains how readerIndex and writerIndex work.

     

    Show where you register your packets and where you send them.

    I didn't write this code, but I'm willing to learn how to fix and clean it up.

    As for where the code is registered.

    MinecraftForge.EVENT_BUS.register(new PlayerUnitPackage());
    MinecraftForge.EVENT_BUS.register(new EntityUnitPackage());
    MinecraftForge.EVENT_BUS.register(new DamageNumberPackage());
    MinecraftForge.EVENT_BUS.register(new ParticlePackage());
    MinecraftForge.EVENT_BUS.register(new WorldPackage());
    MinecraftForge.EVENT_BUS.register(new PacketAnimation());
    
    Network.registerMessage(PlayerUnitPackage.Handler.class, PlayerUnitPackage.class, 0,
            Side.CLIENT);
    Network.registerMessage(EntityUnitPackage.Handler.class, EntityUnitPackage.class, 1,
            Side.CLIENT);
    Network.registerMessage(DamageNumberPackage.Handler.class, DamageNumberPackage.class, 2,
            Side.CLIENT);
    Network.registerMessage(ParticlePackage.Handler.class, ParticlePackage.class, 3, Side.CLIENT);
    Network.registerMessage(WorldPackage.Handler.class, WorldPackage.class, 4, Side.CLIENT);
    Network.registerMessage(MessagePackage.Handler.class, MessagePackage.class, 5, Side.CLIENT);
    

     

    @Mod.EventBusSubscriber
    public class OnTrackEntity {
    
        @SubscribeEvent
        public static void onEntityTrack(PlayerEvent.StartTracking event) {
    
            Entity entity = event.getTarget();
    
            if (entity instanceof EntityLivingBase) {
                if (entity.isEntityEqual(event.getEntityPlayer()) == false) {
                    if (entity.hasCapability(EntityData.Data, null)) {
    
                        Main.Network.sendTo(new EntityUnitPackage((EntityLivingBase) entity),
                                (EntityPlayerMP) event.getEntityPlayer());
                    }
    
                }
            }
    
        }
    }

     

    /**
     * @return checks if it should be synced to clients. Clients currently only see health and status
     * effects
     */
    private DirtyCheck getDirtyCheck() {
    
        DirtyCheck check = new DirtyCheck();
    
        check.hp = (int) MyStats.get(Health.GUID).Value;
    
        return check;
    }
    
    public void RecalculateStats(EntityLivingBase entity, UnitData data, int level,
                                 IWorldData world) {
    
        data.setEquipsChanged(false);
    
        if (data.getUnit() == null) {
            data.setUnit(this, entity);
        }
    
        DirtyCheck old = getDirtyCheck();
    
        Unit copy = this.Clone();
    
        int tier = 0;
        if (world != null) {
            tier = world.getTier();
        }
    
        ClearStats();
    
        MobRarity rar = Rarities.Mobs.get(data.getRarity());
    
        float hpadded = this.getHpAdded(entity, rar, data);
    
        MyStats.get(Health.GUID).Flat += hpadded;
    
    
        if (entity instanceof EntityPlayer) {
            List<GearItemData> gears = PlayerStatUtils.getEquipsExcludingWeapon(entity); // slow
            boolean gearIsValid = this.isGearCombinationValid(gears, entity);
    
            ItemStack weapon = entity.getHeldItemMainhand();
            if (weapon != null) {
                GearItemData wep = Gear.Load(weapon);
                if (wep != null && wep.GetBaseGearType().slotType().equals(GearSlotType.Weapon))
                    gears.add(wep);
            }
    
            ItemStack offhand = entity.getHeldItemOffhand();
            if (offhand != null) {
                GearItemData off = Gear.Load(offhand);
                if (off != null && off.GetBaseGearType().slotType().equals(GearSlotType.OffHand))
                    gears.add(off);
            }
    
            PlayerStatUtils.AddPlayerBaseStats(data, this);
    
            if (gearIsValid) {
                PlayerStatUtils.CountWornSets(entity, gears, this);
                PlayerStatUtils.AddAllGearStats(entity, gears, this, level); // slow, but required
                PlayerStatUtils.AddAllSetStats(entity, this, level);
            }
        } else {
            MobStatUtils.AddMobcStats(data, data.getLevel(), entity);
            MobStatUtils.AddMobTierStats(this, tier);
    
        }
    
        CommonStatUtils.AddStatusEffectStats(this, level);
        CommonStatUtils.AddMapAffixStats(this, level);
        PlayerStatUtils.CalcStatConversionsAndTransfers(copy, this);
        PlayerStatUtils.CalcTraits(data);
    
        CalcStats(data);
    
        DirtyCheck newcheck = getDirtyCheck();
    
        if (old.isDirty(newcheck)) {
            Main.Network.sendToAllTracking(new EntityUnitPackage(entity, data), entity);
        }
    
    }
  8. package com.robertx22.network;
    
    import com.robertx22.mmorpg.Main;
    import com.robertx22.uncommon.capability.EntityData;
    import com.robertx22.uncommon.capability.EntityData.UnitData;
    import io.netty.buffer.ByteBuf;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraftforge.fml.common.network.ByteBufUtils;
    import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
    import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
    import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
    
    import java.util.concurrent.Executors;
    import java.util.concurrent.ScheduledExecutorService;
    import java.util.concurrent.TimeUnit;
    
    public class EntityUnitPackage implements IMessage {
    
        public int id;
        public NBTTagCompound nbt;
    
        public EntityUnitPackage() {
    
        }
    
        public EntityUnitPackage(Entity entity) {
            this.id = entity.getEntityId();
            this.nbt = entity.getCapability(EntityData.Data, null).getNBT();
        }
    
        public EntityUnitPackage(Entity entity, UnitData data) {
            this.id = entity.getEntityId();
            this.nbt = data.getNBT();
        }
    
        @Override
        public void fromBytes(ByteBuf buf) {
            nbt = ByteBufUtils.readTag(buf);
            id = nbt.getInteger("id");
        }
    
        @Override
        public void toBytes(ByteBuf buf) {
            nbt.setInteger("id", id);
            ByteBufUtils.writeTag(buf, nbt);
    
        }
    
        public static class Handler implements IMessageHandler<EntityUnitPackage, IMessage> {
    
            @Override
            public IMessage onMessage(EntityUnitPackage message, MessageContext ctx) {
    
                Runnable noteThread = new Runnable() {
                    @Override
                    public void run() {
                        try {
    
                            final EntityPlayer player = Main.proxy.getPlayerEntityFromContext(ctx);
    
                            if (player != null && player.world != null) {
                                Entity entity = player.world.getEntityByID(message.id);
    
                                EntityLivingBase en = (EntityLivingBase) entity;
    
                                if (en != null) {
                                    en.getCapability(EntityData.Data, null).setNBT(message.nbt);
    
                                }
    
                            }
    
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
    
                };
                ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
                scheduler.schedule(noteThread, 1, TimeUnit.SECONDS);
    
                return null;
            }
    
        }
    }
    
  9. 8 hours ago, diesieben07 said:

    The problem is that you are trying to read data where there is none. This usually means you have a mismatch between the data you are sending and the data you are trying to read on the other side.

    Again: Show your code.

    Ok, Ive looked through the packets and noticed this one read and writed differently. The reader is missing Mobd saved once. Is this the problem?

  10.  @Override
            public NBTTagCompound getNBT() {
                nbt.setFloat(MANA, mana);
                nbt.setFloat(ENERGY, energy);
                nbt.setInteger(LEVEL, level);
                nbt.setInteger(EXP, exp);
                nbt.setInteger(RARITY, rarity);
                nbt.setString(UUID, uuid);
                nbt.setString(NAME, name);
                nbt.setBoolean(MOB_SAVED_ONCE, true);
                nbt.setInteger(CURRENT_MAP_ID, currentMapId);
                nbt.setBoolean(EQUIPS_CHANGED, equipsChanged);
                nbt.setFloat(DMG_DONE_BY_NON_PLAYERS, dmgByNonPlayers);
    
                if (unit != null) {
                    NBTTagCompound unitnbt = new NBTTagCompound();
                    Writer.write(unitnbt, unit);
                    nbt.setTag(UNIT_OBJECT, unitnbt);
                }
                if (kills != null) {
                    NBTTagCompound killsnbt = new NBTTagCompound();
                    Writer.write(killsnbt, kills);
                    nbt.setTag(KILLS_OBJECT, killsnbt);
                }
    
                return nbt;
    
            }
    
            @Override
            public void setNBT(NBTTagCompound value) {
                this.nbt = value;
                this.mana = value.getFloat(MANA);
                this.energy = value.getFloat(ENERGY);
                this.level = value.getInteger(LEVEL);
                this.exp = value.getInteger(EXP);
                this.rarity = value.getInteger(RARITY);
                this.uuid = value.getString(UUID);
                this.name = value.getString(NAME);
                this.currentMapId = value.getInteger(CURRENT_MAP_ID);
                this.equipsChanged = value.getBoolean(EQUIPS_CHANGED);
                this.dmgByNonPlayers = value.getFloat(DMG_DONE_BY_NON_PLAYERS);
    
                NBTTagCompound object_nbt = (NBTTagCompound) this.nbt.getTag(UNIT_OBJECT);
                if (object_nbt != null) {
                    unit = new Unit();
                    Reader.read(object_nbt, unit);
                }
    
                NBTTagCompound kills_nbt = (NBTTagCompound) this.nbt.getTag(KILLS_OBJECT);
                if (kills_nbt != null) {
                    kills = new PlayerMapKillsData();
                    Reader.read(kills_nbt, kills);
                }
    
            }

     

  11. 8 hours ago, diesieben07 said:

    The problem is that you are trying to read data where there is none. This usually means you have a mismatch between the data you are sending and the data you are trying to read on the other side.

    Again: Show your code.

    Will do, I look at all my Handlers and post up the one soon.

  12. People on my server have been getting this issue alot: java.lang.IndexOutOfBoundsException: readerIndex(32) + length(1) exceeds writerIndex(32): PooledUnsafeDirectByteBuf(ridx: 32, widx: 32, cap: 32). But the debug log doesnt provide anything useful for me to find the source of the problem. I know the problem is with one of my packets, how do I find the packet with the 32 index?

×
×
  • Create New...

Important Information

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