Jump to content

Recommended Posts

Posted

Hello kind helper,

 

I'm having a problem with the texturing of one of my blocks, this appears to be due to it having too many (well, 2) tile entities.

 

What it should do:

I place the block, a lil algo determines its direction and the textures get assigned to the blocks sides with respect to that direction, the direction gets saved in the tile entity that belongs to the block(well, the position) and once the world gets reloaded the block will show the correct textures.

 

What it does.

I place the block, a lil algo determines its direction and the textures get assigned to the blocks sides with respect to that direction, the direction gets saved in a tile entity that belongs to the block and once the world gets reloaded the block shows the default textures indicating that something isn't working properly.

 

I can be sure that the direction gets saved properly i added a System.out to the readFromNBT function outputting the correct values on reloading the world. The Tile entity that gets loaded by my getTexture function however outputs the default direction.

 

What i did then in order to determine wether my tile entity or works or not is the following:

I added a function

	@Override
    public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
	if(this.hasTileEntity(world.getBlockMetadata(par2, par3, par4))){
        NosTileEntity tile = (NosTileEntity) world.getBlockTileEntity(par2, par3, par4);
        System.out.println(tile.getDirection());
        return true;
        }
	return false;
    }

 

As you can see it tells me the direction saved in the tile entity on right clicking the block, the correct one if the entity works properly, the default value if it does not. And this is where i start getting confused as the output i received was the following:

 

2013-01-11 18:43:03 [iNFO] [sTDOUT] NotSetYet  //the default value

2013-01-11 18:43:03 [iNFO] [sTDOUT] EAS            // the correct value (east)

 

So rightclicking a block once gives me 2 output values. Are there two block or entities saved in this direction? I have no idea, so if anyone could help me with this, it would be much appreciated.

 

// i turned to the wiki for help, and it had some advice on how to use tile entities but my specific problem could not be solved by anything i found there.

 

 

p.s.: The code might contain some odd things (like the damageDropped function) this is due to the fact that I'm currently working on moving from relying on metadata alone to (mostly) relying on (you guessed it) tile entities.

 

 

The Block

package newOldStuff.blocks;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockLog;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import newOldStuff.NosCommonProxy;

public class NosTimberFrameBlock extends BlockContainer {

private static final String[] subNames = { "Plain", "Diagonally-striped",
	"Diagonlly-crossed", "Vertically-striped", "Horizontally-striped", "Y-shaped",
	"Elhaz-shaped","Plain-crossed","Split"};

public NosTimberFrameBlock (int id) {
	super(id, Material.wood);
	setBurnProperties(blockID, 3, 10);
	setHardness(2.0F);
	setResistance(4.0F);
	setStepSound(soundWoodFootstep);
	setCreativeTab(CreativeTabs.tabBlock);
	setBlockName("Timber Frame");
}	

@Override
public int getBlockTexture(IBlockAccess blockAccess, int blockX, int blockY, int blockZ, int side)
{       	
	if(side == 0 || side == 1)return 0;

	int metadata = blockAccess.getBlockMetadata(blockX, blockY, blockZ);
	NosTileEntity tile;

	switch(metadata){
	case 1:
	case 5:
	case 6:
	case 8:
		tile = (NosTileEntity) blockAccess.getBlockTileEntity(blockX, blockY, blockZ);
		return getBlockTextureFromSideAndMetadataAndDirection(side, metadata, tile.getDirection());
	default:return this.getBlockTextureFromSideAndMetadata(side, metadata);
	}	
}

public int getBlockTextureFromSideAndMetadataAndDirection(int side, int metadata, String direction){
	switch(metadata){
	case 1:
		if(direction == "NOR"){if(side == 3 || side == 4)return 1; else return 2;}
		if(direction == "EAS"){if(side == 3 || side == 5)return 1; else return 2;}
		if(direction == "SOU"){if(side == 3 || side == 4)return 2; else return 1;}
		if(direction == "WES"){if(side == 3 || side == 5)return 2; else return 1;}
	case 5:
		if(direction=="DNW"){return 6;}else{return 7;}
	case 6:
		if(direction=="DNW"){return 13;}else{return 14;}
	case 8:
	default: return 255;
	}		
}

@Override
    public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
	if(this.hasTileEntity(world.getBlockMetadata(par2, par3, par4))){
        NosTileEntity tile = (NosTileEntity) world.getBlockTileEntity(par2, par3, par4);
        System.out.println(tile.getDirection());
        return true;
        }
	return false;
    }

@Override
public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
	if(side == 0 || side == 1) return 0;		
	switch(metadata){
	case 0: return 0;
	case 1: return 1;
	case 2:	return 3;
	case 3: return 4;
	case 4: return 5;
	case 5: return 6;
	case 6: return 13;
	case 7: return 12;
	case 8: return 10;
	default: return 255;
	}
}

@Override
public void onBlockPlacedBy(World theWorld, int blockX, int blockY, int blockZ, EntityLiving thePlayer) {
	NosTileEntity tile;
	switch(theWorld.getBlockMetadata(blockX, blockY, blockZ)){
	case 1:tile = (NosTileEntity)theWorld.getBlockTileEntity(blockX, blockY, blockZ);tile.setDirection(thePlayer.posX,thePlayer.posZ);break;
	case 5:
	case 6:tile = (NosTileEntity)theWorld.getBlockTileEntity(blockX, blockY, blockZ);tile.setDirection(thePlayer.posY);break;
	}
}

@Override
public String getTextureFile () {
	return NosCommonProxy.ordinaryBlocks;
}

@Override
public int damageDropped (int metadata) {
	if(metadata==9)return 1;
	if(metadata==10)return 1;
	if(metadata==11)return 1;
	if(metadata==12)return 6;		
	if(metadata==13)return 5;
	return metadata;
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(int unknown, CreativeTabs tab, List subItems) {
	for (int i = 0; i < 9; i++) {
		subItems.add(new ItemStack(this, 1, i));
	}
}

public static String getSubName(int metadata){
	if(metadata==9)return subNames[1] + " " + "Timber Frame";
	if(metadata==10)return subNames[1] + " " + "Timber Frame";
	if(metadata==11)return subNames[1] + " " + "Timber Frame";
	if(metadata==12)return subNames[6] + " " + "Timber Frame";
	if(metadata==13)return subNames[5] + " " + "Timber Frame";
	return  subNames[metadata] + " " + "Timber Frame";		
}

@Override
public boolean hasTileEntity(int metadata){
	switch(metadata){
	case 1:return true;
	case 5:return true;
	case 6:return true;
	case 8:return true;
	default:return false;
	}
}

@Override
public TileEntity createNewTileEntity(World world){
	try{return new NosTileEntity();}
	catch (Exception var3){throw new RuntimeException(var3);}
}

@Override
    public TileEntity createTileEntity(World world, int metadata)
    {
            return createNewTileEntity(world);

    } 
}

The Entity

package newOldStuff.blocks;

import net.minecraft.block.BlockContainer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class NosTileEntity extends TileEntity{

private String direction = "NotSetYet";

public void setDirection(double playerY){
	if(playerY<yCoord) {this.direction = "DNW";}
	else {this.direction = "UPW";}
}

public void setDirection(double playerX, double playerZ){
	double diffX = (double)xCoord + 0.5 - playerX, diffZ = (double)zCoord + 0.5 -playerZ;

	if (Math.abs(diffX)>=Math.abs(diffZ)){
		if(diffX>0){this.direction = "WES";}
		else{this.direction = "EAS";}
	}else{
		if(diffZ>0){this.direction = "SOU";}
		else{this.direction = "NOR";}
	}
}

public void setDirection(double playerX, double playerY, double playerZ){
	//implement
}

public String getDirection(){
	return this.direction;
}

@Override
public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	this.direction = nbt.getString("DIRECTION");
	//System.out.println("Tile X:"+xCoord+" Y:"+yCoord+" Z:"+zCoord+" Richtung:"+this.direction);
}

@Override
public void writeToNBT(NBTTagCompound nbt){
    super.writeToNBT(nbt);
	//System.out.println(this.direction);
	nbt.setString("DIRECTION", this.direction);
}
}

Posted

The reason you get 2 outputs is because the code gets run both server and client side, as even single player is on a server now. As for the textures not working properly, you may need to sync the server and client tile entities using packets.

Posted

Thanks for your advice,

i will have a look into how to do that tomorrow as it is already have past eleven in the evening over here.

I hope i can now get it to work on my own, but there also a chance that might have further questions about how to do this properly. ^^

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • wait, i just did that. why didn't it work? also it's the same. help me!!!!
    • Culprit has been located! It was Tough As Nails + (plus) which was among one of the mods *added* before re-entering, in an attempt to improve compatibility. It, for some reason or another, did not want to work!
    • "You can either try to load it with only the vanilla data pack ("safe mode"), or go back to the title screen and fix it manually." Hello! I encountered this error just now while attempting to re-enter my world for the first time. Notably, no mods were removed before encountering this error and, while being able to find this error elsewhere on the internet, in my scenario it is seemingly caused by a specific mod, of which I cannot isolate. Things I have tried: - Enter "Safe Mode" (fails) - Remove datapacks (no change) - Reverted to old save data (no change) Here is the server log: https://mclo.gs/9vJQEfN I use Modrinth mod loader so please let me know how to share my mod list, and if it is needed.
    • So, i'm hosting (or attempting to host) a port-forwarded modded server for 1.12.2. There's quite a few mods in this pack, but they all run and have no compatibility issues (besides something causing the game to crash if you go fullscreen, a problem ive given up trying to identify or fix). It can run on 6gb of ram or less, and works fine in singleplayer. All of my friends that want to join have the exact same mod/config/game setup as I do (I personally helped them set everything up). Just to be safe, we've all allocated 12 gigabytes of RAM to the installation, and I've also allocated 12GB to the server itself. I am able to join with no issue and it runs fine. However, when they try to join, it gets stuck in the 'logging in' screen before their game becomes unresponsive. When they close it, it gives them the exit code 805306369, which usually means not enough RAM, but this cant be the case. On my screen, in the server, it shows them joining, and then disconnecting, so I dont think its a port-forwarding issue. They can all run it just fine in singleplayer as well. The annoying bit about this particular issue is that it generates no crash log. Does anyone have any suggestions? Thanks! Here is my debug log, and his, starting from the same place. MINE: [132647] [Netty Client IO #5INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132653.817 [132653] [Client threadINFO] [minecraftGuiConnecting] Connecting to 0, 25565 132654.682 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.common.core.transformer.ClassNodeTransformertransform29] Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 132654.684 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.map.core.transformer.ClassNodeTransformertransform29] Transforming class net.minecraft.client.network.NetHandlerPlayClient 132654.764 [132654] [Netty Client IO #9INFO] [FML] Server protocol version 2 132654.777 [132654] [Netty Client IO #9INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132656.193 [132656] [Client threadINFO] [FML] Injecting existing registry data into this client instance 132659.081 [132659] [Client threadINFO] [FML] Applying holder lookups 132659.082 [132659] [Client threadINFO] [FML] Holder lookups applied 132659.092 [132659] [Netty Client IO #9INFO] [FML] [Netty Client IO #9] Client side modded connection established HIS: [13:12:16] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:25.597 [13:12:25] [Client thread/INFO] [minecraft/GuiConnecting]: Connecting to (my IP address and the server port 25565) 13:12:26.805 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.common.core.transformer.ClassNodeTransformer:transform:29]: Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 13:12:26.808 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.map.core.transformer.ClassNodeTransformer:transform:29]: Transforming class net.minecraft.client.network.NetHandlerPlayClient 13:12:26.936 [13:12:26] [Netty Client IO #1/INFO] [FML]: Server protocol version 2 13:12:27.114 [13:12:27] [Netty Client IO #1/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:27.480 [13:12:27] [Client thread/INFO] [FML]: Injecting existing registry data into this client instance 13:12:30.669 [13:12:30] [Client thread/INFO] [FML]: Applying holder lookups 13:12:30.671 [13:12:30] [Client thread/INFO] [FML]: Holder lookups applied 13:13:04.700 Process crashed with exit code -805306369 P.S - Both mods "CTM" and "FUSION" are present in both our folders so idk what that's about.
    • Please read the FAQ (link is orange banner at top of page), and post logs as described there, to an external site such as https://mclo.gs  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.