Add support for more than two states, and added a riding pose

This commit is contained in:
Sollace 2018-10-20 16:57:49 +02:00
parent 1af726c06a
commit 21ac013034
8 changed files with 134 additions and 82 deletions

View file

@ -0,0 +1,6 @@
package com.minelittlepony.gui;
@FunctionalInterface
public interface IStyleFactory {
Style getStyle();
}

View file

@ -1,41 +1,50 @@
package com.minelittlepony.gui; package com.minelittlepony.gui;
import net.minecraft.client.Minecraft; import com.voxelmodpack.hdskins.util.MoreStreams;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import java.util.List;
public class IconicToggle extends IconicButton { public class IconicToggle extends IconicButton {
private Style onState = new Style(); private Style[] styles;
private Style offState = new Style();
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); 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; return value;
} }
public IconicToggle setValue(boolean value) { public IconicToggle setValue(int value) {
if (this.value != value) { if (this.value != value) {
this.value = value; this.value = value % styles.length;
(value ? onState : offState).apply(this); styles[this.value].apply(this);
} }
return this; return this;
} }
public IconicToggle setStyle(Style style, boolean value) { public IconicToggle setStyles(IStyleFactory... styles) {
if (value) { this.styles = MoreStreams.map(styles, IStyleFactory::getStyle, Style[]::new);
onState = style;
} else { return this;
offState = style; }
}
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) { if (this.value == value) {
style.apply(this); style.apply(this);
@ -46,55 +55,7 @@ public class IconicToggle extends IconicButton {
@Override @Override
public void perform() { public void perform() {
setValue(!value); setValue(value + 1);
super.perform(); 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) {
}
}
} }

View 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) {
}
}

View file

@ -42,6 +42,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
protected boolean previewThinArms = false; protected boolean previewThinArms = false;
protected boolean previewSleeping = false; protected boolean previewSleeping = false;
protected boolean previewRiding = false;
public EntityPlayerModel(GameProfile gameprofile) { public EntityPlayerModel(GameProfile gameprofile) {
super(DummyWorld.INSTANCE); super(DummyWorld.INSTANCE);
@ -109,14 +110,23 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
previewSleeping = sleep; previewSleeping = sleep;
} }
public void setRiding(boolean ride) {
previewRiding = ride;
}
@Override
public boolean isRiding() {
return previewRiding;
}
@Override @Override
public boolean isPlayerSleeping() { public boolean isPlayerSleeping() {
return previewSleeping; return !previewRiding && previewSleeping;
} }
@Override @Override
public boolean isSneaking() { public boolean isSneaking() {
return !previewSleeping && super.isSneaking(); return !previewRiding && !previewSleeping && super.isSneaking();
} }
public void updateModel() { public void updateModel() {
@ -138,7 +148,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
motionY = 0; motionY = 0;
} }
if (posY == 0 && isJumping && !previewSleeping) { if (posY == 0 && isJumping && !previewSleeping && !previewRiding) {
jump(); jump();
} }

View file

@ -5,6 +5,7 @@ import com.minelittlepony.gui.GameGui;
import com.minelittlepony.gui.IconicButton; import com.minelittlepony.gui.IconicButton;
import com.minelittlepony.gui.IconicToggle; import com.minelittlepony.gui.IconicToggle;
import com.minelittlepony.gui.Label; import com.minelittlepony.gui.Label;
import com.minelittlepony.gui.Style;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.voxelmodpack.hdskins.HDSkinManager; 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()))) .setTooltip(format("hdskins.mode.skin", toTitleCase(Type.ELYTRA.name())))
.setTooltipOffset(0, 10); .setTooltipOffset(0, 10);
addButton(new IconicToggle(width - 25, 118, sender -> { addButton(new IconicToggle(width - 25, 118, 3, sender -> {
playSound(SoundEvents.BLOCK_BREWING_STAND_BREW); playSound(SoundEvents.BLOCK_BREWING_STAND_BREW);
localPlayer.setSleeping(sender.getValue()); boolean sleep = sender.getValue() == 1;
remotePlayer.setSleeping(sender.getValue()); boolean ride = sender.getValue() == 2;
localPlayer.setSleeping(sleep);
remotePlayer.setSleeping(sleep);
localPlayer.setRiding(ride);
remotePlayer.setRiding(ride);
})) }))
.setValue(localPlayer.isPlayerSleeping()) .setValue(localPlayer.isPlayerSleeping() ? 1 : 0)
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.IRON_BOOTS, 1)).setTooltip("Standing"), false) .setStyle(new Style().setIcon(new ItemStack(Items.IRON_BOOTS, 1)).setTooltip("Standing"), 0)
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.CLOCK, 1)).setTooltip("Sleeping"), true) .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); .setTooltipOffset(0, 10);
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> { addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {

View file

@ -1,6 +1,11 @@
package com.voxelmodpack.hdskins.util; package com.voxelmodpack.hdskins.util;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.common.collect.Lists;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class MoreStreams { public class MoreStreams {
@ -8,4 +13,11 @@ public class MoreStreams {
public static <T> Stream<T> ofNullable(@Nullable T t) { public static <T> Stream<T> ofNullable(@Nullable T t) {
return t == null ? Stream.empty() : Stream.of(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);
}
} }

View file

@ -3,6 +3,7 @@ package com.minelittlepony.hdskins.gui;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyManager; import com.minelittlepony.PonyManager;
import com.minelittlepony.gui.IconicToggle; import com.minelittlepony.gui.IconicToggle;
import com.minelittlepony.gui.Style;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
@ -45,10 +46,10 @@ public class GuiSkinsMineLP extends GuiSkins {
public void initGui() { public void initGui() {
super.initGui(); super.initGui();
addButton(new IconicToggle(width - 25, 142, sender -> setWet(sender.getValue())) addButton(new IconicToggle(width - 25, 142, 2, sender -> setWet(sender.getValue() == 1))
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.WATER_BUCKET)).setTooltip("minelp.mode.wet"), true) .setStyle(new Style().setIcon(new ItemStack(Items.WATER_BUCKET)).setTooltip("minelp.mode.wet"), 1)
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.BUCKET)).setTooltip("minelp.mode.dry"), false) .setStyle(new Style().setIcon(new ItemStack(Items.BUCKET)).setTooltip("minelp.mode.dry"), 0)
.setValue(isWet) .setValue(isWet ? 1 : 0)
.setTooltipOffset(0, 10)); .setTooltipOffset(0, 10));
} }

View file

@ -105,7 +105,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P
super.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); 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; float headRotateAngleX = isSleeping() ? 0.1f : headPitch / 57.29578F;
headRotateAngleX = Math.min(headRotateAngleX, (float) (0.5f - Math.toRadians(motionPitch))); headRotateAngleX = Math.min(headRotateAngleX, (float) (0.5f - Math.toRadians(motionPitch)));