Jump to content

[1.10.2]Get problems with extend block state and custom model


Recommended Posts

Posted (edited)

All codes : GitHub

Model here

      1.The block (codes here) can place ,and model works. But get crash when reload world(saved game and rejoin)  (I think it cause by can't get extend block state).  game log(L729 crash)

I find that 

Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.bxzmod.energyconversion.blocks.blockmodel.PowerBlockBakedModel.func_188616_a(PowerBlockBakedModel.java:142) ~[PowerBlockBakedModel.class:?]

In my code is (here)

	@Override
	public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
	{
		IExtendedBlockState extendedBlockState;
		List<BakedQuad> quads = new ArrayList<>();

		if (state == null)
		{
			for (EnumFacing f : EnumFacing.values())
				quads.add(this.setQuad(f, 0));
			return quads;
		} else
			extendedBlockState = (IExtendedBlockState) state;
		if (side == null)
		{
			return Collections.emptyList();
		}
		byte[] a = extendedBlockState.getValue(PowerBlock.SIDE_CONFIG);
		quads.add(this.setQuad(side, a[side.getIndex()]));
		return quads;
	}

Does this crash mean that the model is loaded earlier than TileEntity?Or the parameter "state" not from block.getExtendedState ?

And how can I repair it?

     2.When I change extend block state in TileEntity(codes here),it doesn't immediate refresh. I need to place a block to refresh it.

	public void setSideType(EnumFacing form)
	{
		this.bSideType[form.getIndex()] = (byte) (this.bSideType[form.getIndex()] == 1 ? 0 : 1);
		IExtendedBlockState extendedBlockState = (IExtendedBlockState) this.worldObj.getBlockState(this.pos);
		extendedBlockState = extendedBlockState.withProperty(PowerBlock.SIDE_CONFIG, this.bSideType);
	}

Does this can update extend block state?If not ,how can i update extend block state ,I tried to use this.worldObj.setBlockState ,but crashed.

    3.Something I don't know what is wrong.

Block side render was effected with it's opposite side.(codes here)

This code from Mcjty's tutorial(here)(I don't understand what this mean)(Can someone explain it for me?)

	private BakedQuad createQuad(Vec3d v1, Vec3d v2, Vec3d v3, Vec3d v4, int num)
	{
		Vec3d normal = v1.subtract(v2).crossProduct(v3.subtract(v2));
		UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
		builder.setTexture(sprite[num]);
		putVertex(builder, normal, v1.xCoord, v1.yCoord, v1.zCoord, 0, 0, num);
		putVertex(builder, normal, v2.xCoord, v2.yCoord, v2.zCoord, 0, 16, num);
		putVertex(builder, normal, v3.xCoord, v3.yCoord, v3.zCoord, 16, 16, num);
		putVertex(builder, normal, v4.xCoord, v4.yCoord, v4.zCoord, 16, 0, num);
		return builder.build();
	}

	private void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, float u,
			float v, int num)
	{
		for (int e = 0; e < format.getElementCount(); e++)
		{
			switch (format.getElement(e).getUsage())
			{
			case POSITION:
				builder.put(e, (float) x, (float) y, (float) z, 1.0f);
				break;
			case COLOR:
				builder.put(e, 1.0f, 1.0f, 1.0f, 1.0f);
				break;
			case UV:
				if (format.getElement(e).getIndex() == 0)
				{
					u = sprite[num].getInterpolatedU(u);
					v = sprite[num].getInterpolatedV(v);
					builder.put(e, u, v, 0f, 1f);
					break;
				}
			case NORMAL:
				builder.put(e, (float) normal.xCoord, (float) normal.yCoord, (float) normal.zCoord, 0f);
				break;
			default:
				builder.put(e);
				break;
			}
		}
	}

tHiIe.pngtHAGd.pngtHkPH.png

 

 

Edited by bxzsj
stupid wrong
Posted

You don't needed extended states for this, just use getActualState and return whatever booleans you want as separate properties.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Oh,thank you! I change it to

	@Override
	public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
	{
		IExtendedBlockState s = (IExtendedBlockState) state;
		PowerBlockTileEntity te = (PowerBlockTileEntity) worldIn.getTileEntity(pos);
		return s.withProperty(SIDE_CONFIG, te.getByte());
	}

But , suddenly find that this doesn't work:  (TileEntity)

	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbt)
	{

		super.writeToNBT(nbt);
		nbt = storage.writeToNBT(nbt);
		if (totalEnergy < 0)
		{
			totalEnergy = 0;
		}
		nbt.setInteger("totalEnergy", totalEnergy);
		nbt.setByteArray("sideType", this.bSideType);//this don't work
		return nbt;
	}

game log show that

MC: Caused by: java.lang.ArrayIndexOutOfBoundsException
MC:     at java.lang.System.arraycopy(Native Method) ~[?:1.8.0_141]
MC:     at com.bxzmod.energyconversion.tileentity.PowerBlockTileEntity.func_145839_a(PowerBlockTileEntity.java:103) ~[PowerBlockTileEntity.class:?]

the code

	@Override
	public void readFromNBT(NBTTagCompound nbt)
	{

		super.readFromNBT(nbt);
		this.totalEnergy = nbt.getInteger("totalEnergy");
		System.arraycopy(nbt.getByteArray("sideType"), 0, this.bSideType, 0, 6);//here the problem
		if (totalEnergy > capacity)
		{
			totalEnergy = capacity;
		}
		storage.readFromNBT(nbt);
	}

and my baked model seems not work 

I tried to use this:  (BakedModel)

LOGGER.info(extendedBlockState.getValue(PowerBlock.SIDE_CONFIG).toString());
Minecraft.getMinecraft().thePlayer.addChatMessage(
		new TextComponentString(extendedBlockState.getValue(PowerBlock.SIDE_CONFIG).toString()));

to check block state work or not. But I didn't see any message show in game log and chat bar.

Posted

I didn't say to make your existing property a property on getActualState I said to use a series of booleans.

As in, new properties.

Like the Fence.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

I have solved the model crash. But,my TileEntity doesn't save data.

It reported a problem: (log L673)

Caused by: java.lang.NullPointerException
	at com.bxzmod.energyconversion.tileentity.PowerBlockTileEntity.func_145839_a(PowerBlockTileEntity.java:109) ~[PowerBlockTileEntity.class:?]

the code is:

	@Override
	public void readFromNBT(NBTTagCompound nbt)
	{
		super.readFromNBT(nbt);
		//LOGGER.info("read" + nbt.toString());
		NBTTagList list = new NBTTagList();
		this.totalEnergy = nbt.getInteger("totalEnergy");
		list = (NBTTagList) nbt.getTag("sideType");//here didn't get nbt tag
		for (int i = 0; i < 6; i++)
			this.sideType[i] = ((NBTTagCompound) list.get(i)).getBoolean("side" + i);
		if (totalEnergy > capacity)
		{
			totalEnergy = capacity;
		}
		storage.readFromNBT(nbt);
	}

	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbt)
	{
		super.writeToNBT(nbt);
		nbt = storage.writeToNBT(nbt);
		if (totalEnergy < 0)
		{
			totalEnergy = 0;
		}
		nbt.setInteger("totalEnergy", totalEnergy);
		NBTTagList list = new NBTTagList();
		for(int i = 0; i <6; i++)
		{
			NBTTagCompound a = new NBTTagCompound();
			a.setBoolean("side" + i, this.sideType[i]);
			list.appendTag(a);
		}
		nbt.setTag("sideType", list);
		//LOGGER.info("write"+nbt.toString());
		return nbt;
	}

I just want to save the block's side config data(as written above the NBTTagList list), but it got an error that once rejoin all side config lose and reset.

And then I tried to output the "nbt" (LOGGER.info("read"+nbt.toString());),  and find that (log)  L650, L671, L674

[13:51:27] [Server thread/INFO]: read{sideType:[0:{side0:0b},1:{side1:0b},2:{side2:1b},3:{side3:0b},4:{side4:0b},5:{side5:0b}],Energy:0,totalEnergy:0,x:-189,y:64,z:235,id:"energyconversion:PowerBlock"}
[13:51:28] [Server thread/INFO]: VoiceServer: Starting up server...
[13:51:28] [Server thread/INFO]: Changing view distance to 12, from 10
[13:51:31] [Netty Local Client IO #0/INFO]: Server protocol version 2
[13:51:31] [Netty Server IO #1/INFO]: Client protocol version 2
[13:51:31] [Netty Server IO #1/INFO]: Client attempting to join with 22 mods : [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],<CoFH ASM>@000,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]_88,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
[13:51:31] [Netty Local Client IO #0/INFO]: [Netty Local Client IO #0] Client side modded connection established
[13:51:31] [Server thread/INFO]: [Server thread] Server side modded connection established
[13:51:31] [Server thread/INFO]: 0x00000000[local:E:db3c6b1b] logged in with entity id 390 at (-187.07428959339794, 64.0, 233.18476770205746)
[13:51:31] [Server thread/INFO]: 0x00000000 joined the game
[13:51:31] [Server thread/INFO]: Sent config to 'TextComponent{text='', siblings=[TextComponent{text='0x00000000', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=ClickEvent{action=SUGGEST_COMMAND, value='/msg 0x00000000 '}, hoverEvent=HoverEvent{action=SHOW_ENTITY, value='TextComponent{text='{name:"0x00000000",id:"e1965b52-bc8f-995f-3766-d820e4b3717b"}', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=0x00000000}}], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=ClickEvent{action=SUGGEST_COMMAND, value='/msg 0x00000000 '}, hoverEvent=HoverEvent{action=SHOW_ENTITY, value='TextComponent{text='{name:"0x00000000",id:"e1965b52-bc8f-995f-3766-d820e4b3717b"}', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=0x00000000}}.'
[13:51:33] [Server thread/INFO]: Saving and pausing game...
[13:51:33] [Client thread/INFO]: Minecraft is in offline mode, could not check for updates.
[13:51:33] [Client thread/INFO]: [CHAT] InvTweaks: Configuration loaded.
[13:51:33] [Netty Local Client IO #0/INFO]: Received config from server.
[13:51:33] [Netty Local Client IO #0/INFO]: Received Cardboard Box blacklist entries from server (15 total)
[13:51:33] [Thread-15/INFO]: VoiceServer: Starting client connection...
[13:51:33] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld
[13:51:33] [Thread-15/INFO]: VoiceServer: Successfully connected to server.
[13:51:33] [VoiceServer Listen Thread/INFO]: VoiceServer: Accepted new connection.
[13:51:33] [Thread-17/INFO]: VoiceServer: Traced IP in 1 attempts.
[13:51:33] [Server thread/INFO]: write{sideType:[0:{side0:0b},1:{side1:0b},2:{side2:1b},3:{side3:0b},4:{side4:0b},5:{side5:0b}],Energy:0,totalEnergy:0,x:-189,y:64,z:235,id:"energyconversion:PowerBlock"}
[13:51:33] [Server thread/INFO]: Saving chunks for level 'New World'/Nether
[13:51:33] [Server thread/INFO]: Saving chunks for level 'New World'/The End
[13:51:33] [Client thread/INFO]: read{x:-189,y:64,z:235,id:"energyconversion:PowerBlock"}
[13:51:33] [Client thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_141]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_141]
	at net.minecraft.util.Util.func_181617_a(SourceFile:46) [h.class:?]
	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1045) [bcx.class:?]
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:371) [bcx.class:?]
	at net.minecraft.client.main.Main.main(SourceFile:124) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_141]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
Caused by: java.lang.NullPointerException
	at com.bxzmod.energyconversion.tileentity.PowerBlockTileEntity.func_145839_a(PowerBlockTileEntity.java:109) ~[PowerBlockTileEntity.class:?]
	at net.minecraft.tileentity.TileEntity.handleUpdateTag(TileEntity.java:341) ~[aqk.class:?]
	at net.minecraft.client.network.NetHandlerPlayClient.func_147263_a(NetHandlerPlayClient.java:728) ~[bll.class:?]
	at net.minecraft.network.play.server.SPacketChunkData.func_148833_a(SourceFile:96) ~[gt.class:?]
	at net.minecraft.network.play.server.SPacketChunkData.func_148833_a(SourceFile:18) ~[gt.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[fl$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_141]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_141]
	at net.minecraft.util.Util.func_181617_a(SourceFile:45) ~[h.class:?]
	... 9 more

 

L671    The "writeToNBT" output   write{sideType:[0:{side0:0b},1:{side1:0b},2:{side2:1b},3:{side3:0b},4:{side4:0b},5:{side5:0b}],Energy:0,totalEnergy:0,x:-189,y:64,z:235,id:"energyconversion:PowerBlock"}

L674    The "readFromNBT" Output    read{x:-189,y:64,z:235,id:"energyconversion:PowerBlock"   do not contain any additional nbt. 

But other nbt "totalEnergy" and "Energy" works . Just "sideType" got wrong.

 

Edited by bxzsj
forget link

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.