Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] GUI not updating values


Melonslise
 Share

Recommended Posts

I created a class extending IExtendedEntityProperties:

 

 

package melonslise.runicinscription;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class ManaProperties implements IExtendedEntityProperties
{
public final static String EXT_PROP_MANA = "HandlerManaSystem";

private final EntityPlayer player;
private int currentMana;
private int maxMana;



public ManaProperties(EntityPlayer player)
{
	this.player = player;
	this.currentMana = 30;
	this.maxMana = 30;
}

public static final void register(EntityPlayer player)
{
	player.registerExtendedProperties(ManaProperties.EXT_PROP_MANA, new ManaProperties(player));
}

public static final ManaProperties get(EntityPlayer player)
{
	return (ManaProperties) player.getExtendedProperties(EXT_PROP_MANA);
}

@Override
public void saveNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = new NBTTagCompound();

	properties.setInteger("CurrentMana", this.currentMana);
	properties.setInteger("MaxMana", this.maxMana);

	compound.setTag(EXT_PROP_MANA, properties);

}

@Override
public void loadNBTData(NBTTagCompound compound)
{
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_MANA);

	this.currentMana = properties.getInteger("CurrentMana");
	this.maxMana = properties.getInteger("MaxMana");

	System.out.println("Mana from NBT: " + this.currentMana + "/" + this.maxMana);
}

@Override
public void init(Entity entity, World world)
{

}

public boolean consumeMana(int amount)
{
	if(this.currentMana >= amount)
	{
		currentMana = currentMana - amount;
		return true;
	}

	return false;
}

public void replenishMana()
{
	this.currentMana = this.maxMana;
}

public int getMaxMana() 
{
	return this.maxMana;
}

public int getCurrentMana()
{
	return this.maxMana;
}
}

 

 

 

And here's it's handler:

 

 

package melonslise.runicinscription.Handler;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import melonslise.runicinscription.ManaProperties;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import net.minecraftforge.event.entity.player.PlayerEvent;

public class HandlerManaEvents
{
@SubscribeEvent
public void onEntityConstructing(EntityConstructing event)
{
	if (event.entity instanceof EntityPlayer && ManaProperties.get((EntityPlayer) event.entity) == null)
		ManaProperties.register((EntityPlayer) event.entity);

	if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(ManaProperties.EXT_PROP_MANA) == null)
		event.entity.registerExtendedProperties(ManaProperties.EXT_PROP_MANA, new ManaProperties((EntityPlayer) event.entity));
}

}

 

 

 

And here's the GUI

 

 

package melonslise.runicinscription.GUI;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import melonslise.runicinscription.ManaProperties;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

public class GUIManaBar extends Gui
{
public GUIManaBar(Minecraft mc)
{	
	int xPos = 2;
	int yPos = 2;

	ManaProperties props = ManaProperties.get(mc.thePlayer);
	mc.fontRenderer.drawStringWithShadow("§1" + props.getCurrentMana() + "/" + props.getMaxMana(), xPos, yPos, );
}
}

 

 

 

And it's hander:

 

 

package melonslise.runicinscription.Handler;

import cpw.mods.fml.client.GuiNotification;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import melonslise.runicinscription.GUI.GUIManaBar;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

public class HandlerGUI
{
   @SubscribeEvent
   public void onRenderGUI(RenderGameOverlayEvent event)
   {
	   if (event.type != ElementType.EXPERIENCE) return;
	   new melonslise.runicinscription.GUI.GUIManaBar(Minecraft.getMinecraft());
   }
}

 

 

 

And both are registered in the mod class

 

 

@EventHandler
public void init(FMLInitializationEvent event)
{
	MinecraftForge.EVENT_BUS.register(new HandlerManaEvents());
                MinecraftForge.EVENT_BUS.register(new HandlerGUI());
}

 

 

 

Here's an item's onItemRightClick code:

 

 

			if (props.consumeMana(15))
			{
				System.out.println("Player had enough mana. Do something awesome!");
			}
			else
			{
				System.out.println("Player ran out of mana. Sad face.");
				props.replenishMana();
			}

 

 

 

And when right clicked the gui values don't change

Link to comment
Share on other sites

  • Replies 98
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Why are you still using IExtendedEntityProperties? Update and use Capabilities, IEEP is gone in newer forge versions.
  • Why do you have basically the same code twice in the entity constructing event? Why do you even check if your properties are already there? If they would be, something would be seriously wrong and you should not just ignore and carry on.
  • Your IEEP identifier should include your ModID.
  • You should choose one of
    RenderGameOverlayEvent.Pre

    or

    RenderGameOverlayEvent.Post

    , don't use both.

  • Why are you drawing in the constructor of
    GUIManaBar

    ? I have seen this style before, what tutorial did you get it from? The maker needs to be properly yelled at...

  • GUIs are entirely client-side, but modifying your IEEP happens on the server. This does not magically sync, you need to send packets to keep your IEEP in sync whenever it changes on the server.

Link to comment
Share on other sites

  • Why are you still using IExtendedEntityProperties? Update and use Capabilities, IEEP is gone in newer forge versions.
  • Why do you have basically the same code twice in the entity constructing event? Why do you even check if your properties are already there? If they would be, something would be seriously wrong and you should not just ignore and carry on.
  • Your IEEP identifier should include your ModID.
  • You should choose one of
    RenderGameOverlayEvent.Pre

    or

    RenderGameOverlayEvent.Post

    , don't use both.

  • Why are you drawing in the constructor of
    GUIManaBar

    ? I have seen this style before, what tutorial did you get it from? The maker needs to be properly yelled at...

  • GUIs are entirely client-side, but modifying your IEEP happens on the server. This does not magically sync, you need to send packets to keep your IEEP in sync whenever it changes on the server.

 

  • I am making a mod for 1.7.10. (Just incase you ask, I will be updating it to 1.8 and don't ask why I am using 1.7.10)
  • I don't know why. I was following coolAlias' tutorial on this thing. What should I have in the handler then?
  • Where do I put my mod id then? (As I said I was following coolAlias' tutorial on IEEP)
  • Ok I'll change  that
  • How should I draw it then? I followed this tutorial : https://emxtutorials.wordpress.com/simple-in-game-gui-overlay/
  • Where can I find a good and detailed tutorial on packets in 1.7.10?

Link to comment
Share on other sites

I am making a mod for 1.7.10. (Just incase you ask, I will be updating it to 1.8 and don't ask why I am using 1.7.10)
No, I won't ask. But I will say: stop.

I don't know why. I was following coolAlias' tutorial on this thing. What should I have in the handler then?
Never have code in your mod (or any other programming project) that you don't understand. You should simply register your IEEP. Nothing more.

Where do I put my mod id then? (As I said I was following coolAlias' tutorial on IEEP)
You put it in the identifier. Like I said.

How should I draw it then? I followed this tutorial : https://emxtutorials.wordpress.com/simple-in-game-gui-overlay/

Not in the constructor.

Where can I find a good and detailed tutorial on packets in 1.7.10?
I don't know, I don't keep track of 1.7.10 tutorials.
Link to comment
Share on other sites

I am making a mod for 1.7.10. (Just incase you ask, I will be updating it to 1.8 and don't ask why I am using 1.7.10)
No, I won't ask. But I will say: stop.

I don't know why. I was following coolAlias' tutorial on this thing. What should I have in the handler then?
Never have code in your mod (or any other programming project) that you don't understand. You should simply register your IEEP. Nothing more.

Where do I put my mod id then? (As I said I was following coolAlias' tutorial on IEEP)
You put it in the identifier. Like I said.

How should I draw it then? I followed this tutorial : https://emxtutorials.wordpress.com/simple-in-game-gui-overlay/

Not in the constructor.

Where can I find a good and detailed tutorial on packets in 1.7.10?
I don't know, I don't keep track of 1.7.10 tutorials.

 

Alright, So I created two messages and two handlers for them:

 

Message about current mana:

 

 

package melonslise.runicinscription.Network;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import io.netty.buffer.ByteBuf;

public class CurrentManaMessage implements IMessage
{
private int currentMana;

public CurrentManaMessage()
{

}

public CurrentManaMessage(int currentMana)
{
	this.currentMana = currentMana;
}

@Override
public void toBytes(ByteBuf buf)
{
	buf.writeInt(currentMana);
}

@Override
public void fromBytes(ByteBuf buf)
{
	currentMana = buf.readInt();
}

public int getCurrentMana()
{
	return currentMana;
}
}

 

 

 

and it's handler

 

 

package melonslise.runicinscription.Handler;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import melonslise.runicinscription.Network.CurrentManaMessage;
import net.minecraft.entity.player.EntityPlayerMP;

public class HandlerCurrentManaMessage implements IMessageHandler<CurrentManaMessage, IMessage>
{
@Override
public IMessage onMessage(CurrentManaMessage message, MessageContext ctx) 
{
	EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;

	int currentMana = message.getCurrentMana();

	return null;
}

}

 

 

 

Message about max mana:

 

 

package melonslise.runicinscription.Network;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import io.netty.buffer.ByteBuf;

public class MaxManaMessage implements IMessage
{
private int maxMana;

public MaxManaMessage()
{
	  
}
  
public MaxManaMessage(int maxMana)
{
	this.maxMana = maxMana;
}

@Override
public void toBytes(ByteBuf buf)
{
	buf.writeInt(maxMana);
}

@Override
public void fromBytes(ByteBuf buf)
{
	maxMana = buf.readInt();
}

public int getMaxMana()
{
	return maxMana;
}
}

 

 

 

and it's handler:

 

 

package melonslise.runicinscription.Handler;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import melonslise.runicinscription.Network.MaxManaMessage;
import net.minecraft.entity.player.EntityPlayerMP;

public class HandlerMaxManaMessage implements IMessageHandler<MaxManaMessage, IMessage>
{
@Override
public IMessage onMessage(MaxManaMessage message, MessageContext ctx)
{
	EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;

	int amount = message.getMaxMana();

	return null;
}
}

 

 

 

So how do I integrate these into my GUI and IEEP?

Link to comment
Share on other sites

If hander is supposed to receive on client, why are your using server side?

 

EntityPlayer player = ctx.getClientHandler().playerEntity;

or

Minecraft#thePlayer

 

When registering packet you need to use Side.CLIENT (its the side of handler).

 

Then when you have client-side player, you simlpy get his IEEP and update it.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

If hander is supposed to receive on client, why are your using server side?

 

EntityPlayer player = ctx.getClientHandler().playerEntity;

or

Minecraft#thePlayer

 

When registering packet you need to use Side.CLIENT (its the side of handler).

 

Then when you have client-side player, you simlpy get his IEEP and update it.

 

I though the receiving end was registered here:

network.registerMessage(HandlerCurrentManaMessage.class, CurrentManaMessage.class, 1, Side.CLIENT);

 

But I did change to this:

EntityPlayer player = ctx.getClientHandler().playerEntity;

 

and it's saying that playerEntity cannot be resolved

Link to comment
Share on other sites

I though the receiving end was registered here:

network.registerMessage(HandlerCurrentManaMessage.class, CurrentManaMessage.class, 1, Side.CLIENT);

 

This is correct, I just pointed that out since i didn't see you register it. (missed it or you didn't provide code).

 

Anyway - handler is the receiver so it is logical that if receiver is client you can (should) use client-only stuff, in this case - use client player.

 

EDIT

 

In case you would want to update client's data about entity that is NOT Minecraft#thePlayer, you will need to send Entity#entityId (via packet) and use Minecraft#theWorld#getEntityById(entityId) to retrieve it.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I though the receiving end was registered here:

network.registerMessage(HandlerCurrentManaMessage.class, CurrentManaMessage.class, 1, Side.CLIENT);

 

This is correct, I just pointed that out since i didn't see you register it. (missed it or you didn't provide code).

 

Anyway - handler is the receiver so it is logical that if receiver is client you can (should) use client-only stuff, in this case - use client player.

 

EDIT

 

In case you would want to update client's data about entity that is NOT Minecraft#thePlayer, you will need to send Entity#entityId (via packet) and use Minecraft#theWorld#getEntityById(entityId) to retrieve it.

 

 

But I did change to this:

EntityPlayer player = ctx.getClientHandler().playerEntity;

 

and it's saying that playerEntity cannot be resolved

Link to comment
Share on other sites

Because there is no such thing (that was my wild guess / pseudo code). Use Minecraft#thePlayer.

 

Note - As Minecraft is @SideOnly class, referencing it from handler should crash on server (dedic).

There are few ways to resolve it, one of them is to make a Proxy getter for Minecraft#thePlayer that returns Minecraft#thePlayer on client and null on server.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Because there is no such thing (that was my wild guess / pseudo code). Use Minecraft#thePlayer.

 

Note - As Minecraft is @SideOnly class, referencing it from handler should crash on server (dedic).

There are few ways to resolve it, one of them is to make a Proxy getter for Minecraft#thePlayer that returns Minecraft#thePlayer on client and null on server.

So how exactly would I make this proxy? As in a new class? How would the getter look like? A small snippet of code would help me understand better.

Link to comment
Share on other sites

CommonProxy#getClientPlayer() - abstract/interface OR return null;

ClientProxy#getClientPlayer() return Minecraft#thePlayer;

ServerProxy#getClientPlayer() return null; (if you alredy return null in Common, ServerProxy is not even needed (Common will be server))

 

Then you have @SidedProxy CommonProxy in your main mod class, ay?

Now when you are on client.jar you will have Minecraft#thePlayer returned, and on server - null (where on server should never even be reached).

 

http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

CommonProxy#getClientPlayer() - abstract/interface OR return null;

ClientProxy#getClientPlayer() return Minecraft#thePlayer;

ServerProxy#getClientPlayer() return null; (if you alredy return null in Common, ServerProxy is not even needed (Common will be server))

 

Then you have @SidedProxy CommonProxy in your main mod class, ay?

Now when you are on client.jar you will have Minecraft#thePlayer returned, and on server - null (where on server should never even be reached).

 

http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

I started off creating getClientPlayer() in the client proxy, but now it's telling me that it cannot create a static reference to a non-static field /:

Link to comment
Share on other sites

Do you know Java? You got everything you need to make it work, only thing that can stop you is lack of java knowledge which won't really be found here - google said error or just read what static means.

 

Hint:

#getClientPlayer should be a member method (not static).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Do you know Java? You got everything you need to make it work, only thing that can stop you is lack of java knowledge which won't really be found here - google said error or just read what static means.

 

Hint:

#getClientPlayer should be a member method (not static).

Alright I found the solution, but I did google around a little and found this:

EntityPlayer thePlayer = (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : ctx.getServerHandler().playerEntity);

 

wouldn't this be better than calling methods from the proxies?

Link to comment
Share on other sites

No it wouldn't be better (tho, it might work, still - it is bad way).

 

Anything marked by @SideOnly is NOT PRESENT on other side. Minecraft is @SideOnly(Side.CLIENT) which means it is not loaded by VM when you fire mod on dedicated server. Because of that if you try to reference Minecraft class from common code - it will crash (in this case - on dedicated server).

 

Whenever you need sided access - you need proxy.

 

You will need proxies at some point, just make them now. God, look into some open sources.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

No it wouldn't be better (tho, it might work, still - it is bad way).

 

Anything marked by @SideOnly is NOT PRESENT on other side. Minecraft is @SideOnly(Side.CLIENT) which means it is not loaded by VM when you fire mod on dedicated server. Because of that if you try to reference Minecraft class from common code - it will crash (in this case - on dedicated server).

 

Whenever you need sided access - you need proxy.

 

You will need proxies at some point, just make them now. God, look into some open sources.

There's still one thing that I don't understand. What do I return in my common proxy?

public EntityClientPlayerMP getClientPlayer()
{
	return ;
}

Link to comment
Share on other sites

3mLydMU.png

 

abstract CommonProxy
{
    public abstract getClientPlayer();
}

ClientProxy extends CommonProxy
{
    public getClientPlayer()
    {
        return Minecraft#thePlayer;
    }
}

ServerProxy extends CommonProxy
{
    public getClientPlayer()
    {
        return null;
    }
}

 

Main
{
    @SidedProxy(clientSide="packages.ClientProxy", serverSide="packages.ServerProxy")
    public static CommonProxy proxy;
}

 

PacketHandler
{
    onMessage(...)
    {
        Main.proxy#getClientPlayer();
    }
}

 

PLEASE, use google sometimes. :)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

abstract CommonProxy
{
    public abstract getClientPlayer();
}

ClientProxy extends CommonProxy
{
    public abstract getClientPlayer()
    {
        return Minecraft#thePlayer;
    }
}

ServerProxy extends CommonProxy
{
    public abstract getClientPlayer()
    {
        return null;
    }
}

 

Main
{
    @SidedProxy(clientSide="packages.ClientProxy", serverSide="packages.ServerProxy")
    public static CommonProxy proxy;
}

 

PacketHandler
{
    onMessage(...)
    {
        Main.proxy#getClientPlayer();
    }
}

 

PLEASE, use google sometimes. :)

Ahahah. Dat meme.

 

In the common proxy it's telling me to change getClientPlayer to void which I cannot do. I also can't change client proxy's getClientPlayer to abstract (I don't think). And I had registered the proxies in the main mod class a long time ago.

 

EDIT: Where did the meme go? ;(

Link to comment
Share on other sites

be7.jpg

 

DUDE, that was pseudocode!!! #getClientPlayer() will obviously have EntityPlayer return.

 

abstract CommonProxy
{
    public abstract EntityPlayer getClientPlayer();
}

1.7.10 is no longer supported by forge, you are on your own.

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
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.

 Share




  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Do not use @OnlyIn. SSpawnObjectPacket only works for vanilla entities. You must use NetworkHooks.getEntitySpawningPacket.
    • public class MudWallBlockEntity extends Entity { private static final BlockState blockState = ModBlocks.TEMPORARY_DIRT_BLOCK.get().defaultBlockState(); private int height; private OneTimeRunnable finishJutsuOnce; private BlockPos startingBlockPos; private BlockPos endBlockPos; private BlockPos oldPos; private int ticks; public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level) { super(entityType, level); } @OnlyIn(Dist.CLIENT) public MudWallBlockEntity(EntityType<? extends MudWallBlockEntity> entityType, World level, BlockPos position, int height, OneTimeRunnable releaseJutsu) { super(entityType, level); this.startingBlockPos = position; this.endBlockPos = new BlockPos(startingBlockPos.getX(), height, startingBlockPos.getZ()); this.oldPos = position; this.height = height; this.finishJutsuOnce = releaseJutsu; this.setPos(position.getX(), position.getY(), position.getZ()); this.ticks = 0; } @Override protected void defineSynchedData() { } @Override protected void readAdditionalSaveData(@Nonnull CompoundNBT pCompound) { startingBlockPos = new BlockPos(pCompound.getInt("StartX"), pCompound.getInt("StartY"),pCompound.getInt("StartZ")); endBlockPos = new BlockPos(startingBlockPos.getX(), pCompound.getInt("Height"), startingBlockPos.getZ()); oldPos = new BlockPos(startingBlockPos.getX(), pCompound.getInt("CurrentHeight"), startingBlockPos.getZ()); } @Override protected void addAdditionalSaveData(@Nonnull CompoundNBT pCompound) { pCompound.putInt("StartX", startingBlockPos.getX()); pCompound.putInt("StartY", startingBlockPos.getY()); pCompound.putInt("StartZ", startingBlockPos.getZ()); pCompound.putInt("Height", height); pCompound.putInt("CurrentHeight", oldPos.getY()); } @Nonnull @Override public IPacket<?> getAddEntityPacket() { return new SSpawnObjectPacket(this, Block.getId(this.getBlockState())); } @Override public void tick() { LogManager.getLogger().info("ticks: " + ticks++ + " current " + blockPosition() + " old " + oldPos); if(blockPosition().equals(endBlockPos)){ if(finishJutsuOnce != null){ finishJutsuOnce.execute(); } remove(); return; } if(blockPosition().equals(oldPos.above())){ oldPos = blockPosition(); level.setBlockAndUpdate(blockPosition(), blockState); } setDeltaMovement(0, 0.1, 0); move(MoverType.SELF, getDeltaMovement()); } public BlockState getBlockState() { return blockState; } public BlockPos getStartingBlockPos() { return startingBlockPos; } @Override public boolean canBeCollidedWith() { return false; } @Override protected boolean canAddPassenger(Entity pPassenger) { return false; } @Override public boolean canChangeDimensions() { return false; } }  
    • Show the whole entity class.
    • The first one is a vanilla server log. The 2nd one is a debug.log that ends prematurely, because the game could not start, because you started 1.16.5 with Java 17. 1.16.5 requires Java 8.
    • The entity creates a pillar of blocks. It appears to work fine; the blocks are getting placed. But the entity is not rendering. It should be displaying interpolated movement upwards. Instead, the blocks just appear (so the entity is invisible). public void tick() { LogManager.getLogger().info("ticks: " + ticks++ + " current " + blockPosition() + " old " + oldPos); if(blockPosition().equals(endBlockPos)){ if(releaseJutsuOnce != null){ releaseJutsuOnce.execute(); } remove(); return; } if(blockPosition().equals(oldPos.above())){ oldPos = blockPosition(); level.setBlockAndUpdate(blockPosition(), blockState); } setDeltaMovement(0, 0.1, 0); move(MoverType.SELF, getDeltaMovement()); } Renderer (copied from falling block): public class MudWallBlockEntityRenderer extends EntityRenderer<MudWallBlockEntity> { public MudWallBlockEntityRenderer(EntityRendererManager entityRendererManager) { super(entityRendererManager); this.shadowRadius = 0.5F; } @Override public void render(MudWallBlockEntity entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight) { BlockState blockstate = entity.getBlockState(); if (blockstate.getRenderShape() == BlockRenderType.MODEL) { World world = entity.getCommandSenderWorld(); if (blockstate != world.getBlockState(entity.blockPosition()) && blockstate.getRenderShape() != BlockRenderType.INVISIBLE) { matrixStack.pushPose(); BlockPos blockpos = new BlockPos(entity.getX(), entity.getBoundingBox().maxY, entity.getZ()); matrixStack.translate(-0.5D, 0.0D, -0.5D); BlockRendererDispatcher blockrendererdispatcher = Minecraft.getInstance().getBlockRenderer(); for (net.minecraft.client.renderer.RenderType type : net.minecraft.client.renderer.RenderType.chunkBufferLayers()) { if (RenderTypeLookup.canRenderInLayer(blockstate, type)) { net.minecraftforge.client.ForgeHooksClient.setRenderLayer(type); blockrendererdispatcher.getModelRenderer().tesselateBlock(world, blockrendererdispatcher.getBlockModel(blockstate), blockstate, blockpos, matrixStack, buffer.getBuffer(type), false, new Random(), blockstate.getSeed(entity.getStartingBlockPos()), OverlayTexture.NO_OVERLAY); } } net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null); matrixStack.popPose(); super.render(entity, entityYaw, partialTicks, matrixStack, buffer, packedLight); } } } @Override public ResourceLocation getTextureLocation(MudWallBlockEntity pEntity) { return AtlasTexture.LOCATION_BLOCKS; } } Registration: RenderingRegistry.registerEntityRenderingHandler(ModEntities.MUD_WALL_BLOCK_ENTITY.get(), MudWallBlockEntityRenderer::new);  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.