1

This is a modded item for Minecraft, where it should create a Rocket Launcher that blows up parts of the world using a rocket. The problem is, whenever I fire it, it creates the explosion fine, but it does not update the chunks. As in, the blocks turn invisible, but their hit detection is still there. I have tried using the update functions from all sorts of projectiles that are in the game, to no avail. Does anyone have any ideas on what I should do to fix it?

EntityRocket

    package com.camp.entity;

    import java.util.List;

    import net.minecraft.block.Block;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.projectile.EntityThrowable;
    import net.minecraft.util.AxisAlignedBB;
    import net.minecraft.util.BlockPos;
    import net.minecraft.util.EnumParticleTypes;
    import net.minecraft.util.MathHelper;
    import net.minecraft.util.MovingObjectPosition;
    import net.minecraft.util.Vec3;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;

    public class EntityRocket extends EntityThrowable {

    int explosionRadius = 10;
    @SideOnly(Side.CLIENT)
    public boolean isInRangeToRenderDist(double distance)
    {
        double d1 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
        d1 *= 64.0D;
        return distance < d1 * d1;
    }

    public static World worldIn;

    protected void entityInit() {}

    public EntityRocket(World worldIn)
    {
        super(worldIn);
        this.worldIn=worldIn;
        this.setSize(1.0F,1.0F);
    }

    public EntityRocket(World worldIn, EntityLivingBase p_i1774_2_)
    {
        super(worldIn, p_i1774_2_);
        this.worldIn=worldIn;
    }

    public EntityRocket(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
        this.worldIn=worldIn;
    }


    @Override
    protected void onImpact(MovingObjectPosition p_70184_1_) {

         //this.WorldIn.createExplosion(riddenByEntity, entityRiderPitchDelta, entityRiderPitchDelta, entityRiderPitchDelta, distanceWalkedModified, inGround);
         worldIn.createExplosion(this, this.posX, this.posY, this.posZ, (float)(this.explosionRadius), true);
         this.isDead = true;

    }

}

Rocket

package com.camp.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

import com.example.Weaponry.Weaponry;




public class Rocket extends Item {

    public static final String name = "Rocket";

    public Rocket(){
        super();


        Item setUnlocalizedName = this.setUnlocalizedName(Weaponry.MODID + "_" + this.name);

        this.setCreativeTab(CreativeTabs.tabMisc);
        this.setMaxStackSize(16);


    }



}

Weaponry

package com.example.Weaponry;



import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;

import com.camp.item.ItemManager;

@Mod(modid = Weaponry.MODID, version = Weaponry.VERSION)
public class Weaponry
{
    public static final String MODID = "weaponry";
    public static final String VERSION = "1.0";

    ItemManager items = new ItemManager();

    @EventHandler
    public void preinit(FMLPreInitializationEvent event)
    {

        ItemManager.mainRegistry();

    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

        GameRegistry.addShapedRecipe(new ItemStack(items.MetalHandle), "i","i",'i', Items.iron_ingot);
        GameRegistry.addShapedRecipe(new ItemStack(items.LongBarrel), "iii", "   ", "iii", 'i', Items.iron_ingot);
        GameRegistry.addShapedRecipe(new ItemStack(items.ShortBarrel), "ii", "  ", "ii", 'i', Items.iron_ingot);
        GameRegistry.addShapelessRecipe(new ItemStack(items.WeaponGrip), items.MetalHandle, Items.rabbit_hide);
        GameRegistry.addShapedRecipe(new ItemStack(items.RocketLauncher),"lcs", " mg", 'l', items.LongBarrel, 'c', items.Chamber, 's', items.ShortBarrel, 'm', items.MetalHandle, 'g', items.WeaponGrip);
        GameRegistry.addShapedRecipe(new ItemStack(items.Rocket, 8), "h", "s", "f", 'h', items.RocketHead, 's', items.ShortBarrel, 'f', items.RocketFuselage);
        GameRegistry.addShapedRecipe(new ItemStack(items.RocketFuselage),"c", "m", 'c', items.CombustionChamber, 'm', items.MetalHandle);
        GameRegistry.addShapedRecipe(new ItemStack(items.RocketHead), " n ", "sts", " n ", 'n', items.NoseCone, 's', items.SulfurCompound, 't', Blocks.tnt);
        GameRegistry.addShapedRecipe(new ItemStack(items.Chamber), "ici", " t ", 'i', Items.iron_ingot, 'c', items.CombustionChamber, 't', items.Trigger);
        GameRegistry.addShapedRecipe(new ItemStack(items.Trigger), "ii", " f", 'i', Items.iron_ingot, 'f', Items.flint_and_steel);
        GameRegistry.addShapedRecipe(new ItemStack(items.CombustionChamber), " s ", "ibi", " t ", 's', items.SulfurCompound, 'i', Items.iron_ingot, 'b', items.ShortBarrel, 't', Blocks.tnt);
        GameRegistry.addShapedRecipe(new ItemStack(items.SulfurCompound), "gsg", "sgs", "gsg", 'g', Items.gunpowder, 's', items.Sulfur);
        GameRegistry.addShapedRecipe(new ItemStack(items.NoseCone), " i ", "i i", 'i', Items.iron_ingot);

        if(event.getSide() == Side.CLIENT)
        {
            RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();

            renderItem.getItemModelMesher().register(ItemManager.MetalHandle, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.MetalHandle.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.ShortBarrel, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.ShortBarrel.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.LongBarrel, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.LongBarrel.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.WeaponGrip, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.WeaponGrip.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.Chamber, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.Chamber.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.CombustionChamber, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.CombustionChamber.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.NoseCone, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.NoseCone.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.Rocket, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.Rocket.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.RocketFuselage, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.RocketFuselage.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.RocketHead, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.RocketHead.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.RocketLauncher, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.RocketLauncher.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.SulfurCompound, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.SulfurCompound.name, "inventory"));
            renderItem.getItemModelMesher().register(ItemManager.Trigger, 0, new ModelResourceLocation(this.MODID + ":" + ItemManager.Trigger.name, "inventory"));


        }

    }
}

ItemManager

package com.camp.item;

import net.minecraftforge.fml.common.registry.GameRegistry;
import sun.misc.Launcher;

public class ItemManager {

    public static RocketLauncher RocketLauncher;
    public static Rocket Rocket;
    public static LongBarrel LongBarrel;
    public static ShortBarrel ShortBarrel;
    public static MetalHandle MetalHandle;
    public static WeaponGrip WeaponGrip;
    public static Chamber Chamber;
    public static CombustionChamber CombustionChamber;
    public static NoseCone NoseCone;
    public static RocketFuselage RocketFuselage;
    public static RocketHead RocketHead;
    public static Sulfur Sulfur;
    public static SulfurCompound SulfurCompound;
    public static Trigger Trigger;

    public static void mainRegistry() {
        initializeItem();
        registerItem();
    }

    public static void initializeItem() {
        Rocket = new Rocket();
        RocketLauncher = new RocketLauncher();
        LongBarrel = new LongBarrel();
        ShortBarrel = new ShortBarrel();
        MetalHandle = new MetalHandle();
        WeaponGrip = new WeaponGrip();
        Chamber = new Chamber();
        CombustionChamber = new CombustionChamber();
        NoseCone = new NoseCone();
        RocketFuselage = new RocketFuselage();
        RocketHead = new RocketHead();
        Sulfur = new Sulfur();
        SulfurCompound = new SulfurCompound();
        Trigger = new Trigger();
    }

    public static void registerItem() {
        GameRegistry.registerItem(Rocket, Rocket.name);
        GameRegistry.registerItem(RocketLauncher, RocketLauncher.name);
        GameRegistry.registerItem(LongBarrel, LongBarrel.name);
        GameRegistry.registerItem(ShortBarrel, ShortBarrel.name);
        GameRegistry.registerItem(MetalHandle, MetalHandle.name);
        GameRegistry.registerItem(WeaponGrip, WeaponGrip.name);
        GameRegistry.registerItem(Chamber, Chamber.name);
        GameRegistry.registerItem(CombustionChamber, CombustionChamber.name);
        GameRegistry.registerItem(NoseCone, NoseCone.name);
        GameRegistry.registerItem(RocketFuselage, RocketFuselage.name);
        GameRegistry.registerItem(RocketHead, RocketHead.name);
        GameRegistry.registerItem(Sulfur, Sulfur.name);
        GameRegistry.registerItem(SulfurCompound, SulfurCompound.name);
        GameRegistry.registerItem(Trigger, Trigger.name);
    }

}

RocketLauncher

package com.camp.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

import com.camp.entity.EntityRocket;
import com.example.Weaponry.Weaponry;



public class RocketLauncher extends Item {

    public static final String name = "RocketLauncher";

    public RocketLauncher(){
        super();
        Item setUnlocalizedName = this.setUnlocalizedName(Weaponry.MODID + "_" + this.name);

        this.setCreativeTab(CreativeTabs.tabMisc);
        this.setMaxStackSize(1);

    }

    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
    {
        if (worldIn.isRemote)
        {
            if (playerIn.inventory.hasItem(ItemManager.Rocket)){
                if (!playerIn.capabilities.isCreativeMode)
                {
                    playerIn.inventory.consumeInventoryItem(ItemManager.Rocket);
                }
                worldIn.spawnEntityInWorld(new EntityRocket(worldIn, playerIn));
            }

        }

        return itemStackIn;
    }



}
4

1 回答 1

0

This in RocketLauncher:

if (worldIn.isRemote)

Should be

if (!worldIn.isRemote)

You are firing the rocket at this moment only clientside. Which removes the blocks visibly, but without a chunk update, you dont notice that you did actually nothing.

At this point your server side never gets the chance to spawn the entity. So it all happens clientside. Which seems to do the same, but the server who decides your movements disagrees.

With relogging or forcing a chunk update via the hotkeys you can see you achieved nothing and it all was but an illusion.

You could use it in a potion effect :P shellshock potion, all missiles, none real :P

于 2015-07-10T06:27:33.877 回答