Skip to content

Commit

Permalink
Merge branch 'hca' into changeling-master
Browse files Browse the repository at this point in the history
  • Loading branch information
asanetargoss committed Jan 15, 2021
2 parents 1f3367a + d07f8a3 commit 2cc5411
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AcquiredCategory(MorphSection parent, String title)

public void setMorph(List<AbstractMorph> morphs)
{
this.morphs = morphs;
this.morphs = morphs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public UserSection(String title)

this.acquired = new AcquiredCategory(this, "acquired");
this.recent = new RecentCategory(this, "recent");
this.add(this.acquired);
}

@Override
Expand Down
39 changes: 27 additions & 12 deletions src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package mchorse.metamorph.api.morphs;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.reflect.FieldUtils;

import mchorse.mclib.client.gui.utils.GuiUtils;
import mchorse.metamorph.Metamorph;
import mchorse.metamorph.api.EntityUtils;
Expand Down Expand Up @@ -50,17 +62,6 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.reflect.FieldUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* Entity morph class
Expand Down Expand Up @@ -1024,7 +1025,12 @@ public SoundEvent getHurtSound(EntityLivingBase target, DamageSource damageSourc
try
{
Method methodHurtSound = InvokeUtil.getPrivateMethod(entity.getClass(), EntityLivingBase.class, SoundHandler.GET_HURT_SOUND.getName());
SoundEvent hurtSound = (SoundEvent) methodHurtSound.invoke(entity);
if (methodHurtSound == null)
{
return null;
}

SoundEvent hurtSound = (SoundEvent)methodHurtSound.invoke(entity);
if (hurtSound == null)
{
hurtSound = SoundHandler.NO_SOUND;
Expand All @@ -1046,6 +1052,11 @@ public SoundEvent getDeathSound(EntityLivingBase target)
try
{
Method methodDeathSound = InvokeUtil.getPrivateMethod(entity.getClass(), EntityLivingBase.class, SoundHandler.GET_DEATH_SOUND.getName());
if (methodDeathSound == null)
{
return null;
}

SoundEvent deathSound = (SoundEvent) methodDeathSound.invoke(entity);
if (deathSound == null)
{
Expand Down Expand Up @@ -1074,6 +1085,10 @@ public void playStepSound(EntityLivingBase target)
try
{
Method methodPlayStep = InvokeUtil.getPrivateMethod(entity.getClass(), Entity.class, SoundHandler.PLAY_STEP_SOUND.getName(), BlockPos.class, Block.class);
if (methodPlayStep == null)
{
return;
}

int x = MathHelper.floor(entity.posX);
int y = MathHelper.floor(entity.posY - 0.20000000298023224D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void onKey(InputEvent.KeyInputEvent event)
{
int key = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();

ClientProxy.getSurvivalScreen().onKeyPre();
MorphManager.INSTANCE.list.keyTyped(player, key);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,14 @@ public void setupSections(boolean creative, Consumer<GuiMorphSection> callback)
MorphList list = MorphManager.INSTANCE.list;
IMorphing cap = Morphing.get(mc.player);

MorphSection section;
AcquiredCategory category;
UserSection section = (UserSection)list.sections.get(0);
AcquiredCategory category = section.acquired;

if (creative || Metamorph.allowMorphingIntoCategoryMorphs.get())
if (!(creative || Metamorph.allowMorphingIntoCategoryMorphs.get()))
{
UserSection user = (UserSection) list.sections.get(0);

section = user;
section.update(mc.world);
category = user.acquired;
}
else
{
section = new MorphSection("user");
category = new AcquiredCategory(section, "acquired");

category.setMorph(cap == null ? Collections.emptyList() : cap.getAcquiredMorphs());
section.add(category);
}
section.update(mc.world);

GuiMorphSection element = section.getGUI(mc, null, callback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;

import java.io.IOException;

import org.lwjgl.input.Keyboard;

/**
Expand All @@ -53,7 +55,8 @@ public class GuiSurvivalScreen extends GuiBase

AbstractMorph lastMorphSelected = null;
private static final int DOUBLE_CLICK_TIME_MS = 500;
private long lastClickTime = -DOUBLE_CLICK_TIME_MS - 1;
private long lastMorphSelectTime = -DOUBLE_CLICK_TIME_MS - 1;
private boolean isClicking = false;

public GuiSurvivalScreen()
{
Expand Down Expand Up @@ -96,14 +99,10 @@ public boolean doesGuiPauseGame()
{
return Metamorph.pauseGUIInSP.get();
}

/**
* Open the survival morph menu and update the morphs element
*/
public GuiSurvivalScreen open()

public void setupSections()
{
EntityPlayer player = Minecraft.getMinecraft().player;
IMorphing cap = Morphing.get(player);
boolean creative = player.isCreative();
boolean allowed = Metamorph.allowMorphingIntoCategoryMorphs.get();

Expand All @@ -113,11 +112,27 @@ public GuiSurvivalScreen open()
this.allowed = allowed;
this.morphs.setupSections(creative, (section) -> this.fill(section.morph));
}
}

/**
* Open the survival morph menu and update the morphs element
*/
public GuiSurvivalScreen open()
{
EntityPlayer player = Minecraft.getMinecraft().player;
IMorphing cap = Morphing.get(player);

this.setupSections();

this.setSelected(cap.getCurrentMorph());

return this;
}

public void onKeyPre()
{
setupSections();
}

/**
* Set given morph selected
Expand Down Expand Up @@ -149,22 +164,47 @@ public void checkCurrentMorph()
checkCurrentMorph(currentMorph, this.morphs.getSelected());
}

private void checkDoubleClick(AbstractMorph morph)
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
isClicking = true;
super.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
protected void mouseReleased(int mouseX, int mouseY, int state)
{
isClicking = false;
super.mouseReleased(mouseX, mouseY, state);
}

@Override
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
{
isClicking = false;
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}

private void checkDoubleClickMorph(AbstractMorph morph)
{
if (morph == null)
{
return;
}
if (!isClicking)
{
return;
}

long clickTime = Minecraft.getSystemTime();
long dt = clickTime - lastClickTime;
lastClickTime = clickTime;
long morphSelectTime = Minecraft.getSystemTime();
long dt = morphSelectTime - lastMorphSelectTime;
lastMorphSelectTime = morphSelectTime;
if (dt > 0 && dt < DOUBLE_CLICK_TIME_MS && lastMorphSelected.equals(morph))
{
MorphAPI.selectMorph(morph);
GuiUtils.playClick();
// Prevent re-fires
lastClickTime = 0;
lastMorphSelectTime = 0;
this.closeScreen();
}
lastMorphSelected = morph;
Expand All @@ -191,7 +231,7 @@ public void fill(AbstractMorph morph)
this.keybind.setKeybind(morph.keybind);
}

checkDoubleClick(morph);
checkDoubleClickMorph(morph);
}

/**
Expand Down
Loading

0 comments on commit 2cc5411

Please sign in to comment.