这个问题与我的世界1.9版有关
我是改装现场的新手,我的测试木原木块遇到了麻烦。我为我的测试木块扩展了BlockLog类。但是,每次我尝试在游戏中放置积木时,游戏都会崩溃。这是我的原木课:
package bravoman.testmod.blocks;
import net.minecraft.block.BlockLog;
public class MangoLog extends BlockLog{
public MangoLog() {
super();
}
}
最近,我一直在关注youtube上的简单教程,这就是我学会了如何创建新块的方法。我更进一步,而不是扩展
Block
,而是继续扩展了BlockLog
。我已经尝试了BlockLog类,试图重写某些方法或添加枚举类型,但无济于事。我相信遗漏了大量代码,但是如果没有进一步的经验来修改Minecraft,我就会陷入困境。我也在下面的minecraft forums .Crash日志中问了这个问题。任何帮助,将不胜感激。
---- Minecraft Crash Report ----
// Why is it breaking :(
Time: 4/25/16 1:22 PM
Description: Unexpected error
java.lang.IllegalArgumentException: Cannot set property PropertyEnum{name=axis, clazz=class net.minecraft.block.BlockLog$EnumAxis, values=[x, y, z, none]} as it does not exist in BlockStateContainer{block=mm:mango_log, properties=[axis]}
at net.minecraft.block.state.BlockStateContainer$StateImplementation.withProperty(BlockStateContainer.java:204)
at net.minecraft.block.BlockLog.onBlockPlaced(BlockLog.java:51)
at net.minecraft.item.ItemBlock.onItemUse(ItemBlock.java:57)
at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:156)
at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:484)
at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1597)
at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2268)
at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2052)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1840)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1114)
at net.minecraft.client.Minecraft.run(Minecraft.java:401)
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)
最佳答案
这是由于您使用了BlockLog
,它具有一些指向状态的信息,但需要子类来实现。他们没有完全实现它,因为日志通常代表几种不同的类型,并且没有逻辑基础。但是,它不会使状态方法抽象化,因此尚不清楚是否需要这样做。BlockLog
扩展了BlockRotatedPillar
,后者定义了自己的状态信息。但是,由于日志具有附加状态(无方向且四面吠叫),因此不使用支柱的状态信息,而是使用单独的状态值。但是BlockLog
不会注册它,并且希望子类这样做(因为它们无论如何都会注册其他信息,这将迫使该信息被覆盖)。由于未进行注册,因此使用了错误的轴信息,并且当游戏需要柱状轴信息时,日志会尝试设置日志轴信息。
要解决此问题,请查看BlockLog
的现有实现:BlockOldLog
(用于处理橡木,桦木,云杉和丛林)和BlockNewLog
(用于进行相思和深色橡木)。
对于您的情况(假设您不希望有任何变体),以下方法可能会起作用(不过,我尚未对其进行测试):
package bravoman.testmod.blocks;
import net.minecraft.block.BlockLog;
public class MangoLog extends BlockLog{
public MangoLog()
{
super();
this.setDefaultState(this.blockState.getBaseState().withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState state = this.getDefaultState();
switch (meta & 0b1100)
{
case 0b0000:
state = state.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
break;
case 0b0100:
state = state.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
break;
case 0b1000:
state = state.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
break;
case 0b1100:
state = state.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
break;
}
return state;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X: return 0b0100;
case Y: return 0b0000;
case Z: return 0b1000;
case NONE: return 0b1100;
}
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {LOG_AXIS});
}
}
重要的部分是您需要处理
LOG_AXIS
属性。如果确实要具有多个变体,请查看
BlockOldLog
或BlockNewLog
作为示例。请注意,使用BlockNewLog
时,诸如damageDropped
和createStackedBlock
之类的方法会从变体中减去4,因为它基于木板ID,其中acadia和深色橡木与橡木,桦木,丛林在同一块中的ID 4和5和云杉。使用您自己的日志,通常不需要这样做。关于java - 放置自定义木刻时,游戏会崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36847653/