mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 14:27:59 +01:00
Add support for more than two states, and added a riding pose
This commit is contained in:
parent
1af726c06a
commit
21ac013034
8 changed files with 134 additions and 82 deletions
|
@ -0,0 +1,6 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IStyleFactory {
|
||||
Style getStyle();
|
||||
}
|
|
@ -1,41 +1,50 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import com.voxelmodpack.hdskins.util.MoreStreams;
|
||||
|
||||
public class IconicToggle extends IconicButton {
|
||||
|
||||
private Style onState = new Style();
|
||||
private Style offState = new Style();
|
||||
private Style[] styles;
|
||||
|
||||
private boolean value;
|
||||
private int value;
|
||||
|
||||
public IconicToggle(int x, int y, IGuiAction<IconicToggle> callback) {
|
||||
public IconicToggle(int x, int y, int states, IGuiAction<IconicToggle> callback) {
|
||||
super(x, y, callback);
|
||||
styles = new Style[states];
|
||||
for (int i = 0; i < styles.length; i++) {
|
||||
styles[i] = new Style();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public IconicToggle setValue(boolean value) {
|
||||
public IconicToggle setValue(int value) {
|
||||
if (this.value != value) {
|
||||
this.value = value;
|
||||
(value ? onState : offState).apply(this);
|
||||
this.value = value % styles.length;
|
||||
styles[this.value].apply(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IconicToggle setStyle(Style style, boolean value) {
|
||||
if (value) {
|
||||
onState = style;
|
||||
} else {
|
||||
offState = style;
|
||||
}
|
||||
public IconicToggle setStyles(IStyleFactory... styles) {
|
||||
this.styles = MoreStreams.map(styles, IStyleFactory::getStyle, Style[]::new);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IconicToggle setStyles(Style... styles) {
|
||||
this.styles = styles;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IconicToggle setStyle(Style style, int value) {
|
||||
value %= styles.length;
|
||||
|
||||
styles[value] = style;
|
||||
|
||||
if (this.value == value) {
|
||||
style.apply(this);
|
||||
|
@ -46,55 +55,7 @@ public class IconicToggle extends IconicButton {
|
|||
|
||||
@Override
|
||||
public void perform() {
|
||||
setValue(!value);
|
||||
setValue(value + 1);
|
||||
super.perform();
|
||||
}
|
||||
|
||||
public static class Style implements IGuiTooltipped<Style> {
|
||||
ItemStack icon = ItemStack.EMPTY;
|
||||
|
||||
private boolean hasOffset = false;
|
||||
private int toolTipX = 0;
|
||||
private int toolTipY = 0;
|
||||
|
||||
private List<String> tooltip;
|
||||
|
||||
public Style setIcon(ItemStack stack) {
|
||||
icon = stack;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Style setIcon(ItemStack stack, int colour) {
|
||||
Items.LEATHER_LEGGINGS.setColor(stack, colour);
|
||||
return setIcon(stack);
|
||||
}
|
||||
|
||||
protected void apply(IconicToggle button) {
|
||||
button.setIcon(icon)
|
||||
.setTooltip(tooltip);
|
||||
if (hasOffset) {
|
||||
button.setTooltipOffset(toolTipX, toolTipY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style setTooltip(List<String> tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style setTooltipOffset(int x, int y) {
|
||||
hasOffset = true;
|
||||
toolTipX = x;
|
||||
toolTipY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
55
src/hdskins/java/com/minelittlepony/gui/Style.java
Normal file
55
src/hdskins/java/com/minelittlepony/gui/Style.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Style implements IGuiTooltipped<Style> {
|
||||
ItemStack icon = ItemStack.EMPTY;
|
||||
|
||||
private boolean hasOffset = false;
|
||||
private int toolTipX = 0;
|
||||
private int toolTipY = 0;
|
||||
|
||||
private List<String> tooltip;
|
||||
|
||||
public Style setIcon(ItemStack stack) {
|
||||
icon = stack;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Style setIcon(ItemStack stack, int colour) {
|
||||
Items.LEATHER_LEGGINGS.setColor(stack, colour);
|
||||
return setIcon(stack);
|
||||
}
|
||||
|
||||
protected void apply(IconicToggle button) {
|
||||
button.setIcon(icon)
|
||||
.setTooltip(tooltip);
|
||||
if (hasOffset) {
|
||||
button.setTooltipOffset(toolTipX, toolTipY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style setTooltip(List<String> tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style setTooltipOffset(int x, int y) {
|
||||
hasOffset = true;
|
||||
toolTipX = x;
|
||||
toolTipY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
|
||||
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
|
|||
|
||||
protected boolean previewThinArms = false;
|
||||
protected boolean previewSleeping = false;
|
||||
protected boolean previewRiding = false;
|
||||
|
||||
public EntityPlayerModel(GameProfile gameprofile) {
|
||||
super(DummyWorld.INSTANCE);
|
||||
|
@ -109,14 +110,23 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
|
|||
previewSleeping = sleep;
|
||||
}
|
||||
|
||||
public void setRiding(boolean ride) {
|
||||
previewRiding = ride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRiding() {
|
||||
return previewRiding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerSleeping() {
|
||||
return previewSleeping;
|
||||
return !previewRiding && previewSleeping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return !previewSleeping && super.isSneaking();
|
||||
return !previewRiding && !previewSleeping && super.isSneaking();
|
||||
}
|
||||
|
||||
public void updateModel() {
|
||||
|
@ -138,7 +148,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
|
|||
motionY = 0;
|
||||
}
|
||||
|
||||
if (posY == 0 && isJumping && !previewSleeping) {
|
||||
if (posY == 0 && isJumping && !previewSleeping && !previewRiding) {
|
||||
jump();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.minelittlepony.gui.GameGui;
|
|||
import com.minelittlepony.gui.IconicButton;
|
||||
import com.minelittlepony.gui.IconicToggle;
|
||||
import com.minelittlepony.gui.Label;
|
||||
import com.minelittlepony.gui.Style;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||
|
@ -194,15 +195,21 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
|
|||
.setTooltip(format("hdskins.mode.skin", toTitleCase(Type.ELYTRA.name())))
|
||||
.setTooltipOffset(0, 10);
|
||||
|
||||
addButton(new IconicToggle(width - 25, 118, sender -> {
|
||||
addButton(new IconicToggle(width - 25, 118, 3, sender -> {
|
||||
playSound(SoundEvents.BLOCK_BREWING_STAND_BREW);
|
||||
|
||||
localPlayer.setSleeping(sender.getValue());
|
||||
remotePlayer.setSleeping(sender.getValue());
|
||||
boolean sleep = sender.getValue() == 1;
|
||||
boolean ride = sender.getValue() == 2;
|
||||
localPlayer.setSleeping(sleep);
|
||||
remotePlayer.setSleeping(sleep);
|
||||
|
||||
localPlayer.setRiding(ride);
|
||||
remotePlayer.setRiding(ride);
|
||||
}))
|
||||
.setValue(localPlayer.isPlayerSleeping())
|
||||
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.IRON_BOOTS, 1)).setTooltip("Standing"), false)
|
||||
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.CLOCK, 1)).setTooltip("Sleeping"), true)
|
||||
.setValue(localPlayer.isPlayerSleeping() ? 1 : 0)
|
||||
.setStyle(new Style().setIcon(new ItemStack(Items.IRON_BOOTS, 1)).setTooltip("Standing"), 0)
|
||||
.setStyle(new Style().setIcon(new ItemStack(Items.CLOCK, 1)).setTooltip("Sleeping"), 1)
|
||||
.setStyle(new Style().setIcon(new ItemStack(Items.BOAT, 1)).setTooltip("Riding"), 2)
|
||||
.setTooltipOffset(0, 10);
|
||||
|
||||
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package com.voxelmodpack.hdskins.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MoreStreams {
|
||||
|
@ -8,4 +13,11 @@ public class MoreStreams {
|
|||
public static <T> Stream<T> ofNullable(@Nullable T t) {
|
||||
return t == null ? Stream.empty() : Stream.of(t);
|
||||
}
|
||||
|
||||
public static <T, V> V[] map(T[] items, Function<T, V> converter, IntFunction<V[]> collector) {
|
||||
return Lists.newArrayList(items)
|
||||
.stream()
|
||||
.map(converter)
|
||||
.toArray(collector);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.hdskins.gui;
|
|||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.PonyManager;
|
||||
import com.minelittlepony.gui.IconicToggle;
|
||||
import com.minelittlepony.gui.Style;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
|
@ -45,10 +46,10 @@ public class GuiSkinsMineLP extends GuiSkins {
|
|||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
addButton(new IconicToggle(width - 25, 142, sender -> setWet(sender.getValue()))
|
||||
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.WATER_BUCKET)).setTooltip("minelp.mode.wet"), true)
|
||||
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.BUCKET)).setTooltip("minelp.mode.dry"), false)
|
||||
.setValue(isWet)
|
||||
addButton(new IconicToggle(width - 25, 142, 2, sender -> setWet(sender.getValue() == 1))
|
||||
.setStyle(new Style().setIcon(new ItemStack(Items.WATER_BUCKET)).setTooltip("minelp.mode.wet"), 1)
|
||||
.setStyle(new Style().setIcon(new ItemStack(Items.BUCKET)).setTooltip("minelp.mode.dry"), 0)
|
||||
.setValue(isWet ? 1 : 0)
|
||||
.setTooltipOffset(0, 10));
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P
|
|||
|
||||
super.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity);
|
||||
|
||||
float headRotateAngleY = isSleeping() ? 1.4f : headYaw / 57.29578F;
|
||||
float headRotateAngleY = isSleeping() ? (Math.abs(entity.getUniqueID().getMostSignificantBits()) % 2.8F) - 1.9F : headYaw / 57.29578F;
|
||||
float headRotateAngleX = isSleeping() ? 0.1f : headPitch / 57.29578F;
|
||||
|
||||
headRotateAngleX = Math.min(headRotateAngleX, (float) (0.5f - Math.toRadians(motionPitch)));
|
||||
|
|
Loading…
Reference in a new issue