Posted May 18, 20187 yr Is possible to create a TileEntity only if Property of a block is for example EnumAxis.Y ? In other cases there is no TileEntity for this block. Edited June 1, 20187 yr by Dipo
May 18, 20187 yr Use Block#createTileEntity(World world, IBlockState state). This method has a IBlockState as a parameter and you can return null if you do not want a TE to be created. Edited May 18, 20187 yr by V0idWa1k3r
May 18, 20187 yr Author 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"); } ...
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.