Выдача сытости по тикам и копание 3х3.

Версия Minecraft
1.12.2
API
Forge
И так, у меня должны быть штанишки, которые восстанавливают 1 сытость например каждые 30 секунд, что для этого использовать здесь?
Java:
if(player.getItemStackFromSlot(EntityEquipmentSlot.LEGS).getItem() != null && player.getItemStackFromSlot(EntityEquipmentSlot.FEET).getItem() == ItemsRegistry.cileggs){
         
        }

Так же есть ещё и лопата, которая должна выполнять функцию раскопки 3х3, но при вскапываний получаю java.lang.StackOverflowError и моментальный shutdown мира...

Java:
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
    {
        boolean ret = this.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);

        if (!(entityLiving instanceof EntityPlayer) || worldIn.isRemote)
        {
            return ret;
        }


        if(!stack.hasTagCompound() || stack.hasTagCompound() && !stack.getTagCompound().getBoolean("drill_mode"))
            return ret;

        EntityPlayer player = (EntityPlayer) entityLiving;
        EnumFacing facing = entityLiving.getHorizontalFacing();

        if (entityLiving.rotationPitch < -45.0F)
        {
            facing = EnumFacing.UP;
        }
        else if (entityLiving.rotationPitch > 45.0F)
        {
            facing = EnumFacing.DOWN;
        }

        boolean yAxis = facing.getAxis() == EnumFacing.Axis.Y;
        boolean xAxis = facing.getAxis() == EnumFacing.Axis.X;

        for (int i = 0; i <= 9; ++i)
        {
            for (int j = 0; j <= 9 && !stack.isEmpty(); ++j)
            {
                if (i == 0 && j == 0)
                {
                    continue;
                }

                BlockPos pos1;
                if (yAxis)
                {
                    pos1 = pos.add(i, 0, j);
                }
                else if (xAxis)
                {
                    pos1 = pos.add(0, i, j);
                }
                else
                {
                    pos1 = pos.add(i, j, 0);
                }

                //:Replicate logic of PlayerInteractionManager.tryHarvestBlock(pos1)
                IBlockState state1 = worldIn.getBlockState(pos1);
                float f = state1.getBlockHardness(worldIn, pos1);
                if (f >= 0F)
                {
                    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, pos1, state1, player);
                    MinecraftForge.EVENT_BUS.post(event);
                    if (!event.isCanceled())
                    {
                        Block block = state1.getBlock();
                        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock())
                        {
                            worldIn.notifyBlockUpdate(pos1, state1, state1, 3);
                            continue;
                        }
                        TileEntity tileentity = worldIn.getTileEntity(pos1);
                        if (tileentity != null)
                        {
                            Packet<?> pkt = tileentity.getUpdatePacket();
                            if (pkt != null)
                            {
                                ((EntityPlayerMP)player).connection.sendPacket(pkt);
                            }
                        }

                        boolean canHarvest = block.canHarvestBlock(worldIn, pos1, player);
                        boolean destroyed = block.removedByPlayer(state1, worldIn, pos1, player, canHarvest);
                        if (destroyed)
                        {
                            block.onPlayerDestroy(worldIn, pos1, state1); //onplayerdestroy
                        }
                        if (canHarvest && destroyed)
                        {
                            block.harvestBlock(worldIn, player, pos1, state1, tileentity, stack);
                            stack.damageItem(1, player);
                        }
                    }
                }
            }
        }

        return ret;
    }

Java:
java.util.concurrent.ExecutionException: java.lang.StackOverflowError
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_281]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_281]
    at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_281]
Caused by: java.lang.StackOverflowError
Caused by: java.lang.StackOverflowError

Ну и ещё одна проблема с топором, который должен создавать взрыв у моба, которым его ударили. Получаю бесконечный цикл ошибок и StackOverflowError пока майн не крашнется. Хотелось бы узнать способ решения данной проблемы...

Java:
public class AxeExplosion {
    @SubscribeEvent
    public void LivingAttack(LivingHurtEvent e) {
        if (e.getSource().getImmediateSource() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) e.getSource().getImmediateSource();
            if (player.isEntityAlive() && player.getHeldItemMainhand().getItem() instanceof ExplosionAxe) {
                if (!player.world.isRemote) {
                    player.world.createExplosion(player, e.getEntity().posX, e.getEntity().posY, e.getEntity().posZ, 4.0F, true);
                }
            }
        }
    }
}


Java:
[01:35:19] [Server thread/ERROR] [FML]: Index: 1 Listeners:
[01:35:19] [Server thread/ERROR] [FML]: 0: NORMAL
[01:35:19] [Server thread/ERROR] [FML]: 1: ASM: com.doctorspiele.customitem.event.AxeExplosion@516beb6 LivingAttack(Lnet/minecraftforge/event/entity/living/LivingHurtEvent;)V
[01:35:19] [Server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.entity.living.LivingHurtEvent@365c8781:
java.lang.StackOverflowError: null
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_281]
    at java.io.FilePermission.init(FilePermission.java:212) ~[?:1.8.0_281]
    at java.io.FilePermission.<init>(FilePermission.java:299) ~[?:1.8.0_281]
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888) ~[?:1.8.0_281]
    at java.io.File.exists(File.java:814) ~[?:1.8.0_281]
    at java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:434) ~[?:1.8.0_281]
    at java.io.File.getCanonicalPath(File.java:618) ~[?:1.8.0_281]
    at java.io.FilePermission$1.run(FilePermission.java:224) ~[?:1.8.0_281]
    at java.io.FilePermission$1.run(FilePermission.java:212) ~[?:1.8.0_281]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_281]
    at java.io.FilePermission.init(FilePermission.java:212) ~[?:1.8.0_281]
    at java.io.FilePermission.<init>(FilePermission.java:299) ~[?:1.8.0_281]
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888) ~[?:1.8.0_281]
    at java.io.File.exists(File.java:814) ~[?:1.8.0_281]
    at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:1379) ~[?:1.8.0_281]
    at sun.misc.URLClassPath.getResource(URLClassPath.java:249) ~[?:1.8.0_281]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[?:1.8.0_281]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363) ~[?:1.8.0_281]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_281]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362) ~[?:1.8.0_281]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_281]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[?:1.8.0_281]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_281]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_281]
    at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_281]
    at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:141) ~[log4j-api-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.impl.ThrowableProxy.loadClass(ThrowableProxy.java:549) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.impl.ThrowableProxy.toExtendedStackTrace(ThrowableProxy.java:661) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.impl.ThrowableProxy.<init>(ThrowableProxy.java:138) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.impl.ThrowableProxy.<init>(ThrowableProxy.java:122) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.impl.MutableLogEvent.getThrownProxy(MutableLogEvent.java:338) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter.format(ExtendedThrowablePatternConverter.java:61) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:38) ~[log4j-core-2.8.1.jar:2.8.1]
    at net.minecraftforge.server.terminalconsole.HighlightErrorConverter.format(HighlightErrorConverter.java:100) ~[forgeSrc-1.12.2-14.23.5.2847.jar:?]
    at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:38) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.layout.PatternLayout$PatternSelectorSerializer.toSerializable(PatternLayout.java:455) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.layout.PatternLayout$PatternSelectorSerializer.toSerializable(PatternLayout.java:444) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:208) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:57) ~[log4j-core-2.8.1.jar:2.8.1]
    at net.minecraftforge.server.terminalconsole.TerminalConsoleAppender.append(TerminalConsoleAppender.java:320) ~[forgeSrc-1.12.2-14.23.5.2847.jar:?]
    at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:448) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:433) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:403) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146) ~[log4j-core-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091) ~[log4j-api-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2011) ~[log4j-api-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1884) ~[log4j-api-2.8.1.jar:2.8.1]
    at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:854) ~[log4j-api-2.8.1.jar:2.8.1]
    at net.minecraftforge.fml.common.eventhandler.EventBus.handleException(EventBus.java:203) ~[EventBus.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:187) ~[EventBus.class:?]
    at net.minecraftforge.common.ForgeHooks.onLivingHurt(ForgeHooks.java:604) ~[ForgeHooks.class:?]
    at net.minecraft.entity.EntityLivingBase.damageEntity(EntityLivingBase.java:1572) ~[EntityLivingBase.class:?]
    at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1031) ~[EntityLivingBase.class:?]
    at net.minecraft.entity.passive.EntityAnimal.attackEntityFrom(EntityAnimal.java:82) ~[EntityAnimal.class:?]
    at net.minecraft.world.Explosion.doExplosionA(Explosion.java:166) ~[Explosion.class:?]
    at net.minecraft.world.WorldServer.newExplosion(WorldServer.java:1244) ~[WorldServer.class:?]
    at net.minecraft.world.World.createExplosion(World.java:2514) ~[World.class:?]
    at com.doctorspiele.customitem.event.AxeExplosion.LivingAttack(AxeExplosion.java:15) ~[AxeExplosion.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_15_AxeExplosion_LivingAttack_LivingHurtEvent.invoke(.dynamic) ~[?:?]
 
Последнее редактирование:

VeniVidiVici

Санта Барбарис
285
12
171
PlayerTickEvent:
@SubscribeEvent
public void onPlayerUpdate(PlayerTickEvent event){
    if(event.phase == Phase.END){
        EntityPlayer player = event.player;
        World world = player.world;
        if(world.getTotalWorldTime() % 36000 == 0){
            if(player.inventory.armorInventory.get(0).getItem() == Items.DIAMOND_LEGGINGS){
                player.getFoodStats().addStats(2, 2.0f);
            }
        }
    }
}
 
Сверху