You have to change the height and width of the player entity for calculating collisions, then override the Entity#getEyeHeight method to set the correct camera position.
You have to change the height and width of the player entity for calculating collisions, then override the Entity#getEyeHeight method to set the correct camera position.
From which class do I call the height and width and where do I put the code into?
Well, I don't have much experience with modifying the player's camera, but if you don't mind reading lots of code you could look at the morph mod by iChun, it changes the camera position depending on the eye height of the entity that was "template" for this morph.
TickHandlerClient is where the eyeHeight is used (not sure about other classes). And it's lots and lots and lots of code. From what I can tell, iChun created his own field called float eyeHeight. And then he assigns a value to the field by Minecraft.getMinecraft().thePlayer.eyeHeight. Time for more reading.
Edit 1: On a side note: what event should I use in my eventhandler for this code to work? I'm working on the code in my eventhandler which uses LivingUpdateEvent
package com.spyeedy.heroesplus.handlers;
import java.util.Random;
import com.spyeedy.heroesplus.armors.civilwar.ArmorCivilWarAntman;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ShrinkGrowEventHandler
{
public float width;
public float height;
public float eyeHeight;
@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
Random rand = new Random();
if (event.entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entity;
if (player.getCurrentArmor(3) !=null && player.getCurrentArmor(2) != null && player.getCurrentArmor(1) != null && player.getCurrentArmor(0) != null)
{
if (player.getCurrentArmor(3).getItem() instanceof ArmorCivilWarAntman && player.getCurrentArmor(2).getItem() instanceof ArmorCivilWarAntman && player.getCurrentArmor(1).getItem() instanceof ArmorCivilWarAntman && player.getCurrentArmor(0).getItem() instanceof ArmorCivilWarAntman)
{
if (KeyHandler.ability01.isKeyDown() && !player.worldObj.isRemote)
{
width = ( Minecraft.getMinecraft().thePlayer.width * (1 / 3) );
height = ( Minecraft.getMinecraft().thePlayer.height * (1 / 3) );
eyeHeight = (Minecraft.getMinecraft().thePlayer.eyeHeight - 1.42F);
}
}
}
}
}
}
if (KeyHandler.ability01.isKeyDown() && !player.worldObj.isRemote)
This can't be true both at the same time (a server has no keys to press). Send a packet to the server when the key is pressed, and do everything else in the message handler (maybe you have to send the camera information back to the client, not sure if the server can do this).
Oh i see, oh boy... what should I do? I never touched message/packet.
Try getting used to basic networking and packet handling. Here is a god tutorial on how do do this.
When the server receives a packet from the client that the key was pressed check if that player is allowed to resize and then do the resize by setting the player's width/height and adjusting the camera position (maybe this has to be done on the client side by sending a packet back to the player) and the eyeHeight.
Jabelar also has a good tutorial on Networking and Packets. He also links to diesieben07's tutorial that also explains how to make packets thread-safe (in case your packet needs a LOT of processing that could cause memory leaks or lag the game otherwise). Thread-safety is extremely more important in 1.8+
diesieben's post also mentions that it is very simple to send a return packet or response to the client using the recommended methods.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
How can I have the player "grow" and "shrink" like Ant-Man with KeyBinding?
You have to change the height and width of the player entity for calculating collisions, then override the Entity#getEyeHeight method to set the correct camera position.
From which class do I call the height and width and where do I put the code into?
Here is a page about adding a KeyBind, then using the KeyInputEvent.
I know how to add my own keys. was wondering where do I put the code and which class does the height and width needs to be called from, EntityPlayer?
The basic Entity class does this, and Entity is superclass of EntityPlayer. So just use EntityPlayer#height/width.
Okay, if i'm overriding Entity#getEyeHeight, how do i even do that? Create my own entity???
No, you have to override that method for the player that changed it's size.
If I'm overriding the method, where will the overriding method be placed? Unless you mean I call the method in another class?
Well, I don't have much experience with modifying the player's camera, but if you don't mind reading lots of code you could look at the morph mod by iChun, it changes the camera position depending on the eye height of the entity that was "template" for this morph.
TickHandlerClient is where the eyeHeight is used (not sure about other classes). And it's lots and lots and lots of code. From what I can tell, iChun created his own field called float eyeHeight. And then he assigns a value to the field by Minecraft.getMinecraft().thePlayer.eyeHeight. Time for more reading.
Edit 1: On a side note: what event should I use in my eventhandler for this code to work? I'm working on the code in my eventhandler which uses LivingUpdateEvent
Mabye use the PlayerTickEvent
Btw you should probably reset everything if the player is not wearing the armor.
Scenario:
The player puts on your armor and shrinks, then he puts on other armor but still has a very small hitbox.
Reset everything??? What do you mean? I changed to PlayerTickEvent and it didn't work, code in the spoiler.
This can't be true both at the same time (a server has no keys to press). Send a packet to the server when the key is pressed, and do everything else in the message handler (maybe you have to send the camera information back to the client, not sure if the server can do this).
I don't want this on the server side, I want this on the client side
But you have to inform the server of every change you do to the client, i. e. the size of the player so the server can handle the collisions properly.
Oh i see, oh boy... what should I do? I never touched message/packet.
Try getting used to basic networking and packet handling. Here is a god tutorial on how do do this.
When the server receives a packet from the client that the key was pressed check if that player is allowed to resize and then do the resize by setting the player's width/height and adjusting the camera position (maybe this has to be done on the client side by sending a packet back to the player) and the eyeHeight.
Jabelar also has a good tutorial on Networking and Packets. He also links to diesieben07's tutorial that also explains how to make packets thread-safe (in case your packet needs a LOT of processing that could cause memory leaks or lag the game otherwise). Thread-safety is extremely more important in 1.8+
diesieben's post also mentions that it is very simple to send a return packet or response to the client using the recommended methods.