mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 19:54:26 +00:00
Compare commits
5
Commits
master
...
guide-books
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be173f13ca | ||
|
|
2567bf63b0 | ||
|
|
a591fef66e | ||
|
|
160f3ae628 | ||
|
|
32839206d3 |
No files matched your search
@@ -19,7 +19,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
|||||||
import net.minecraftforge.client.event.RenderHandEvent;
|
import net.minecraftforge.client.event.RenderHandEvent;
|
||||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||||
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||||
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||||
import noppes.npcs.client.gui.hud.ClientHudManager;
|
import noppes.npcs.client.gui.hud.ClientHudManager;
|
||||||
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
||||||
@@ -36,6 +38,7 @@ import noppes.npcs.controllers.data.FramePart;
|
|||||||
import noppes.npcs.controllers.data.MarkData;
|
import noppes.npcs.controllers.data.MarkData;
|
||||||
import noppes.npcs.controllers.data.PlayerData;
|
import noppes.npcs.controllers.data.PlayerData;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
|
import somehussar.gui.guides.GuideController;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -79,6 +82,12 @@ public class ClientEventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void worldEventLoad(WorldEvent.Load event) {
|
||||||
|
GuideController.resetGlint();
|
||||||
|
GuideController.handleWorldJoin();
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onItemTooltip(ItemTooltipEvent event) {
|
public void onItemTooltip(ItemTooltipEvent event) {
|
||||||
AuctionTooltipHandler.onItemTooltip(event);
|
AuctionTooltipHandler.onItemTooltip(event);
|
||||||
|
|||||||
@@ -254,14 +254,13 @@ import noppes.npcs.items.ItemNpcTool;
|
|||||||
import noppes.npcs.items.ItemScripted;
|
import noppes.npcs.items.ItemScripted;
|
||||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import tconstruct.client.tabs.InventoryTabCustomNpc;
|
import tconstruct.client.tabs.*;
|
||||||
import tconstruct.client.tabs.InventoryTabVanilla;
|
|
||||||
import tconstruct.client.tabs.TabRegistry;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class ClientProxy extends CommonProxy {
|
public class ClientProxy extends CommonProxy {
|
||||||
@@ -386,14 +385,34 @@ public class ClientProxy extends CommonProxy {
|
|||||||
MinecraftForge.EVENT_BUS.register(new LightningHandler());
|
MinecraftForge.EVENT_BUS.register(new LightningHandler());
|
||||||
|
|
||||||
if (ConfigClient.InventoryGuiEnabled) {
|
if (ConfigClient.InventoryGuiEnabled) {
|
||||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
setupTabs();
|
||||||
if (TabRegistry.getTabList().isEmpty()) {
|
|
||||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
|
||||||
}
|
|
||||||
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupTabs() {
|
||||||
|
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||||
|
|
||||||
|
ensureInventoryTabIsFirst();
|
||||||
|
|
||||||
|
TabRegistry.getTabList().add(1, new InventoryTabGuides());
|
||||||
|
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureInventoryTabIsFirst() {
|
||||||
|
List<AbstractTab> tabList = TabRegistry.getTabList();
|
||||||
|
|
||||||
|
// Find the first inventory tab or create one.
|
||||||
|
InventoryTabVanilla vanillaTab = tabList.stream()
|
||||||
|
.filter(InventoryTabVanilla.class::isInstance)
|
||||||
|
.map(InventoryTabVanilla.class::cast)
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(InventoryTabVanilla::new);
|
||||||
|
|
||||||
|
// Move the inventory tab to be the FIRST in the list no matter what.
|
||||||
|
tabList.remove(vanillaTab);
|
||||||
|
tabList.add(0, vanillaTab);
|
||||||
|
}
|
||||||
|
|
||||||
public FakePlayer getCommandPlayer(IWorld world) {
|
public FakePlayer getCommandPlayer(IWorld world) {
|
||||||
return (FakePlayer) (new EntityCustomNpc(world.getMCWorld())).getFakePlayer();
|
return (FakePlayer) (new EntityCustomNpc(world.getMCWorld())).getFakePlayer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package somehussar.gui;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
|
||||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
|
||||||
import somehussar.gui.annotationHandling.GuiFieldHandler;
|
|
||||||
import somehussar.gui.annotationHandling.field.EditableField;
|
|
||||||
|
|
||||||
public class AnnotatedGui<T> extends SubGuiInterface {
|
|
||||||
private final GuiFieldHandler.ClassMetadata metadata;
|
|
||||||
|
|
||||||
public AnnotatedGui(T object, String[] groups, GuiScreen parent) {
|
|
||||||
this(object, groups, parent, 256, 216);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnnotatedGui(T object, String[] groups, GuiScreen parent, int xSize, int ySize) {
|
|
||||||
if (object != null)
|
|
||||||
metadata = GuiFieldHandler.getMetadata(object.getClass());
|
|
||||||
else
|
|
||||||
metadata = null;
|
|
||||||
setBackground("menubg.png");
|
|
||||||
this.xSize = xSize;
|
|
||||||
this.ySize = ySize;
|
|
||||||
closeOnEsc = true;
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
if (metadata == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (EditableField field : metadata.getParent().getDeclaredFields()) {
|
|
||||||
addLabel(new GuiNpcLabel(i++, field.getName(), guiLeft + 8, guiTop + i * 15 + 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package somehussar.gui;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
|
||||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
|
||||||
import somehussar.gui.annotationHandling.field.EditableField;
|
|
||||||
|
|
||||||
public class ImmediateTextField extends GuiNpcTextField {
|
|
||||||
private final EditableField editableField;
|
|
||||||
//
|
|
||||||
// private final GuiNpcTextField encapsulatedField;
|
|
||||||
|
|
||||||
public ImmediateTextField(int id, EditableField field, int xPos, int yPos) {
|
|
||||||
this(id, field, Minecraft.getMinecraft().fontRenderer, xPos, yPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImmediateTextField(int id, EditableField field, FontRenderer fontRenderer, int xPos, int yPos) {
|
|
||||||
super(id, null, fontRenderer, xPos, yPos, 0, 0, null);
|
|
||||||
|
|
||||||
this.editableField = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawTextBox(int mousX, int mousY) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(int xPos, int yPos, int k) {
|
|
||||||
xPos -= this.xPosition;
|
|
||||||
yPos -= this.yPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling;
|
|
||||||
|
|
||||||
public interface FieldConstraint {
|
|
||||||
void validate(Object value);
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling;
|
|
||||||
|
|
||||||
public final class FieldConstraints {
|
|
||||||
|
|
||||||
private static final FieldConstraints EMPTY =
|
|
||||||
new FieldConstraints(new FieldConstraint[0]);
|
|
||||||
|
|
||||||
private final FieldConstraint[] constraints;
|
|
||||||
|
|
||||||
public FieldConstraints(FieldConstraint[] constraints) {
|
|
||||||
this.constraints = constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FieldConstraints empty() {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate(Object value) {
|
|
||||||
for (FieldConstraint c : constraints) {
|
|
||||||
c.validate(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return constraints.length == 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface GuiEditable {
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@interface Field {
|
|
||||||
String value();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display order
|
|
||||||
* Higher value = higher priority.
|
|
||||||
*/
|
|
||||||
int order() default 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@interface Group {
|
|
||||||
String value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@interface Size {
|
|
||||||
int labelWidth() default 60;
|
|
||||||
|
|
||||||
int fieldWidth() default 50;
|
|
||||||
|
|
||||||
GuiEditable.Size DEFAULT_SIZE = new GuiEditable.Size() {
|
|
||||||
@Override
|
|
||||||
public int labelWidth() {
|
|
||||||
return 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int fieldWidth() {
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Annotation> annotationType() {
|
|
||||||
return GuiEditable.Size.class;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling;
|
|
||||||
|
|
||||||
import somehussar.gui.annotationHandling.constraints.ConstraintFactory;
|
|
||||||
import somehussar.gui.annotationHandling.constraints.NumericConstraint;
|
|
||||||
import somehussar.gui.annotationHandling.constraints.NumericConstraintFactory;
|
|
||||||
import somehussar.gui.annotationHandling.field.EditableField;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class GuiFieldHandler {
|
|
||||||
|
|
||||||
private static final Map<Class<?>, ClassMetadata> CACHE = new HashMap<>();
|
|
||||||
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
|
||||||
|
|
||||||
public static final Map<Class<? extends Annotation>, ConstraintFactory<?>> registry = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
registry.put(NumericConstraint.class, new NumericConstraintFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private GuiFieldHandler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ClassMetadata getMetadata(Class<?> type) {
|
|
||||||
return CACHE.computeIfAbsent(type, GuiFieldHandler::scanClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"RawUseOfParameterized"})
|
|
||||||
private static ClassMetadata scanClass(Class<?> type) {
|
|
||||||
if (!type.isAnnotationPresent(GuiEditable.class)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassMetadata parent = null;
|
|
||||||
|
|
||||||
Class<?> superCls = type.getSuperclass();
|
|
||||||
if (superCls != null && superCls != Object.class) {
|
|
||||||
parent = getMetadata(superCls);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<EditableField> list = new ArrayList<>();
|
|
||||||
for (Field field : type.getDeclaredFields()) {
|
|
||||||
EditableField editableField = createEditableField(field);
|
|
||||||
|
|
||||||
if (editableField != null) {
|
|
||||||
list.add(editableField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ClassMetadata(
|
|
||||||
type,
|
|
||||||
list.toArray(list.toArray(new EditableField[0])),
|
|
||||||
parent
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"RawUseOfParameterized", "unchecked"})
|
|
||||||
private static EditableField createEditableField(Field field) {
|
|
||||||
try {
|
|
||||||
GuiEditable.Field fieldConfig = field.getAnnotation(GuiEditable.Field.class);
|
|
||||||
if (fieldConfig == null) return null;
|
|
||||||
if (Modifier.isFinal(field.getModifiers())) return null;
|
|
||||||
|
|
||||||
GuiEditable.Size size = field.getAnnotation(GuiEditable.Size.class);
|
|
||||||
if (size == null) size = GuiEditable.Size.DEFAULT_SIZE;
|
|
||||||
;
|
|
||||||
|
|
||||||
field.setAccessible(true);
|
|
||||||
EditableField.Builder builder = new EditableField.Builder()
|
|
||||||
.name(fieldConfig.value())
|
|
||||||
.type(field.getType())
|
|
||||||
.getter(LOOKUP.unreflectGetter(field))
|
|
||||||
.setter(LOOKUP.unreflectSetter(field))
|
|
||||||
.constraints(buildConstraints(field))
|
|
||||||
.order(fieldConfig.order())
|
|
||||||
.size(size);
|
|
||||||
|
|
||||||
|
|
||||||
GuiEditable.Group group = field.getAnnotation(GuiEditable.Group.class);
|
|
||||||
if (group != null)
|
|
||||||
builder.group(group.value());
|
|
||||||
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"Failed to bind field: " + field, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"RawUseOfParameterized", "unchecked"})
|
|
||||||
private static FieldConstraints buildConstraints(Field field) {
|
|
||||||
List<FieldConstraint> list = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Annotation ann : field.getAnnotations()) {
|
|
||||||
ConstraintFactory factory = registry.get(ann.annotationType());
|
|
||||||
if (factory != null) {
|
|
||||||
FieldConstraint c = factory.create(field, ann);
|
|
||||||
list.add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.isEmpty()) return FieldConstraints.empty();
|
|
||||||
return new FieldConstraints(list.toArray(new FieldConstraint[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings({"RawUseOfParameterized"})
|
|
||||||
public static final class ClassMetadata {
|
|
||||||
final Class<?> type;
|
|
||||||
final EditableField[] fields; // only declared fields
|
|
||||||
final ClassMetadata parent; // superclass metadata (nullable)
|
|
||||||
|
|
||||||
ClassMetadata(Class<?> type, EditableField[] fields, ClassMetadata parent) {
|
|
||||||
this.type = type;
|
|
||||||
this.fields = fields;
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassMetadata getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EditableField[] getDeclaredFields() {
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling.constraints;
|
|
||||||
|
|
||||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public interface ConstraintFactory<A extends Annotation> {
|
|
||||||
FieldConstraint create(Field field, A annotation);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling.constraints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.FIELD)
|
|
||||||
public @interface NumericConstraint {
|
|
||||||
double min() default Double.NEGATIVE_INFINITY;
|
|
||||||
|
|
||||||
double max() default Double.POSITIVE_INFINITY;
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling.constraints;
|
|
||||||
|
|
||||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class NumericConstraintFactory implements ConstraintFactory<NumericConstraint> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FieldConstraint create(Field field, NumericConstraint ann) {
|
|
||||||
return new NumericRangeConstraint(ann.min(), ann.max());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling.constraints;
|
|
||||||
|
|
||||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
|
||||||
|
|
||||||
public final class NumericRangeConstraint implements FieldConstraint {
|
|
||||||
|
|
||||||
private final double min;
|
|
||||||
private final double max;
|
|
||||||
|
|
||||||
public NumericRangeConstraint(double min, double max) {
|
|
||||||
this.min = min;
|
|
||||||
this.max = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate(Object value) {
|
|
||||||
if (!(value instanceof Number)) {
|
|
||||||
throw new ConstraintViolationException("Expected number, got " + value);
|
|
||||||
}
|
|
||||||
|
|
||||||
double v = ((Number) value).doubleValue();
|
|
||||||
if (v < min || v > max) {
|
|
||||||
throw new ConstraintViolationException(
|
|
||||||
"Value " + v + " must be between " + min + " and " + max
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class ConstraintViolationException extends RuntimeException {
|
|
||||||
public ConstraintViolationException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package somehussar.gui.annotationHandling.field;
|
|
||||||
|
|
||||||
import somehussar.gui.annotationHandling.FieldConstraints;
|
|
||||||
import somehussar.gui.annotationHandling.GuiEditable;
|
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
|
|
||||||
public final class EditableField<T> {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final Class<T> type;
|
|
||||||
private final MethodHandle getter;
|
|
||||||
private final MethodHandle setter;
|
|
||||||
private final FieldConstraints constraints;
|
|
||||||
private final int order;
|
|
||||||
private final String group;
|
|
||||||
private final GuiEditable.Size size;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
public T read(T instance) {
|
|
||||||
try {
|
|
||||||
return (T) getter.invoke(instance);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new RuntimeException("Failed to read field " + name, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(T instance, T value) {
|
|
||||||
constraints.validate(value);
|
|
||||||
try {
|
|
||||||
setter.invoke(instance, value);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new RuntimeException("Failed to write field " + name, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldConstraints getConstraints() {
|
|
||||||
return this.constraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOrder() {
|
|
||||||
return this.order;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditableField(Builder<T> b) {
|
|
||||||
this.name = b.name;
|
|
||||||
this.type = b.type;
|
|
||||||
this.getter = b.getter;
|
|
||||||
this.setter = b.setter;
|
|
||||||
this.constraints = b.constraints;
|
|
||||||
this.order = b.order;
|
|
||||||
this.group = b.group;
|
|
||||||
this.size = b.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder<T> {
|
|
||||||
private String name;
|
|
||||||
private Class<T> type;
|
|
||||||
private MethodHandle getter;
|
|
||||||
private MethodHandle setter;
|
|
||||||
private FieldConstraints constraints;
|
|
||||||
private int order;
|
|
||||||
private String group = null;
|
|
||||||
private GuiEditable.Size size;
|
|
||||||
|
|
||||||
public Builder<T> name(String v) {
|
|
||||||
this.name = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> type(Class<T> v) {
|
|
||||||
this.type = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> getter(MethodHandle v) {
|
|
||||||
this.getter = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> setter(MethodHandle v) {
|
|
||||||
this.setter = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> constraints(FieldConstraints v) {
|
|
||||||
this.constraints = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> order(int order) {
|
|
||||||
this.order = order;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> group(String value) {
|
|
||||||
this.group = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder<T> size(GuiEditable.Size size) {
|
|
||||||
this.size = size;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EditableField<T> build() {
|
|
||||||
return new EditableField<>(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package somehussar.gui.guides;
|
||||||
|
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.achievement.GuiAchievement;
|
||||||
|
import net.minecraft.stats.AchievementList;
|
||||||
|
|
||||||
|
// TODO: THIS IS JUST THE CLIENT SIDE CONTROLLER
|
||||||
|
// NEED SERVER SIDE
|
||||||
|
public class GuideController {
|
||||||
|
private static boolean glint = true;
|
||||||
|
private static boolean isGuideLoaded = true;
|
||||||
|
|
||||||
|
public static boolean isGuideLoaded() {
|
||||||
|
return isGuideLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setGuideLoaded(boolean isGuideLoaded) {
|
||||||
|
GuideController.isGuideLoaded = isGuideLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean glint() {
|
||||||
|
return glint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleWorldJoin() {
|
||||||
|
if (glint()){
|
||||||
|
GuiAchievement achievementGui = Minecraft.getMinecraft().guiAchievement;
|
||||||
|
achievementGui.func_146255_b(AchievementList.openInventory);
|
||||||
|
achievementGui.field_146265_j = "Check out guides in your inventory!";
|
||||||
|
achievementGui.field_146268_i = "CNPC Guides!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disableGlint() {
|
||||||
|
glint = false;
|
||||||
|
final long time = Minecraft.getSystemTime();
|
||||||
|
GuiAchievement achievementGui = Minecraft.getMinecraft().guiAchievement;
|
||||||
|
achievementGui.field_146263_l = (achievementGui.field_146263_l <= time - 3000 && achievementGui.field_146262_n ? time : Minecraft.getSystemTime() - (long) (3000.0D * 0.5D));
|
||||||
|
achievementGui.field_146262_n = false;
|
||||||
|
achievementGui.field_146265_j = "Guides explored!";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetGlint() {
|
||||||
|
glint = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package tconstruct.client.tabs;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.gui.achievement.GuiAchievement;
|
||||||
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||||
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderItem;
|
||||||
|
import net.minecraft.stats.Achievement;
|
||||||
|
import net.minecraft.stats.AchievementList;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL12;
|
||||||
|
import somehussar.gui.guides.GuideController;
|
||||||
|
|
||||||
|
import static tconstruct.client.tabs.TabRegistry.getPotionOffset;
|
||||||
|
|
||||||
|
public class InventoryTabGuides extends AbstractTab {
|
||||||
|
|
||||||
|
// TODO: Replace with a proper texture.
|
||||||
|
private static final ResourceLocation HELP_TEXTURE = new ResourceLocation("customnpcs", "textures/marks/question.png");
|
||||||
|
public InventoryTabGuides() {
|
||||||
|
super(0, 0, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabClicked() {
|
||||||
|
int xSize = 176;
|
||||||
|
int ySize = 166;
|
||||||
|
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||||
|
|
||||||
|
GuideController.disableGlint();
|
||||||
|
if (!(gui instanceof GuiInventory))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int guiLeft = (gui.width - xSize) / 2;
|
||||||
|
int guiTop = (gui.height - ySize) / 2;
|
||||||
|
guiLeft += getPotionOffset();
|
||||||
|
TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabGuides.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldAddToList() {
|
||||||
|
return GuideController.isGuideLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||||
|
if (this.visible) {
|
||||||
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||||
|
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
this.zLevel = 100.0F;
|
||||||
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
int yTexPos = this.enabled ? 3 : 32;
|
||||||
|
int ySize = this.enabled ? 25 : 32;
|
||||||
|
int xOffset = this.id == 2 ? 0 : 1;
|
||||||
|
int yPos = this.yPosition + (this.enabled ? 3 : 0);
|
||||||
|
mc.renderEngine.bindTexture(super.texture);
|
||||||
|
this.drawTexturedModalRect(this.xPosition, yPos, xOffset * 28,
|
||||||
|
yTexPos, 28, ySize);
|
||||||
|
|
||||||
|
this.zLevel = 100.0f;
|
||||||
|
mc.renderEngine.bindTexture(HELP_TEXTURE);
|
||||||
|
|
||||||
|
RenderHelper.enableGUIStandardItemLighting();
|
||||||
|
this.zLevel = 100.0F;
|
||||||
|
this.itemRenderer.zLevel = 100.0F;
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||||
|
drawTextured(this.xPosition + 6, this.yPosition + 8, 0, 0, 16, 16, 16, 16);
|
||||||
|
|
||||||
|
if (GuideController.glint()) {
|
||||||
|
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
mc.renderEngine.bindTexture(RenderItem.RES_ITEM_GLINT);
|
||||||
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
|
||||||
|
this.renderGlint(this.xPosition, yPos, 28, ySize);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||||
|
}
|
||||||
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||||
|
this.zLevel = 0.0F;
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderGlint(int x, int y, int width, int height) {
|
||||||
|
OpenGlHelper.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE, 0, 0);
|
||||||
|
|
||||||
|
final float GLINT_TEX_SCALE = 0.00390625F; // 1 / 256
|
||||||
|
long now = Minecraft.getSystemTime();
|
||||||
|
double z = this.zLevel;
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
|
||||||
|
for (int pass = 0; pass < 2; ++pass) {
|
||||||
|
long cycleLengthMs = 3000 + pass * 1873;
|
||||||
|
float scrollU = (now % cycleLengthMs) / (float) cycleLengthMs * 256.0F;
|
||||||
|
float skew = (pass == 1) ? -1.0F : 4.0F;
|
||||||
|
|
||||||
|
float uLeft = scrollU * GLINT_TEX_SCALE;
|
||||||
|
float uRight = (scrollU + width) * GLINT_TEX_SCALE;
|
||||||
|
float uBottomSkew = (scrollU + height * skew) * GLINT_TEX_SCALE;
|
||||||
|
float uBottomRightSkew = (scrollU + width + height * skew) * GLINT_TEX_SCALE;
|
||||||
|
float vTop = 0.0F;
|
||||||
|
float vBottom = height * GLINT_TEX_SCALE;
|
||||||
|
|
||||||
|
tessellator.addVertexWithUV(x, y + height, z, uBottomSkew, vBottom);
|
||||||
|
tessellator.addVertexWithUV(x + width, y + height, z, uBottomRightSkew, vBottom);
|
||||||
|
tessellator.addVertexWithUV(x + width, y, z, uRight, vTop);
|
||||||
|
tessellator.addVertexWithUV(x, y, z, uLeft, vTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTextured(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
|
||||||
|
{
|
||||||
|
float f4 = 1.0F / textureWidth;
|
||||||
|
float f5 = 1.0F / textureHeight;
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
tessellator.addVertexWithUV((double)x, (double)(y + height), this.zLevel, (double)(u * f4), (double)((v + (float)height) * f5));
|
||||||
|
tessellator.addVertexWithUV((double)(x + width), (double)(y + height), this.zLevel, (double)((u + (float)width) * f4), (double)((v + (float)height) * f5));
|
||||||
|
tessellator.addVertexWithUV((double)(x + width), (double)y, this.zLevel, (double)((u + (float)width) * f4), (double)(v * f5));
|
||||||
|
tessellator.addVertexWithUV((double)x, (double)y, this.zLevel, (double)(u * f4), (double)(v * f5));
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,3 +26,11 @@ public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker
|
|||||||
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
||||||
#GuiScreen
|
#GuiScreen
|
||||||
public net.minecraft.client.gui.GuiScreen field_146290_a # selectedButton
|
public net.minecraft.client.gui.GuiScreen field_146290_a # selectedButton
|
||||||
|
# ItemRenderer
|
||||||
|
public net.minecraft.client.renderer.entity.RenderItem field_110798_h # RES_ITEM_GLINT
|
||||||
|
|
||||||
|
public net.minecraft.client.gui.achievement.GuiAchievement field_146268_i # popupTitle
|
||||||
|
public net.minecraft.client.gui.achievement.GuiAchievement field_146265_j # description
|
||||||
|
public net.minecraft.client.gui.achievement.GuiAchievement field_146263_l # startTime
|
||||||
|
public net.minecraft.client.gui.achievement.GuiAchievement field_146266_k # achievementType
|
||||||
|
public net.minecraft.client.gui.achievement.GuiAchievement field_146262_n # showOnlyDescription / persistUntilCompletion. It does the job of both of these ;o
|
||||||
Reference in new issue
Block a user