mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 01:57:34 +00:00
Merge pull request #116 from Goodbird-git/hitbox-settings
Implemented the ability to change hitbox size
This commit is contained in:
5 files changed
+136
-17
No files matched your search
@@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.controllers.data.CustomHitboxData;
|
||||
import noppes.npcs.controllers.data.CustomTintData;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -61,8 +62,9 @@ public class DataDisplay {
|
||||
|
||||
//0 - Yes, 1 - No, 2 - Only NPCs, 3 - Only Players, 4 - NPCs and Players
|
||||
public int collidesWith = 1;
|
||||
|
||||
public CustomTintData customTintData;
|
||||
|
||||
public CustomHitboxData customHitboxData;
|
||||
public CustomTintData customTintData;
|
||||
|
||||
public DataDisplay(EntityNPCInterface npc){
|
||||
this.npc = npc;
|
||||
@@ -70,7 +72,8 @@ public class DataDisplay {
|
||||
skinOverlayData = new DataSkinOverlays(npc);
|
||||
name = getRandomName();
|
||||
animationData = new AnimationData(this);
|
||||
customTintData = new CustomTintData();
|
||||
customHitboxData = new CustomHitboxData();
|
||||
customTintData = new CustomTintData();
|
||||
}
|
||||
|
||||
public String getRandomName() {
|
||||
@@ -92,8 +95,8 @@ public class DataDisplay {
|
||||
nbttagcompound = skinOverlayData.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound = animationData.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound = customTintData.writeToNBT(nbttagcompound);
|
||||
nbttagcompound = customHitboxData.writeToNBT(nbttagcompound);
|
||||
nbttagcompound = customTintData.writeToNBT(nbttagcompound);
|
||||
|
||||
if (this.playerProfile != null)
|
||||
{
|
||||
@@ -119,7 +122,6 @@ public class DataDisplay {
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("InvisibleToList", list);
|
||||
|
||||
return nbttagcompound;
|
||||
}
|
||||
public void readToNBT(NBTTagCompound nbttagcompound) {
|
||||
@@ -171,9 +173,9 @@ public class DataDisplay {
|
||||
skinOverlayData.readFromNBT(nbttagcompound);
|
||||
|
||||
animationData.readFromNBT(nbttagcompound);
|
||||
|
||||
customTintData.readFromNBT(nbttagcompound);
|
||||
|
||||
customHitboxData.readFromNBT(nbttagcompound);
|
||||
customTintData.readFromNBT(nbttagcompound);
|
||||
|
||||
modelSize = ValueUtil.clamp(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
|
||||
if(modelSize > ConfigMain.NpcSizeLimit)
|
||||
modelSize = ConfigMain.NpcSizeLimit;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.data.CustomHitboxData;
|
||||
|
||||
public class SubGuiCustomHitbox extends SubGuiInterface implements ITextfieldListener
|
||||
{
|
||||
private CustomHitboxData hitboxData;
|
||||
public SubGuiCustomHitbox(CustomHitboxData hitboxData){
|
||||
this.hitboxData = hitboxData;
|
||||
setBackground("menubg.png");
|
||||
xSize = 256;
|
||||
ySize = 216;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
addLabel(new GuiNpcLabel(0,"Custom hitbox", guiLeft + 5, guiTop + 35));
|
||||
addButton(new GuiNpcButtonYesNo(0,guiLeft + 122, guiTop + 30, 56, 20 ,hitboxData.isCustomHitbox()));
|
||||
if(hitboxData.isCustomHitbox()){
|
||||
addLabel(new GuiNpcLabel(3,"Width", guiLeft + 5, guiTop + 57));
|
||||
addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 122, guiTop + 53, 50, 18, hitboxData.getWidth() + ""));
|
||||
getTextField(2).floatsOnly = true;
|
||||
getTextField(2).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 20);
|
||||
|
||||
addLabel(new GuiNpcLabel(4,"Height", guiLeft + 5, guiTop + 79));
|
||||
addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + 75, 50, 18, hitboxData.getHeight() + ""));
|
||||
getTextField(3).floatsOnly = true;
|
||||
getTextField(3).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 20);
|
||||
}
|
||||
addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190,98, 20, "gui.done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
int id = guibutton.id;
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
if(button.id == 0){
|
||||
hitboxData.setCustomHitbox(((GuiNpcButtonYesNo)button).getBoolean());
|
||||
initGui();
|
||||
}
|
||||
if(id == 66){
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
if(textfield.id == 2){
|
||||
hitboxData.setWidth(textfield.getFloat());
|
||||
}
|
||||
if(textfield.id == 3){
|
||||
hitboxData.setHeight(textfield.getFloat());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
|
||||
y+=23;
|
||||
addLabel(new GuiNpcLabel(11,"gui.title", guiLeft + 5, y + 5));
|
||||
addTextField(new GuiNpcTextField(11,this, fontRendererObj, guiLeft + 50, y, 206, 20, display.title));
|
||||
|
||||
y+=23;
|
||||
addLabel(new GuiNpcLabel(1,"display.model", guiLeft + 5, y + 5));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 50, y,110,20, "selectServer.edit"));
|
||||
@@ -87,14 +86,14 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
|
||||
y+=23;
|
||||
addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5));
|
||||
this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible));
|
||||
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings"));
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings"));
|
||||
this.addButton(new GuiNpcButton(12,guiLeft + 300, y, 100, 20, "display.hitbox"));
|
||||
|
||||
y+=23;
|
||||
addLabel(new GuiNpcLabel(10,"display.bossbar", guiLeft + 5, y + 5));
|
||||
this.addButton(new GuiNpcButton(10, guiLeft + 60, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar));
|
||||
|
||||
GeckoAddonClient.Instance.geckoNpcDisplayInitGui(this);
|
||||
GeckoAddonClient.Instance.geckoNpcDisplayInitGui(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,9 +183,12 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
|
||||
npc.display.skinOverlayData.overlayList.get(0).setBlend(button.getValue() == 0);
|
||||
initGui();
|
||||
}
|
||||
else if (button.id == 13){
|
||||
setSubGui(new SubGuiNpcTint(display.customTintData));
|
||||
}
|
||||
else if (button.id == 12){
|
||||
setSubGui(new SubGuiCustomHitbox(display.customHitboxData));
|
||||
}
|
||||
else if (button.id == 13){
|
||||
setSubGui(new SubGuiNpcTint(display.customTintData));
|
||||
}
|
||||
else if(button.id == 14){
|
||||
String name = display.getRandomName();
|
||||
display.setName(name);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class CustomHitboxData {
|
||||
private float width = 1f;
|
||||
private float height = 1.8f;
|
||||
|
||||
private boolean customHitbox = false;
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setBoolean("CustomHitbox", customHitbox);
|
||||
if(customHitbox) {
|
||||
nbttagcompound.setFloat("HitboxWidth", width);
|
||||
nbttagcompound.setFloat("HitboxHeight", height);
|
||||
}
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
customHitbox = nbttagcompound.getBoolean("CustomHitbox");
|
||||
if(customHitbox) {
|
||||
width = nbttagcompound.getFloat("HitboxWidth");
|
||||
height = nbttagcompound.getFloat("HitboxHeight");
|
||||
}
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean isCustomHitbox() {
|
||||
return customHitbox;
|
||||
}
|
||||
|
||||
public void setCustomHitbox(boolean customHitbox) {
|
||||
this.customHitbox = customHitbox;
|
||||
}
|
||||
}
|
||||
@@ -1093,7 +1093,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
if(width / 2 > worldObj.MAX_ENTITY_RADIUS) {
|
||||
worldObj.MAX_ENTITY_RADIUS = width / 2;
|
||||
}
|
||||
|
||||
if(display.customHitboxData.isCustomHitbox()){
|
||||
width = display.customHitboxData.getWidth();
|
||||
height = display.customHitboxData.getHeight();
|
||||
}
|
||||
this.setPosition(posX, posY, posZ);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user