Jump to content

Recommended Posts

Posted

Hey, 

I'm trying to make blocks that are moving smoothly. For that, I want to create an entity that renders the block. 

I'm registering the renderer but for some reason, it isn't being rendered. 
This is my code of the renderer and the registry

package me.cirex.fluidships.entity.renderer;

import com.mojang.blaze3d.matrix.MatrixStack;

import me.cirex.fluidships.entity.EntityBlock;
import me.cirex.fluidships.entity.model.EntityBlockModel;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;

public class EntityBlockRenderer extends EntityRenderer<EntityBlock> {

	protected EntityBlockRenderer(EntityRendererManager renderManager) {
		super(renderManager);
	}

	@Override
	public void render(EntityBlock entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn,
			IRenderTypeBuffer bufferIn, int packedLightIn) {
		System.out.println("test");
		EntityBlockModel model = new EntityBlockModel(entityIn);
		for (net.minecraft.client.renderer.RenderType type : net.minecraft.client.renderer.RenderType
				.getBlockRenderTypes()) {
			model.render(matrixStackIn, bufferIn.getBuffer(type), packedLightIn, 0, 1, 1, 1, 1);
		}
		super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
	}

	@Override
	public ResourceLocation getEntityTexture(EntityBlock entity) {
		return null;
	}


	public static class RenderFactory implements IRenderFactory<EntityBlock> {

		@Override
		public EntityRenderer<? super EntityBlock> createRenderFor(EntityRendererManager manager) {
			return new EntityBlockRenderer(manager);
		}

	}
}
package me.cirex.fluidships.registry;

import me.cirex.fluidships.FluidShips;
import me.cirex.fluidships.block.InvisibleBlock;
import me.cirex.fluidships.entity.EntityBlock;
import me.cirex.fluidships.entity.renderer.EntityBlockRenderer;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ShipRegistry {

	@SuppressWarnings("unchecked")
	public static EntityType<EntityBlock> BLOCK_ENTITY = (EntityType<EntityBlock>) EntityType.Builder
			.create(EntityBlock::new, EntityClassification.MISC).size(1F, 1F)
			.build(FluidShips.MODID + ":block_entity")
			.setRegistryName(new ResourceLocation(FluidShips.MODID, "block_entity"));

	public static Block INVISIBLE_BLOCK = new InvisibleBlock();

	@SubscribeEvent
	public void onBlockRegistry(final RegistryEvent.Register<Block> event) {
		event.getRegistry().register(INVISIBLE_BLOCK);
	}

	@SubscribeEvent
	public void onEntityTypeRegistry(final RegistryEvent.Register<EntityType<? extends Entity>> event) {
		event.getRegistry().register(BLOCK_ENTITY);
	}

	public void registerRenderer() {
		RenderingRegistry.registerEntityRenderingHandler(BLOCK_ENTITY, new EntityBlockRenderer.RenderFactory());
	}

	public void onClientSetup(final FMLClientSetupEvent event) {
		registerRenderer();
	}

}

 

Posted
1 hour ago, diesieben07 said:

You don't need an entity. Look at e.g. shulker boxes (ShulkerBoxTileEntityRenderer).

I can't really get it working using a TileEntity. Can you maybe answer my original question?

Posted
25 minutes ago, diesieben07 said:

An entity is the wrong tool for this.

Show your attempt with a TE.

So far, I'm having problems with what arguments I put in for 
Builder.create

and for new EntityBlockRenderer

package me.cirex.fluidships.registry;

import me.cirex.fluidships.FluidShips;
import me.cirex.fluidships.block.InvisibleBlock;
import me.cirex.fluidships.entity.EntityBlock;
import me.cirex.fluidships.entity.renderer.EntityBlockRenderer;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ShipRegistry {

    public static TileEntityType<?> BLOCK_TILE_ENTITY;

    @SubscribeEvent
    public void onBlockRegistry(final RegistryEvent.Register<Block> event) {

    }

    @SubscribeEvent
    public void onEntityTypeRegistry(final RegistryEvent.Register<TileEntityType<?>> event) {
        BLOCK_TILE_ENTITY = TileEntityType.Builder.create(null, null).build(null);
        event.getRegistry().register(BLOCK_TILE_ENTITY);
    }

    public void registerRenderer() {
        RenderingRegistry.registerEntityRenderingHandler(BLOCK_TILE_ENTITY, new EntityBlockRenderer());
    }

    public void onClientSetup(final FMLClientSetupEvent event) {
        registerRenderer();
    }

}
 

package me.cirex.fluidships.registry;

import me.cirex.fluidships.FluidShips;
import me.cirex.fluidships.block.InvisibleBlock;
import me.cirex.fluidships.entity.EntityBlock;
import me.cirex.fluidships.entity.renderer.EntityBlockRenderer;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ShipRegistry {

	public static TileEntityType<?> BLOCK_TILE_ENTITY;

	@SubscribeEvent
	public void onBlockRegistry(final RegistryEvent.Register<Block> event) {

	}

	@SubscribeEvent
	public void onEntityTypeRegistry(final RegistryEvent.Register<TileEntityType<?>> event) {
		BLOCK_TILE_ENTITY = TileEntityType.Builder.create(null, null).build(null);
		event.getRegistry().register(BLOCK_TILE_ENTITY);
	}

	public void registerRenderer() {
		RenderingRegistry.registerEntityRenderingHandler(BLOCK_TILE_ENTITY, new EntityBlockRenderer());
	}

	public void onClientSetup(final FMLClientSetupEvent event) {
		registerRenderer();
	}

}

 

Posted
6 minutes ago, diesieben07 said:

That does not make sense.

Well, the second parameter of the Builder is blocks that the tileentity can be applied to. But I want the TE to be applied to any block

Posted
20 hours ago, diesieben07 said:

That cannot work. A tile entity is bound to specific blocks only. You cannot apply a tile entity to blocks you don't own (e.g. vanilla minecraft blocks).

Well then, apparently a TileEntity isn't the right tool either.

 

21 hours ago, diesieben07 said:

An entity is the wrong tool for this.

Show your attempt with a TE.

 

Posted
1 hour ago, diesieben07 said:

Your original post says that you want to make blocks that move smoothly.

That means you want to add a block. You need to implement this block (your own block class) and give it a tile entity.

Well, basically I want to make ships moving like in this video. I don't want a block by block movement though

 (4

Posted
12 minutes ago, diesieben07 said:

This is what happens when you don't describe your problem properly.

Why did you not post this information in the first place?

well, that's what I meant with blocks moving smoothly. I'm sorry, anyway, do you know how I'm going to do this?

Posted
1 minute ago, diesieben07 said:

With lots and lots of pain.

Minecraft's engine is not designed to do this and you'll have a hard time. That being said, no, i don't know how to do this.

hm, okay, thank you anyway

Posted (edited)

Try taking a look at Archimedes Ships mod for 1.15 or something, I recall seeing one in reddit but I don't remember the name, since probably nothing much has changed from 1.15 to 1.16 just look at its code and try immitating it, I don't know if it has a github tho.

Edited by MostafaSabry55

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.