这是Minecraft的一个改装项目,它应该创建一个使用火箭炸毁世界部分地区的火箭发射器。问题是,无论何时我开火,它都会产生爆炸,但它不会更新块。如同,块变得不可见,但它们的命中检测仍然存在。我尝试过使用游戏中各种射弹的更新功能,但无济于事。有没有人对我应该做些什么来解决它?
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;
}
}
火箭
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);
}
}
武器
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;
}
}
答案 0 :(得分:0)
这在RocketLauncher中:
if (worldIn.isRemote)
应该是
if (!worldIn.isRemote)
此刻你只是在客户端射击火箭。这明显地删除了块,但没有块更新,你没有注意到你实际上什么也没做。
此时,您的服务器端永远不会有机会产生实体。所以这一切都发生在客户端。这似乎也是如此,但决定你的动作的服务器不同意。
通过热键重新启动或强制更新块,你可以看到你什么都没做,这只是一种幻觉。
你可以在药水效果中使用它:P shellshock药水,所有导弹,没有真实:P