Jump to content

Recommended Posts

Posted (edited)

So I made this mod a while ago where I had an item, that adds a lightningboltentity to whatever block you look. Turns out that it doesn't function properly on a dedicated server. Can anyone tell me what the issue is?

Here is the code:

 

package com.dersichkeinennamenausdenkenkann.somethings.items;

import java.util.List;
import com.dersichkeinennamenausdenkenkann.somethings.SomeMod;
import com.dersichkeinennamenausdenkenkann.somethings.util.helpers.KeyHelpStuff;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.effect.LightningBoltEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;


public class Cross extends Item {


    public Cross() {
        super(new Item.Properties()

                .group(SomeMod.SomethingItemGroup.instance)
                .maxStackSize(1)
        );
    }

    public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn)
    {
        if(KeyHelpStuff.isHoldingShift())
        {
            tooltip.add(new StringTextComponent("With this Item, you will be able to summon some dawm sick lightningbolts. But they hurt... Just so you know"));
        }
        else {
            tooltip.add(new StringTextComponent("Hold" + "\u00A7b" + " SHIFT " + "\u00A7f" + "for more Information!"));
        }
        super.addInformation(stack, worldIn, tooltip, flagIn);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn){

        if(!(worldIn instanceof ServerWorld)) return new ActionResult<>(ActionResultType.PASS, playerIn.getHeldItem(handIn));

        RayTraceResult lookingAt = Minecraft.getInstance().objectMouseOver;
        if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK) {
            double x = lookingAt.getHitVec().getX();
            double y = lookingAt.getHitVec().getY();
            double z = lookingAt.getHitVec().getZ();

            ((ServerWorld) worldIn).addLightningBolt(new LightningBoltEntity(worldIn, x, y, z, false));
        }
            // not looking at block

        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

    @Override
    public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
        return false;
    }
}

 

or is it something other than the lightning that is added?

Edited by NoNameGuy
Posted

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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