ustc-zzzz / fmltutor Goto Github PK
View Code? Open in Web Editor NEWMinecraft 1.8.9 FML Mod Development Tutorial
Home Page: https://fmltutor.ustc-zzzz.net/
License: MIT License
Minecraft 1.8.9 FML Mod Development Tutorial
Home Page: https://fmltutor.ustc-zzzz.net/
License: MIT License
呵呵呵
催更玩家NBT
由于有三个物品槽于是
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.equals(capability))
{
@SuppressWarnings("unchecked")
T result = null;
if (facing == EnumFacing.DOWN)
{
result = (T) this.itemOut;
}
else if (facing == EnumFacing.UP)
{
result = (T) this.itemIn;
}
else
{
result = (T) this.itemFuel;
}
return result;
}
return super.getCapability(capability, facing);
}
为什么会NPE?
由于不知如何定义display项,所以方块在手上第三人称时会变得无比巨大
希望作者能将教程里的版本更新到1.10,万分感谢~。
因为自己的网实在太差无法从forge服务器下载MDK所以不得不在mcbbs下了别人下载完的MDK,但是版本是1.10.2的。。。。
跟着教程学习的时候发现1.10和1.8已经有不小的区别了,比如说教程里的Material.ground在1.10里变成了Material.GROUND。this.setStepSound(soundTypeGrass)这句里soundTypeGrass找不到了(还好不很重要所以我删了这句话)。还有GameRegistry.registerBlock等方法不推荐使用了,doc里说使用register但我不知道怎么用。。。。。
另外我觉得教程写的很好,就是BlockState部分有点没看懂,准备再研究一下。
public BlockGrassBlock()
{
super(Material.ground);
this.setUnlocalizedName("grassBlock");
this.setHardness(0.5F);
this.setStepSound(soundTypeGrass);
}
若渲染部分过难,是否可以将世界生成提前?
ToolMaterial中建议添加下文代码的提醒:
ItemLoader.java中
public static final Item.ToolMaterial REDSTONE = EnumHelper.addToolMaterial("REDSTONE", 3, 16, 16.0F, 0.0F, 10);
必须放到
public static ItemPickaxe redstonePickaxe = new ItemRedstonePickaxe();
之前,否则会报错。
反编译就借助fernflower-fixed
java -jar fernflower-fixed.jar minecraft-xxx.jar ./output/
但是之后使用fields.csv、methods.csv、params.csv、以及*.srg的映射文件来进行反混淆该用什么工具的什么命令进行?
在1.9的时候,
net.minecraft.client.resources.model.ModelResourceLocation
被移动到了
net.minecraft.client.renderer.block.model
下面
私以为modid不仅仅使用字母,应该是最好使用小写字母。在mc(1.9.4)里面读取的modid文件夹的时候,会默认把大写变成小写,所以读取路径是小写的。一个小小坑。
GUI可是一大难点,求更新~
当我想创建一个新斧子的时候,代码如下
ItemSilverAxe.java
package firok.soulcraft.item;
import creativetab.CreativeTabsLoader;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraftforge.common.util.EnumHelper;
public class ItemSilverAxe extends ItemAxe
{
public static final Item.ToolMaterial SILVER = EnumHelper.addToolMaterial("SILVER", 3, 16, 16.0F, 0.0F, 10);
public ItemSilverAxe()
{
super(SILVER);
this.setUnlocalizedName("silverAxe");
this.setCreativeTab(CreativeTabsLoader.tabSoulCraft);
}
}
然后就报错了
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
at net.minecraft.item.ItemAxe.<init>(ItemAxe.java:19)
at firok.soulcraft.item.ItemSilverAxe.<init>(ItemSilverAxe.java:15)
at firok.soulcraft.item.ItemLoader.<clinit>(ItemLoader.java:17)
问题代码是这一行
super(SILVER);
如果把
import net.minecraft.item.ItemAxe;
public class ItemSilverAxe extends ItemAxe;
改成
import net.minecraft.item.ItemPickaxe;
public class ItemSilverAxe extends ItemPickaxe;
就没有问题了
是不是1.10.2版本MC不同工具需要用不同方式设置材质啊?
下面是完整的错误报告
---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.
Time: 17-4-4 下午12:50
Description: There was a severe problem during mod loading that has caused the game to fail
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Soul Craft (soulcraft)
Caused by: java.lang.ExceptionInInitializerError
at firok.soulcraft.common.CommonProxy.preInit(CommonProxy.java:15)
at firok.soulcraft.client.ClientProxy.preInit(ClientProxy.java:15)
at firok.soulcraft.SoulCraft.preInit(SoulCraft.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:602)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:243)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:221)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:145)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:614)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:257)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:477)
at net.minecraft.client.Minecraft.run(Minecraft.java:386)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
at net.minecraft.item.ItemAxe.<init>(ItemAxe.java:19)
at firok.soulcraft.item.ItemSilverAxe.<init>(ItemSilverAxe.java:15)
at firok.soulcraft.item.ItemLoader.<clinit>(ItemLoader.java:17)
... 46 more
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- System Details --
Details:
Minecraft Version: 1.10.2
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_121, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 713195224 bytes (680 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.32 Powered by Forge 12.18.3.2185 5 mods loaded, 5 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCH mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)
UCH FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.10.2-12.18.3.2185.jar)
UCH Forge{12.18.3.2185} [Minecraft Forge] (forgeSrc-1.10.2-12.18.3.2185.jar)
UCH examplemod{1.0} [examplemod] (bin)
UCE soulcraft{0.1.0} [Soul Craft] (bin)
Loaded coremods (and transformers):
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 375.57' Renderer: 'GeForce GTX 950M/PCIe/SSE2'
被催更一段时间就不更了= =我要催更
idea大法好
1.11 中 modid 必须为小写,且不能超过 64 个字符
net.minecraftforge.fml.common.FMLModContainer
:
if (modid.length() > 64)
{
FMLLog.bigWarning("The modid %s is longer than the recommended maximum of 64 characters. Truncation is enforced in 1.11", modid);
throw new IllegalArgumentException(String.format("The modid %s is longer than the recommended maximum of 64 characters. Truncation is enforced in 1.11", modid));
}
if (!modid.equals(modid.toLowerCase(Locale.ENGLISH)))
{
FMLLog.bigWarning("The modid %s is not the same as it's lowercase version. Lowercasing is enforced in 1.11", modid);
throw new IllegalArgumentException(String.format("The modid %s is not the same as it's lowercase version. Lowercasing will be enforced in 1.11", modid));
}
如果不按要求写 modid 就要 throw 了。
可以用 snake_case
(commit 7fe8c48)
话说infinity studio还招人嘛?最近在学习mod开发,Java基础觉得还可以,想向大佬们学习QAQ。。。
作者求你快点更新IGuiHandler的部分吧。。。
在“运行、构建和发布Mod的方法”上面6行的“然后打开IDE,将工程目录切换到这个目录”,其中“这个目录到底是什么没写清楚”,应该是把工程目录切换到mdk目录下的eclipse(或者idea)而不是mdk目录
請問 1.7.10 是不是沒有ModelLoader?
我们注意到,和旧版本的MCP相比,新版本的MCP更加具体化了方法名,实际上,有的时候,MCP还会为部分方法指定了泛型。
建议在这一行后面加上:
你可以在MCPBot(http://export.mcpbot.bspk.rs/)获得1.7.10以上的所有MCP版本。
接口函数参数写了两个IChunkProvider,
public void generate
(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator,
IChunkProvider chunkProvider)
感觉第一个应该是IChunkGenerator
public void generate
(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
IChunkProvider chunkProvider)
因为我用的1.8.9 stable-20,使用的是IChunkGenerator。
可能是版本更迭的原因吧,看code里面也是IChunkProvider,如果是这么明显的错误,IDE应该会报错的。1.8版本的这个接口处理得不清真╮(╯Д╰)╭。
minecraft {
replace "@version@", project.version
}
ForgeGradle有问题,这个replace
不能正常工作。希望您将这段移除。
FMLCommonHandler.instance().bus().register(this);
我在1.7.10中要加入这個才能觸發那個Input Event,
在高版本中是不需要的嗎?
没错,就是net.minecraftforge.fml.common.network.FMLEventChannel
。
(虽然我大概知道怎么用,2333333333333333333333)
“Update quickly please”
在forge-1.9-12.16.1.1887中
public class EntityMaid extends EntityCow {
public int b;
public EntityMaid(World worldIn) {
super(worldIn);
this.setSize(0.6F, 1.8F);
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
}
@Override
public void writeEntityToNBT(NBTTagCompound tagCompound){
super.writeEntityToNBT(tagCompound);
tagCompound.setInteger("iconType", this.b);
}
@Override
public void readEntityFromNBT(NBTTagCompound tagCompound){
super.readEntityFromNBT(tagCompound);
this.b=tagCompound.getInteger("iconType");
}
@Override
public boolean processInteract(EntityPlayer player, EnumHand p_184645_2_, ItemStack stack) {
if (stack != null && stack.getItem() == Items.stick){
this.b=(b+1)%5;
}
else if(stack != null && stack.getItem() != Items.bucket){
return super.processInteract(player, p_184645_2_, stack);
}
return true;
}
}
public class RenderEntityMaid extends RenderLiving{
private static final ResourceLocation MAID_TEXTURE1 = new ResourceLocation(Qyyh.MODID + ":" + "textures/entity/maid1.png");
private static final ResourceLocation MAID_TEXTURE2 = new ResourceLocation(Qyyh.MODID + ":" + "textures/entity/maid2.png");
private static final ResourceLocation MAID_TEXTURE3 = new ResourceLocation(Qyyh.MODID + ":" + "textures/entity/maid3.png");
private static final ResourceLocation MAID_TEXTURE4 = new ResourceLocation(Qyyh.MODID + ":" + "textures/entity/maid4.png");
private static final ResourceLocation MAID_TEXTURE5 = new ResourceLocation(Qyyh.MODID + ":" + "textures/entity/maid5.png");
public RenderEntityMaid(RenderManager renderManager) {
super(renderManager, new ModelPlayer(0.0F, false), 0.5F);
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
int iconType=((EntityMaid)entity).b;
switch (iconType) {
case 0:
return RenderEntityMaid.MAID_TEXTURE1;
case 1:
return RenderEntityMaid.MAID_TEXTURE2;
case 2:
return RenderEntityMaid.MAID_TEXTURE3;
case 3:
return RenderEntityMaid.MAID_TEXTURE4;
case 4:
return RenderEntityMaid.MAID_TEXTURE5;
default:
return RenderEntityMaid.MAID_TEXTURE5;
}
}
}
请问哪里有错误 每次退出游戏在进都是皮肤1
1.9的DataWatcher完全不会用
抱歉作者又是我,我问题比较多。
请问为什么Gui和TileEntity的ItemStackHandler内容不同步?也就是说将物品放入ItemStack内本应该减少的,但是不变。而且关闭GUI以后内容消失。
this.tileentity = tile;
for (int i = 0; i < 3; ++i)
{
this.addSlotToContainer(new SlotItemHandler(this.tileentity.aInventory, i, 38 + i * 32, 20));
}
this.addSlotToContainer(new SlotItemHandler(this.tileentity.bInventory,0,38 + 4 * 32, 20));
最后返回的是null(return null;)这样在最后一个参数完成后,再输入下一个按tab按键的时候,控制台会报错,应该修改成父类的返回值 return Collections.emptyList();
在1.7.10中 構造方法是傳入ID (int) 而不是名字
我傳入了36會崩潰 (可能因為原本是沒有此ID的)
我傳入了20 (原版為凋零的效果)後, 會和凋零重疊了...
請問1.7.10要怎麼做?
这是我目前的配置
minecraft {
version = "1.9.4-12.17.0.1962"
runDir = "run"
mappings = "snapshot_20160613"
}
我想将mappings换成stable_#
这样的稳定版本,请问该去哪里寻找mappings稳定版与minecraft版本的对照表
1.9前可以透过net.minecraftforge.common.ChestGenHooks.addItem(String,WeightedRandomChestContent)加入至宝箱。唯1.9后(包括1.9)使用LootTable机制,假如不直接修改档案便不能放入。(net.minecraft.world.storage.loot好像有有用的东西,但不知道怎么用)
1.7.10这么多人用,开发1.8,1.9没地方用啊
应该在设置工作空间那里建议国内用户直接使用Gradle而不是gradlew gradlew慢到爆
然后给出一个下载地址
我在1.10.2中编写mod时,已经注册过方块的ItemBlock,在为方块添加模型和材质时使用的getItemFromBlock(block)方法得到null值,导致游戏出现NullPointerException。
同时getBlockRegistry()也已被弃用。
求解啦。
在 IGuiHandler 小节中应该是 位于客户端最顶端的对象是GuiContainer,而不是 位于服务端最顶端的对象是GuiContainer
教程里是在对应工具的class内创建了材质
public static final Item.ToolMaterial NAME_MATERIAL= EnumHelper.addToolMaterial("NAME_MATERIAL", 3, 16, 16.0F, 0.0F, 10);
然后调用了super()初始化
但是这样每一种工具都会运行一遍同样的代码吧..
如果把初始化工具材质的代码放在一起
比如放进ConfigLoader内 然后再
super(ConfigLoader.NAME_MATERIAL ,8.0F,-3.1F);
这样应该效率更高而且更便于管理材质属性
如题,怎么办啊😱
如果没有API文档的话,想要实现教程中没有的功能,只能去看源码么?另外感谢作者的教程~
像2.1.2的事件教程當中,
方塊激活化判斷
if (!event.isCanceled() && !worldIn.isRemote) {
worldIn.setBlockToAir(pos);
return true;
}
為什么要判斷要在客戶端上把方塊填空, 並且截斷事件??
1.7 节中出现的代码:
item.goldenEgg.name=Golden Egg
tile.grassBlock.name=Grass Block
其中不包含Mod id的写法已被废弃,等待修改为:
item.fmltutor.goldenEgg.name=Golden Egg
tile.fmltutor.grassBlock.name=Grass Block
我仿照烈焰人设计了一个AI,可是弄出来之后他经常乱发,而且没发数量不定,有时候直接疯了一样连射……而且他本身虽然是个远攻,但是每次发射时都要走近目标,像小白那样高级的AI是怎么实现的呢
这是 我的代码
package captain.pegger.kingofground.entity;
import javax.annotation.Nullable;
import captain.pegger.kingofground.item.ItemLoader;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIAttackRangedBow;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
public class EntityMage extends EntityTameable
{
public EntityMage(World worldIn)
{
super(worldIn);
this.setSize(0.8F, 1.8F);
this.setTamed(false);
}
protected void initEntityAI()
{
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityMage.AIFireballAttack(this));
this.tasks.addTask(3, new EntityAIAttackMelee(this, 1.0D, false));
this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 6.0F, 16.0F));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(9, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true, new Class[0]));
if (!this.isTamed())
{
this.targetTasks.addTask(5, new EntityAINearestAttackableTarget(this, EntityPlayer.class, false));
}
}
@Override
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3600001192092896D);
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(25.0D);
this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(2.0D);
}
@Override
protected void entityInit()
{
super.entityInit();
}
protected void playStepSound(BlockPos pos, Block blockIn)
{
this.playSound(SoundEvents.ENTITY_HORSE_STEP, 0.15F, 1.0F);
}
@Override
public EntityAgeable createChild(EntityAgeable ageable)
{
return this;
}
@Override
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
}
@Override
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
}
@Override
protected SoundEvent getHurtSound()
{
return SoundEvents.ENTITY_VILLAGER_HURT;
}
@Override
protected SoundEvent getDeathSound()
{
return SoundEvents.ENTITY_VILLAGER_DEATH;
}
@Override
protected float getSoundVolume()
{
return 1F;
}
@Override
public void onLivingUpdate()
{
super.onLivingUpdate();
}
@Override
public float getEyeHeight()
{
return this.height;
}
@Override
public boolean attackEntityAsMob(Entity entityIn)
{
boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this),
((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));
if (flag)
{
this.applyEnchantments(this, entityIn);
}
return flag;
}
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack)
{
if (this.isTamed())
{
if (stack != null)
{
if (stack.getItem() instanceof ItemFood)
{
ItemFood itemfood = (ItemFood) stack.getItem();
if ((this.getHealth() < 25.0F))
{
if (!player.capabilities.isCreativeMode)
{
--stack.stackSize;
}
this.heal(itemfood.getHealAmount(stack));
return true;
}
}
if (this.isOwner(player) && !this.worldObj.isRemote && !this.isBreedingItem(stack))
{
this.setAttackTarget((EntityLivingBase) null);
}
}
}
else if (stack != null && stack.getItem() == Items.DIAMOND)
{
if (!player.capabilities.isCreativeMode)
{
--stack.stackSize;
}
if (!this.worldObj.isRemote)
{
if (this.rand.nextInt(1) == 0)
{
this.setTamed(true);
this.navigator.clearPathEntity();
this.setAttackTarget((EntityLivingBase) null);
this.setHealth(25.0F);
this.setOwnerId(player.getUniqueID());
this.playTameEffect(true);
this.worldObj.setEntityState(this, (byte) 7);
}
else
{
this.playTameEffect(false);
this.worldObj.setEntityState(this, (byte) 6);
}
}
return true;
}
return super.processInteract(player, hand, stack);
}
@Override
public boolean shouldAttackEntity(EntityLivingBase target, EntityLivingBase owner)
{
if (!(target instanceof EntityCreeper) && !(target instanceof EntityGhast))
{
if (target instanceof EntityRobber || target instanceof EntityMercenary || target instanceof EntityWolf)
{
EntityTameable entitywolf = (EntityTameable) target;
if (entitywolf.isTamed() && entitywolf.getOwner() == owner)
{
return false;
}
}
return target instanceof EntityPlayer && owner instanceof EntityPlayer
&& !((EntityPlayer) owner).canAttackPlayer((EntityPlayer) target) ? false
: !(target instanceof EntityHorse) || !((EntityHorse) target).isTame();
}
else
{
return false;
}
}
@Override
public void onDeath(DamageSource source)
{
if (!this.worldObj.isRemote)
{
this.entityDropItem(new ItemStack(Items.GOLD_NUGGET, 2), 1F);
this.entityDropItem(new ItemStack(ItemLoader.summonstone, 1), 1F);
if (this.rand.nextInt(2) >= 1)
{
this.entityDropItem(new ItemStack(ItemLoader.summonstone, 2), 1F);
}
super.onDeath(source);
}
}
public static class AIFireballAttack extends EntityAIBase
{
private final EntityMage mage;
private int attackTime;
public AIFireballAttack(EntityMage mageIn)
{
this.mage = mageIn;
}
@Override
public boolean shouldExecute()
{
EntityLivingBase target = this.mage.getAttackTarget();
return target != null && target.isEntityAlive();
}
@Override
public void startExecuting()
{
}
@Override
public void updateTask()
{
--this.attackTime;
EntityLivingBase target = this.mage.getAttackTarget();
double d0 = this.mage.getDistanceSqToEntity(target);
if (d0 < 4.0D)
{
this.attackTime = 20;
this.mage.attackEntityAsMob(target);
this.mage.getMoveHelper().setMoveTo(target.posX, target.posY, target.posZ, 1.0D);
}
else if (d0 < 256.0D)
{
this.attackTime = 100;
double d1 = target.posX - this.mage.posX;
double d2 = target.getEntityBoundingBox().minY + target.height / 2.0F
- (this.mage.posY + this.mage.height / 2.0F);
double d3 = target.posZ - this.mage.posZ;
float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
this.mage.worldObj.playEvent((EntityPlayer) null, 1018,
new BlockPos((int) this.mage.posX, (int) this.mage.posY, (int) this.mage.posZ), 0);
EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.mage.worldObj, this.mage,
d1 + this.mage.getRNG().nextGaussian() * f, d2, d3 + this.mage.getRNG().nextGaussian() * f);
entitysmallfireball.posY = this.mage.posY + this.mage.height / 2.0F + 0.5D;
this.mage.worldObj.spawnEntityInWorld(entitysmallfireball);
this.mage.getLookHelper().setLookPositionWithEntity(target, 10.0F, 10.0F);
}
else
{
this.mage.getNavigator().clearPathEntity();
this.mage.getMoveHelper().setMoveTo(target.posX, target.posY, target.posZ, 1.0D);
}
super.updateTask();
}
}
}
如果用空桶右键点击空中,游戏会终止。
代码应该改为
` @SubscribeEvent
public void onFillBucket(FillBucketEvent event) {
Fluid fluid = null;
BlockPos blockpos = null;
IBlockState blockState = null;
RayTraceResult tar = event.getTarget();
if (tar != null) {
blockpos = tar.getBlockPos();
blockState = event.world.getBlockState(blockpos);
fluid = FluidRegistry.lookupFluidForBlock(blockState.getBlock());
}
if (fluid != null && new Integer(0).equals(blockState.getValue(BlockFluidBase.LEVEL)))
{
FluidStack fluidStack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
event.world.setBlockToAir(blockpos);
event.result = FluidContainerRegistry.fillFluidContainer(fluidStack, event.current);
event.setResult(Result.ALLOW);
}
}
新建一个包(这里是com.github.ustc_zzzz.fmltutor),并在其中新建一个类(强烈建议这个类的类名和你的Mod名称相同),这就是这个Mod的主类了。
把下面的代码抄进你新建的类中,下面我会解释为什么要这么做。
我把代码抄进去后 第三行:
import com.github.ustc_zzzz.fmltutor.common.CommonProxy;
提示:无法解析导入 com.github.ustc_zzzz.fmltutor.common
用的是eclipse。
类名包名都是照着你教程来的 其他地方没错误
这是怎么回事
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.