Jump to content

[1.12.2] TileEntity on Blocks with Properties [Solved]


Dipo

Recommended Posts

My update method in TileEntity class is not called...

My TileEntity class:

Spoiler

package sk.psuchtak.techno.tileentity;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

public class RubberLogTE extends TileEntity implements ITickable {

	int tick = 0;

	public RubberLogTE() {
		System.out.println("created");
	}

	@Override
	public void update() {
		System.out.println(tick);
		tick++;
	}
}

 

 

 

My Block class:

Spoiler

package sk.psuchtak.techno.block;

import javax.annotation.Nullable;

import com.google.common.base.Predicate;

import net.minecraft.block.BlockLog;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import sk.psuchtak.techno.TechnoMod;
import sk.psuchtak.techno.item.TechnoAxe;
import sk.psuchtak.techno.item.TechnoItems;
import sk.psuchtak.techno.tileentity.RubberLogTE;
import sk.psuchtak.techno.utils.EnumHandler;
import sk.psuchtak.techno.utils.ItemBlockVariants;
import sk.psuchtak.techno.utils.interfaces.IHasModel;
import sk.psuchtak.techno.utils.interfaces.IMetaName;

public class TechnoLogs extends BlockLog implements IMetaName, IHasModel {

	public static final PropertyEnum<EnumHandler.EnumTrees> VARIANT = PropertyEnum.<EnumHandler.EnumTrees>create(
			"variant", EnumHandler.EnumTrees.class, new Predicate<EnumHandler.EnumTrees>() {
				public boolean apply(@Nullable EnumHandler.EnumTrees apply) {
					return apply.getMetadata() < EnumHandler.EnumTrees.values().length;
				}
			});

	public static final PropertyEnum<EnumHandler.EnumRubberWood> RUBBER = PropertyEnum.<EnumHandler.EnumRubberWood>create(
			"rubber", EnumHandler.EnumRubberWood.class, new Predicate<EnumHandler.EnumRubberWood>() {
				public boolean apply(@Nullable EnumHandler.EnumRubberWood apply) {
					return apply.getMetadata() < EnumHandler.EnumRubberWood.values().length;
				}
			});

	private String name;

	public TechnoLogs(String name) {
		super();
		setUnlocalizedName(name);
		setRegistryName(name);
		setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumHandler.EnumTrees.RUBBER)
				.withProperty(LOG_AXIS, EnumAxis.Y).withProperty(RUBBER, EnumHandler.EnumRubberWood.CLASSIC));
		setCreativeTab(TechnoMod.technoTab);
		setHardness(2.0F);
		setSoundType(SoundType.WOOD);

		this.name = name;

		TechnoBlocks.BLOCKS.add(this);
		TechnoItems.ITEMS.add(new ItemBlockVariants(this).setRegistryName(this.getRegistryName()));
	}

	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
		for (EnumHandler.EnumTrees enumType : EnumHandler.EnumTrees.values()) {
			items.add(new ItemStack(this, 1, enumType.getMetadata()));
		}
	}

	public IBlockState getStateFromMeta(int meta) {
		int size = EnumHandler.EnumTrees.values().length;
		int size2 = size + 2;
		IBlockState state;

		int sw = meta - (meta / size2 * size2);

		if (sw == (size2 - 2)) {
			state = this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumTrees.RUBBER).withProperty(RUBBER,
					EnumHandler.EnumRubberWood.HOLE);
		} else if (sw == (size2 - 1)) {
			state = this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumTrees.RUBBER).withProperty(RUBBER,
					EnumHandler.EnumRubberWood.RUBBERING);
		} else {
			state = this.getDefaultState()
					.withProperty(VARIANT, EnumHandler.EnumTrees.byMetadata(meta - (meta / size * size)))
					.withProperty(RUBBER, EnumHandler.EnumRubberWood.CLASSIC);
		}

		switch (meta / size2) {
		case 0:
			state = state.withProperty(LOG_AXIS, EnumAxis.Y);
			break;
		case 1:
			state = state.withProperty(LOG_AXIS, EnumAxis.X);
			break;
		case 2:
			state = state.withProperty(LOG_AXIS, EnumAxis.Z);
			break;
		default:
			state = state.withProperty(LOG_AXIS, EnumAxis.NONE);
		}

		return state;
	}

	public int getMetaFromState(IBlockState state) {
		int i = 0;
		int size = EnumHandler.EnumTrees.values().length;
		int size2 = size + 2;
		i = i | ((EnumHandler.EnumTrees) state.getValue(VARIANT)).getMetadata();

		switch ((EnumAxis) state.getValue(LOG_AXIS)) {
		case Y:
			i += 0;
			break;
		case X:
			i += size2;
			break;
		case Z:
			i += 2 * size2;
			break;
		default:
			i += 3 * size2;
		}

		switch ((EnumHandler.EnumRubberWood) state.getValue(RUBBER)) {
		case CLASSIC:
			i += 0;
			break;
		case HOLE:
			i += 1;
			break;
		case RUBBERING:
			i += 2;
			break;

		}

		return i;
	}

	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] { VARIANT, LOG_AXIS, RUBBER });
	}

	protected ItemStack getSilkTouchDrop(IBlockState state) {
		return new ItemStack(Item.getItemFromBlock(this), 1,
				((EnumHandler.EnumTrees) state.getValue(VARIANT)).getMetadata());
	}

	public int damageDropped(IBlockState state) {
		return ((EnumHandler.EnumTrees) state.getValue(VARIANT)).getMetadata();
	}

	@Override
	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
			EntityPlayer player) {
		return new ItemStack(state.getBlock(), 1,
				state.getValue(VARIANT).getMetadata() + state.getValue(RUBBER).getMetadata());
	}

	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
			EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		if (state.getValue(VARIANT) == EnumHandler.EnumTrees.RUBBER
				&& state.getValue(RUBBER) == EnumHandler.EnumRubberWood.CLASSIC) {
			if (playerIn.getHeldItem(hand).getItem() instanceof ItemAxe
					|| playerIn.getHeldItem(hand).getItem() instanceof TechnoAxe) {
				state.withProperty(RUBBER, EnumHandler.EnumRubberWood.HOLE);
				IBlockState stateNew = this.blockState.getBaseState()
						.withProperty(VARIANT, EnumHandler.EnumTrees.RUBBER)
						.withProperty(LOG_AXIS, state.getValue(LOG_AXIS))
						.withProperty(RUBBER, EnumHandler.EnumRubberWood.HOLE);
				worldIn.setBlockState(pos, stateNew);
				this.createTileEntity(worldIn, stateNew);
				return true;
			}
		}
		return false;
	}

	@Override
	public String getSpecialName(ItemStack stack) {
		int meta = stack.getItemDamage();
		int size = EnumHandler.EnumTrees.values().length;
		int variant = meta - (meta / size * size);
		return EnumHandler.EnumTrees.values()[variant].getName();
	}

	@Override
	public void registerModels() {
		int j = EnumHandler.EnumTrees.values().length;
		for (int i = 0; i < j; i++) {
			TechnoMod.proxy.registerVariantRenderer(Item.getItemFromBlock(this), i,
					"log_" + EnumHandler.EnumTrees.values()[i].getName(), "inventory");
		}
		TechnoMod.proxy.registerVariantRenderer(Item.getItemFromBlock(this), j, "log_rubber_hole", "inventory");
		TechnoMod.proxy.registerVariantRenderer(Item.getItemFromBlock(this), j + 1, "log_rubber_rubbering",
				"inventory");
	}

	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		if (state.getValue(RUBBER) == EnumHandler.EnumRubberWood.HOLE) {
			System.out.println("creating te");
			return new RubberLogTE();
		}
		return null;
	}
}

 

 

createNewTileEntity is being called from onBlockActivated, and Iam sure that the TileEntity is being created when i click on the block with axe.

And the TileEntity is being registered here:

Spoiler

...
@SubscribeEvent
public static void onBlockRegister(RegistryEvent.Register<Block> event) {
	event.getRegistry().registerAll(TechnoBlocks.BLOCKS.toArray(new Block[0]));
	GameRegistry.registerTileEntity(RubberLogTE.class, "rubber_log");
	Utils.getLogger().info("Blocks registred");
}
...

 

 

Link to comment
Share on other sites

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

    • I had a similar issue to what you do above. Given this is an old post, you've probably sorted this now In my case, I had Java (JDK) 22 installed. After uninstalling that and installing 17.0.11 (having both installed gives the same error), then running the startserver.bat worked for me. I managed to get to the EULA section and then start my server correctly- I hope it helps anyone else who may have this issue!
    • Make a test with another Launcher like MultiMC, AT Launcher or Technic Launcher
    • I opened up Minecraft today for the first time in a month and whenever I try and play forge I get an error 1 message. I restarted my computer, tried reinstalling both Minecraft and Forge and have updated all of my drivers. Nothing seems to work so I'm stumped. I have absolutely no mods installed ATM so I have no idea what could be causing the problem. I hope yall are able to help.   DebugLog:   [19May2024 20:33:51.600] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, dmoy18, --version, 1.20.1-forge-47.2.0, --gameDir, C:\Users\dmoyf\AppData\Roaming\.minecraft, --assetsDir, C:\Users\dmoyf\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, c083972cd92d4dd2894beb25b82ebe82, --accessToken, ????????, --clientId, MDljMzIwMjYtOTJiNS00YWUxLTk1M2EtN2ExMGExZWM0MDAw, --xuid, 2535417310772497, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\dmoyf\AppData\Roaming\.minecraft\quickPlay\java\1716168829421.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [19May2024 20:33:51.604] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 11 arch amd64 version 10.0 [19May2024 20:33:51.634] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [fmlclientdev,forgeclient,minecraft,forgegametestserverdev,fmlserveruserdev,fmlclient,fmldatauserdev,forgeserverdev,forgeserveruserdev,forgeclientdev,forgeclientuserdev,forgeserver,forgedatadev,fmlserver,fmlclientuserdev,fmlserverdev,forgedatauserdev,testharness,forgegametestserveruserdev] [19May2024 20:33:51.653] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [srgtomcp] [19May2024 20:33:51.668] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,slf4jfixer,object_holder_definalize,runtime_enum_extender,capability_token_subclass,accesstransformer,runtimedistcleaner] [19May2024 20:33:51.681] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [19May2024 20:33:51.688] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path GAMEDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path MODSDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft\mods [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path CONFIGDIR is C:\Users\dmoyf\AppData\Roaming\.minecraft\config [19May2024 20:33:51.689] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path FMLCONFIG is C:\Users\dmoyf\AppData\Roaming\.minecraft\config\fml.toml
  • Topics

×
×
  • Create New...

Important Information

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