WIP Modifier settings gui overhaul
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
@@ -27,14 +19,10 @@ import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
||||
import nl.requios.effortlessbuilding.gui.buildmode.RadialMenu;
|
||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifierSettingsGui;
|
||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreen;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
import nl.requios.effortlessbuilding.network.*;
|
||||
import nl.requios.effortlessbuilding.render.BuildRenderTypes;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@EventBusSubscriber(Dist.CLIENT)
|
||||
public class ClientEvents {
|
||||
|
||||
@@ -200,7 +188,7 @@ public class ClientEvents {
|
||||
if (ReachHelper.getMaxReach(player) == 0) {
|
||||
EffortlessBuilding.log(player, "Build modifiers are disabled until your reach has increased. Increase your reach with craftable reach upgrades.");
|
||||
} else {
|
||||
mc.setScreen(new ModifierSettingsGui());
|
||||
mc.setScreen(new ModifiersScreen());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
public class Array extends BaseModifier {
|
||||
|
||||
public BlockPos offset = BlockPos.ZERO;
|
||||
public Vec3i offset = BlockPos.ZERO;
|
||||
public int count = 5;
|
||||
|
||||
@Override
|
||||
@@ -54,7 +54,7 @@ public class Array extends BaseModifier {
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
var compound = super.serializeNBT();
|
||||
compound.getCompound("offset").merge(NbtUtils.writeBlockPos(offset));
|
||||
compound.putIntArray("offset", new int[]{offset.getX(), offset.getY(), offset.getZ()});
|
||||
compound.putInt("count", count);
|
||||
return compound;
|
||||
}
|
||||
@@ -62,7 +62,8 @@ public class Array extends BaseModifier {
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag compound) {
|
||||
super.deserializeNBT(compound);
|
||||
offset = NbtUtils.readBlockPos(compound.getCompound("offset"));
|
||||
int[] offsetArray = compound.getIntArray("offset");
|
||||
offset = new Vec3i(offsetArray[0], offsetArray[1], offsetArray[2]);
|
||||
count = compound.getInt("count");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.Label;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiCheckBoxFixed;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiNumberField;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
import nl.requios.effortlessbuilding.utilities.MathHelper;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ArrayEntry extends BaseModifierEntry<Array> {
|
||||
|
||||
protected Vector<ScrollInput> offsetInputs = new Vector<>(3);
|
||||
protected Vector<Label> offsetLabels = new Vector<>(3);
|
||||
protected ScrollInput countInput;
|
||||
protected Label reachLabel;
|
||||
|
||||
public ArrayEntry(BaseModifier array) {
|
||||
super((Array) array);
|
||||
|
||||
offsetInputs.clear();
|
||||
offsetLabels.clear();
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
var label = new Label(0, 0, Components.immutableEmpty()).withShadow();
|
||||
|
||||
final int index = i;
|
||||
var scrollInput = new ScrollInput(0, 0, 20, 20)
|
||||
.withRange(0, 100)
|
||||
.writingTo(label)
|
||||
.titled(Component.literal("Offset"))
|
||||
.calling(value -> {
|
||||
modifier.offset = MathHelper.with(modifier.offset, index, value);
|
||||
// label.x = x + 65 + 20 * index - font.width(label.text) / 2;
|
||||
onValueChanged();
|
||||
});
|
||||
scrollInput.setState(MathHelper.get(modifier.offset, index));
|
||||
scrollInput.onChanged();
|
||||
|
||||
offsetInputs.add(scrollInput);
|
||||
offsetLabels.add(label);
|
||||
}
|
||||
|
||||
listeners.addAll(offsetInputs);
|
||||
listeners.addAll(offsetLabels);
|
||||
|
||||
countInput = new ScrollInput(0, 0, 20, 20)
|
||||
.withRange(1, 100)
|
||||
.titled(Component.literal("Count"))
|
||||
.calling(value -> {
|
||||
modifier.count = value;
|
||||
onValueChanged();
|
||||
});
|
||||
|
||||
countInput.setState(modifier.count);
|
||||
countInput.onChanged();
|
||||
|
||||
listeners.add(countInput);
|
||||
|
||||
reachLabel = new Label(100, 100, Components.immutableEmpty()).withShadow();
|
||||
|
||||
onValueChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
offsetInputs.forEach(ScrollInput::tick);
|
||||
offsetLabels.forEach(Label::tick);
|
||||
countInput.tick();
|
||||
|
||||
int currentReach = Math.max(-1, getArrayReach());
|
||||
int maxReach = ReachHelper.getMaxReach(Minecraft.getInstance().player);
|
||||
ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED;
|
||||
var reachText = "Reach: " + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach;
|
||||
reachLabel.text = Component.literal(reachText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged() {
|
||||
super.onValueChanged();
|
||||
|
||||
}
|
||||
|
||||
private int getArrayReach() {
|
||||
try {
|
||||
//find largest offset
|
||||
double x = Math.abs(modifier.offset.getX());
|
||||
double y = Math.abs(modifier.offset.getY());
|
||||
double z = Math.abs(modifier.offset.getZ());
|
||||
double largestOffset = Math.max(Math.max(x, y), z);
|
||||
return (int) (largestOffset * modifier.count);
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCurrentReachValid(int currentReach, int maxReach) {
|
||||
return currentReach <= maxReach && currentReach > -1;
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiCheckBoxFixed;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiNumberField;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ArrayPanel extends BaseModifierPanel {
|
||||
|
||||
protected List<GuiNumberField> arrayNumberFieldList = new ArrayList<>();
|
||||
|
||||
private GuiCheckBoxFixed buttonArrayEnabled;
|
||||
private GuiNumberField textArrayOffsetX, textArrayOffsetY, textArrayOffsetZ, textArrayCount;
|
||||
|
||||
public ArrayPanel(GuiScrollPane scrollPane) {
|
||||
super(scrollPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(List<Widget> renderables) {
|
||||
super.init(renderables);
|
||||
|
||||
int y = top;
|
||||
buttonArrayEnabled = new GuiCheckBoxFixed(left - 15 + 8, y, "", false) {
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
super.onClick(mouseX, mouseY);
|
||||
setCollapsed(!buttonArrayEnabled.isChecked());
|
||||
}
|
||||
};
|
||||
renderables.add(buttonArrayEnabled);
|
||||
|
||||
y = top + 20;
|
||||
textArrayOffsetX = new GuiNumberField(font, renderables, left + 70, y, 50, 18);
|
||||
textArrayOffsetX.setNumber(0);
|
||||
textArrayOffsetX.setTooltip(Component.literal("How much each copy is shifted."));
|
||||
arrayNumberFieldList.add(textArrayOffsetX);
|
||||
|
||||
textArrayOffsetY = new GuiNumberField(font, renderables, left + 140, y, 50, 18);
|
||||
textArrayOffsetY.setNumber(0);
|
||||
textArrayOffsetY.setTooltip(Component.literal("How much each copy is shifted."));
|
||||
arrayNumberFieldList.add(textArrayOffsetY);
|
||||
|
||||
textArrayOffsetZ = new GuiNumberField(font, renderables, left + 210, y, 50, 18);
|
||||
textArrayOffsetZ.setNumber(0);
|
||||
textArrayOffsetZ.setTooltip(Component.literal("How much each copy is shifted."));
|
||||
arrayNumberFieldList.add(textArrayOffsetZ);
|
||||
|
||||
y = top + 50;
|
||||
textArrayCount = new GuiNumberField(font, renderables, left + 55, y, 50, 18);
|
||||
textArrayCount.setNumber(5);
|
||||
textArrayCount.setTooltip(Component.literal("How many copies should be made."));
|
||||
arrayNumberFieldList.add(textArrayCount);
|
||||
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
|
||||
if (modifierSettings != null) {
|
||||
Array.ArraySettings a = modifierSettings.getArraySettings();
|
||||
buttonArrayEnabled.setIsChecked(a.enabled);
|
||||
textArrayOffsetX.setNumber(a.offset.getX());
|
||||
textArrayOffsetY.setNumber(a.offset.getY());
|
||||
textArrayOffsetZ.setNumber(a.offset.getZ());
|
||||
textArrayCount.setNumber(a.count);
|
||||
}
|
||||
|
||||
setCollapsed(!buttonArrayEnabled.isChecked());
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
arrayNumberFieldList.forEach(GuiNumberField::update);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(PoseStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
boolean isSelected, float partialTicks) {
|
||||
int yy = y;
|
||||
int offset = 8;
|
||||
|
||||
buttonArrayEnabled.render(ms, mouseX, mouseY, partialTicks);
|
||||
if (buttonArrayEnabled.isChecked()) {
|
||||
buttonArrayEnabled.y = yy;
|
||||
font.draw(ms, "Array enabled", left + offset, yy + 2, 0xFFFFFF);
|
||||
|
||||
yy = y + 20;
|
||||
font.draw(ms, "Offset", left + offset, yy + 5, 0xFFFFFF);
|
||||
font.draw(ms, "X", left + 50 + offset, yy + 5, 0xFFFFFF);
|
||||
textArrayOffsetX.y = yy;
|
||||
font.draw(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
|
||||
textArrayOffsetY.y = yy;
|
||||
font.draw(ms, "Z", left + 190 + offset, yy + 5, 0xFFFFFF);
|
||||
textArrayOffsetZ.y = yy;
|
||||
|
||||
yy = y + 50;
|
||||
font.draw(ms, "Count", left + offset, yy + 5, 0xFFFFFF);
|
||||
textArrayCount.y = yy;
|
||||
|
||||
int currentReach = Math.max(-1, getArrayReach());
|
||||
int maxReach = ReachHelper.getMaxReach(mc.player);
|
||||
ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED;
|
||||
String reachText = "Reach: " + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach;
|
||||
font.draw(ms, reachText, left + 176 + offset, yy + 5, 0xFFFFFF);
|
||||
|
||||
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
|
||||
} else {
|
||||
buttonArrayEnabled.y = yy;
|
||||
font.draw(ms, "Array disabled", left + offset, yy + 2, 0x999999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void drawTooltip(PoseStack ms, Screen guiScreen, int mouseX, int mouseY) {
|
||||
//Draw tooltips last
|
||||
if (buttonArrayEnabled.isChecked()) {
|
||||
arrayNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char typedChar, int keyCode) {
|
||||
super.charTyped(typedChar, keyCode);
|
||||
for (GuiNumberField numberField : arrayNumberFieldList) {
|
||||
numberField.charTyped(typedChar, keyCode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||
arrayNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||
|
||||
boolean insideArrayEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||
|
||||
if (insideArrayEnabledLabel) {
|
||||
buttonArrayEnabled.playDownSound(this.mc.getSoundManager());
|
||||
buttonArrayEnabled.onClick(mouseX, mouseY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Array.ArraySettings getArraySettings() {
|
||||
boolean arrayEnabled = buttonArrayEnabled.isChecked();
|
||||
BlockPos arrayOffset = new BlockPos(0, 0, 0);
|
||||
try {
|
||||
arrayOffset = new BlockPos(textArrayOffsetX.getNumber(), textArrayOffsetY.getNumber(), textArrayOffsetZ.getNumber());
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Array offset not a valid number.");
|
||||
}
|
||||
|
||||
int arrayCount = 5;
|
||||
try {
|
||||
arrayCount = (int) textArrayCount.getNumber();
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Array count not a valid number.");
|
||||
}
|
||||
|
||||
return new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpandedHeight() {
|
||||
return 80;
|
||||
}
|
||||
|
||||
private int getArrayReach() {
|
||||
try {
|
||||
//find largest offset
|
||||
double x = Math.abs(textArrayOffsetX.getNumber());
|
||||
double y = Math.abs(textArrayOffsetY.getNumber());
|
||||
double z = Math.abs(textArrayOffsetZ.getNumber());
|
||||
double largestOffset = Math.max(Math.max(x, y), z);
|
||||
return (int) (largestOffset * textArrayCount.getNumber());
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCurrentReachValid(int currentReach, int maxReach) {
|
||||
return currentReach <= maxReach && currentReach > -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllIcons;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.BoxWidget;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiCollapsibleScrollEntry;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
|
||||
public abstract class BaseModifierEntry<T extends BaseModifier> extends ModifiersScreenList.Entry {
|
||||
|
||||
public T modifier;
|
||||
BoxWidget enableButton;
|
||||
|
||||
public BaseModifierEntry(T modifier) {
|
||||
super();
|
||||
|
||||
this.modifier = modifier;
|
||||
|
||||
enableButton = new BoxWidget()
|
||||
.showingElement(AllIcons.I_CONFIRM.asStencil())
|
||||
.withCallback(() -> {
|
||||
modifier.enabled = !modifier.enabled;
|
||||
onValueChanged();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
enableButton.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||
|
||||
enableButton.x = x + width - 80;
|
||||
enableButton.y = y + 10;
|
||||
enableButton.setWidth(35);
|
||||
enableButton.setHeight(height - 20);
|
||||
enableButton.render(ms, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
public void onValueChanged() {
|
||||
enableButton.showingElement(modifier.enabled ? AllIcons.I_CONFIRM.asStencil() : AllIcons.I_DISABLE.asStencil());
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiCollapsibleScrollEntry;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
|
||||
public abstract class BaseModifierPanel extends GuiCollapsibleScrollEntry {
|
||||
|
||||
public BaseModifierPanel(GuiScrollPane scrollPane) {
|
||||
super(scrollPane);
|
||||
}
|
||||
|
||||
public abstract void setModifier(BaseModifier modifier);
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||
import nl.requios.effortlessbuilding.gui.elements.*;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class MirrorEntry extends BaseModifierEntry<Mirror> {
|
||||
|
||||
public MirrorEntry(BaseModifier modifier) {
|
||||
super((Mirror) modifier);
|
||||
}
|
||||
|
||||
|
||||
// protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
||||
//
|
||||
// protected List<Button> mirrorButtonList = new ArrayList<>();
|
||||
// protected List<GuiIconButton> mirrorIconButtonList = new ArrayList<>();
|
||||
// protected List<GuiNumberField> mirrorNumberFieldList = new ArrayList<>();
|
||||
//
|
||||
// private GuiNumberField textMirrorPosX, textMirrorPosY, textMirrorPosZ, textMirrorRadius;
|
||||
// private GuiCheckBoxFixed buttonMirrorEnabled, buttonMirrorX, buttonMirrorY, buttonMirrorZ;
|
||||
// private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
||||
// private boolean drawPlanes, drawLines, toggleOdd;
|
||||
//
|
||||
// public MirrorEntry(GuiScrollPane scrollPane) {
|
||||
// super(scrollPane);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void init(List<Widget> renderables) {
|
||||
// super.init(renderables);
|
||||
//
|
||||
// int y = top - 2;
|
||||
// buttonMirrorEnabled = new GuiCheckBoxFixed(left - 15 + 8, y, "", false) {
|
||||
// @Override
|
||||
// public void onClick(double mouseX, double mouseY) {
|
||||
// super.onClick(mouseX, mouseY);
|
||||
// setCollapsed(!buttonMirrorEnabled.isChecked());
|
||||
// }
|
||||
// };
|
||||
// renderables.add(buttonMirrorEnabled);
|
||||
//
|
||||
// y = top + 18;
|
||||
// textMirrorPosX = new GuiNumberField(font, renderables, left + 58, y, 62, 18);
|
||||
// textMirrorPosX.setNumber(0);
|
||||
// textMirrorPosX.setTooltip(
|
||||
// Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// mirrorNumberFieldList.add(textMirrorPosX);
|
||||
//
|
||||
// textMirrorPosY = new GuiNumberField(font, renderables, left + 138, y, 62, 18);
|
||||
// textMirrorPosY.setNumber(64);
|
||||
// textMirrorPosY.setTooltip(Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// mirrorNumberFieldList.add(textMirrorPosY);
|
||||
//
|
||||
// textMirrorPosZ = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
// textMirrorPosZ.setNumber(0);
|
||||
// textMirrorPosZ.setTooltip(Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// mirrorNumberFieldList.add(textMirrorPosZ);
|
||||
//
|
||||
// y = top + 50;
|
||||
// buttonMirrorX = new GuiCheckBoxFixed(left + 60, y, " X", true);
|
||||
// mirrorButtonList.add(buttonMirrorX);
|
||||
//
|
||||
// buttonMirrorY = new GuiCheckBoxFixed(left + 100, y, " Y", false);
|
||||
// mirrorButtonList.add(buttonMirrorY);
|
||||
//
|
||||
// buttonMirrorZ = new GuiCheckBoxFixed(left + 140, y, " Z", false);
|
||||
// mirrorButtonList.add(buttonMirrorZ);
|
||||
//
|
||||
// y = top + 47;
|
||||
// textMirrorRadius = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
// textMirrorRadius.setNumber(50);
|
||||
// //TODO change to diameter (remove /2)
|
||||
// textMirrorRadius.setTooltip(Arrays.asList(Component.literal("How far the mirror reaches in any direction."),
|
||||
// Component.literal("Max: ").withStyle(ChatFormatting.GRAY).append(Component.literal(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).withStyle(ChatFormatting.GOLD)),
|
||||
// Component.literal("Upgradeable in survival with reach upgrades.").withStyle(ChatFormatting.GRAY)));
|
||||
// mirrorNumberFieldList.add(textMirrorRadius);
|
||||
//
|
||||
// y = top + 72;
|
||||
// buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
|
||||
// Vec3 pos = new Vec3(Math.floor(mc.player.getX()) + 0.5, Math.floor(mc.player.getY()) + 0.5, Math.floor(mc.player.getZ()) + 0.5);
|
||||
// textMirrorPosX.setNumber(pos.x);
|
||||
// textMirrorPosY.setNumber(pos.y);
|
||||
// textMirrorPosZ.setNumber(pos.z);
|
||||
// });
|
||||
// buttonCurrentPosition.setTooltip(Component.literal("Set mirror position to current player position"));
|
||||
// mirrorIconButtonList.add(buttonCurrentPosition);
|
||||
//
|
||||
// buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
|
||||
// toggleOdd = !toggleOdd;
|
||||
// buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
// if (toggleOdd) {
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
// textMirrorPosX.setNumber(textMirrorPosX.getNumber() + 0.5);
|
||||
// textMirrorPosY.setNumber(textMirrorPosY.getNumber() + 0.5);
|
||||
// textMirrorPosZ.setNumber(textMirrorPosZ.getNumber() + 0.5);
|
||||
// } else {
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// textMirrorPosX.setNumber(Math.floor(textMirrorPosX.getNumber()));
|
||||
// textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
|
||||
// textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
|
||||
// }
|
||||
// });
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// mirrorIconButtonList.add(buttonToggleOdd);
|
||||
//
|
||||
// buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
|
||||
// drawLines = !drawLines;
|
||||
// buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
// buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
// });
|
||||
// buttonDrawLines.setTooltip(Component.literal("Show lines"));
|
||||
// mirrorIconButtonList.add(buttonDrawLines);
|
||||
//
|
||||
// buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
|
||||
// drawPlanes = !drawPlanes;
|
||||
// buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
// buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
// });
|
||||
// buttonDrawPlanes.setTooltip(Component.literal("Show area"));
|
||||
// mirrorIconButtonList.add(buttonDrawPlanes);
|
||||
//
|
||||
// ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
|
||||
// if (modifierSettings != null) {
|
||||
// Mirror.MirrorSettings m = modifierSettings.getMirrorSettings();
|
||||
// buttonMirrorEnabled.setIsChecked(m.enabled);
|
||||
// textMirrorPosX.setNumber(m.position.x);
|
||||
// textMirrorPosY.setNumber(m.position.y);
|
||||
// textMirrorPosZ.setNumber(m.position.z);
|
||||
// buttonMirrorX.setIsChecked(m.mirrorX);
|
||||
// buttonMirrorY.setIsChecked(m.mirrorY);
|
||||
// buttonMirrorZ.setIsChecked(m.mirrorZ);
|
||||
// textMirrorRadius.setNumber(m.radius);
|
||||
// drawLines = m.drawLines;
|
||||
// drawPlanes = m.drawPlanes;
|
||||
// buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
// buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
// buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
// buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
// if (textMirrorPosX.getNumber() == Math.floor(textMirrorPosX.getNumber())) {
|
||||
// toggleOdd = false;
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// } else {
|
||||
// toggleOdd = true;
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
// }
|
||||
// buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
// }
|
||||
//
|
||||
// renderables.addAll(mirrorButtonList);
|
||||
// renderables.addAll(mirrorIconButtonList);
|
||||
//
|
||||
// setCollapsed(!buttonMirrorEnabled.isChecked());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void updateScreen() {
|
||||
// super.updateScreen();
|
||||
// mirrorNumberFieldList.forEach(GuiNumberField::update);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void drawEntry(PoseStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
// boolean isSelected, float partialTicks) {
|
||||
//
|
||||
// int yy = y;
|
||||
// int offset = 8;
|
||||
//
|
||||
// buttonMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
|
||||
// if (buttonMirrorEnabled.isChecked()) {
|
||||
// buttonMirrorEnabled.y = yy;
|
||||
// font.draw(ms, "Mirror enabled", left + offset, yy + 2, 0xFFFFFF);
|
||||
//
|
||||
// yy = y + 18;
|
||||
// font.draw(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
|
||||
// font.draw(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
|
||||
// textMirrorPosX.y = yy;
|
||||
// font.draw(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
|
||||
// textMirrorPosY.y = yy;
|
||||
// font.draw(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
|
||||
// textMirrorPosZ.y = yy;
|
||||
//
|
||||
// yy = y + 50;
|
||||
// font.draw(ms, "Direction", left + offset, yy + 2, 0xFFFFFF);
|
||||
// buttonMirrorX.y = yy;
|
||||
// buttonMirrorY.y = yy;
|
||||
// buttonMirrorZ.y = yy;
|
||||
// font.draw(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
|
||||
// textMirrorRadius.y = yy - 3;
|
||||
//
|
||||
// yy = y + 72;
|
||||
// buttonCurrentPosition.y = yy;
|
||||
// buttonToggleOdd.y = yy;
|
||||
// buttonDrawLines.y = yy;
|
||||
// buttonDrawPlanes.y = yy;
|
||||
//
|
||||
// mirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
// mirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
// mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
|
||||
// } else {
|
||||
// buttonMirrorEnabled.y = yy;
|
||||
// font.draw(ms, "Mirror disabled", left + offset, yy + 2, 0x999999);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void drawTooltip(PoseStack ms, Screen guiScreen, int mouseX, int mouseY) {
|
||||
// //Draw tooltips last
|
||||
// if (buttonMirrorEnabled.isChecked()) {
|
||||
// mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
// mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean charTyped(char typedChar, int modifiers) {
|
||||
// super.charTyped(typedChar, modifiers);
|
||||
// for (GuiNumberField numberField : mirrorNumberFieldList) {
|
||||
// numberField.charTyped(typedChar, modifiers);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||
// mirrorNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||
//
|
||||
// boolean insideMirrorEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||
//
|
||||
// if (insideMirrorEnabledLabel) {
|
||||
// buttonMirrorEnabled.playDownSound(this.mc.getSoundManager());
|
||||
// buttonMirrorEnabled.onClick(mouseX, mouseY);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public Mirror.MirrorSettings getMirrorSettings() {
|
||||
// boolean mirrorEnabled = buttonMirrorEnabled.isChecked();
|
||||
//
|
||||
// Vec3 mirrorPos = new Vec3(0, 64, 0);
|
||||
// try {
|
||||
// mirrorPos = new Vec3(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
|
||||
// } catch (NumberFormatException | NullPointerException ex) {
|
||||
// EffortlessBuilding.log(mc.player, "Mirror position not a valid number.");
|
||||
// }
|
||||
//
|
||||
// boolean mirrorX = buttonMirrorX.isChecked();
|
||||
// boolean mirrorY = buttonMirrorY.isChecked();
|
||||
// boolean mirrorZ = buttonMirrorZ.isChecked();
|
||||
//
|
||||
// int mirrorRadius = 50;
|
||||
// try {
|
||||
// mirrorRadius = (int) textMirrorRadius.getNumber();
|
||||
// } catch (NumberFormatException | NullPointerException ex) {
|
||||
// EffortlessBuilding.log(mc.player, "Mirror radius not a valid number.");
|
||||
// }
|
||||
//
|
||||
// return new Mirror.MirrorSettings(mirrorEnabled, mirrorPos, mirrorX, mirrorY, mirrorZ, mirrorRadius, drawLines, drawPlanes);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected String getName() {
|
||||
// return "Mirror";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getExpandedHeight() {
|
||||
// return 100;
|
||||
// }
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||
import nl.requios.effortlessbuilding.gui.elements.*;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class MirrorPanel extends BaseModifierPanel {
|
||||
|
||||
protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
||||
|
||||
protected List<Button> mirrorButtonList = new ArrayList<>();
|
||||
protected List<GuiIconButton> mirrorIconButtonList = new ArrayList<>();
|
||||
protected List<GuiNumberField> mirrorNumberFieldList = new ArrayList<>();
|
||||
|
||||
private GuiNumberField textMirrorPosX, textMirrorPosY, textMirrorPosZ, textMirrorRadius;
|
||||
private GuiCheckBoxFixed buttonMirrorEnabled, buttonMirrorX, buttonMirrorY, buttonMirrorZ;
|
||||
private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
||||
private boolean drawPlanes, drawLines, toggleOdd;
|
||||
|
||||
public MirrorPanel(GuiScrollPane scrollPane) {
|
||||
super(scrollPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(List<Widget> renderables) {
|
||||
super.init(renderables);
|
||||
|
||||
int y = top - 2;
|
||||
buttonMirrorEnabled = new GuiCheckBoxFixed(left - 15 + 8, y, "", false) {
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
super.onClick(mouseX, mouseY);
|
||||
setCollapsed(!buttonMirrorEnabled.isChecked());
|
||||
}
|
||||
};
|
||||
renderables.add(buttonMirrorEnabled);
|
||||
|
||||
y = top + 18;
|
||||
textMirrorPosX = new GuiNumberField(font, renderables, left + 58, y, 62, 18);
|
||||
textMirrorPosX.setNumber(0);
|
||||
textMirrorPosX.setTooltip(
|
||||
Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
mirrorNumberFieldList.add(textMirrorPosX);
|
||||
|
||||
textMirrorPosY = new GuiNumberField(font, renderables, left + 138, y, 62, 18);
|
||||
textMirrorPosY.setNumber(64);
|
||||
textMirrorPosY.setTooltip(Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
mirrorNumberFieldList.add(textMirrorPosY);
|
||||
|
||||
textMirrorPosZ = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
textMirrorPosZ.setNumber(0);
|
||||
textMirrorPosZ.setTooltip(Arrays.asList(Component.literal("The position of the mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
mirrorNumberFieldList.add(textMirrorPosZ);
|
||||
|
||||
y = top + 50;
|
||||
buttonMirrorX = new GuiCheckBoxFixed(left + 60, y, " X", true);
|
||||
mirrorButtonList.add(buttonMirrorX);
|
||||
|
||||
buttonMirrorY = new GuiCheckBoxFixed(left + 100, y, " Y", false);
|
||||
mirrorButtonList.add(buttonMirrorY);
|
||||
|
||||
buttonMirrorZ = new GuiCheckBoxFixed(left + 140, y, " Z", false);
|
||||
mirrorButtonList.add(buttonMirrorZ);
|
||||
|
||||
y = top + 47;
|
||||
textMirrorRadius = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
textMirrorRadius.setNumber(50);
|
||||
//TODO change to diameter (remove /2)
|
||||
textMirrorRadius.setTooltip(Arrays.asList(Component.literal("How far the mirror reaches in any direction."),
|
||||
Component.literal("Max: ").withStyle(ChatFormatting.GRAY).append(Component.literal(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).withStyle(ChatFormatting.GOLD)),
|
||||
Component.literal("Upgradeable in survival with reach upgrades.").withStyle(ChatFormatting.GRAY)));
|
||||
mirrorNumberFieldList.add(textMirrorRadius);
|
||||
|
||||
y = top + 72;
|
||||
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
|
||||
Vec3 pos = new Vec3(Math.floor(mc.player.getX()) + 0.5, Math.floor(mc.player.getY()) + 0.5, Math.floor(mc.player.getZ()) + 0.5);
|
||||
textMirrorPosX.setNumber(pos.x);
|
||||
textMirrorPosY.setNumber(pos.y);
|
||||
textMirrorPosZ.setNumber(pos.z);
|
||||
});
|
||||
buttonCurrentPosition.setTooltip(Component.literal("Set mirror position to current player position"));
|
||||
mirrorIconButtonList.add(buttonCurrentPosition);
|
||||
|
||||
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
|
||||
toggleOdd = !toggleOdd;
|
||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
if (toggleOdd) {
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
textMirrorPosX.setNumber(textMirrorPosX.getNumber() + 0.5);
|
||||
textMirrorPosY.setNumber(textMirrorPosY.getNumber() + 0.5);
|
||||
textMirrorPosZ.setNumber(textMirrorPosZ.getNumber() + 0.5);
|
||||
} else {
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
textMirrorPosX.setNumber(Math.floor(textMirrorPosX.getNumber()));
|
||||
textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
|
||||
textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
|
||||
}
|
||||
});
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
mirrorIconButtonList.add(buttonToggleOdd);
|
||||
|
||||
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
|
||||
drawLines = !drawLines;
|
||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
});
|
||||
buttonDrawLines.setTooltip(Component.literal("Show lines"));
|
||||
mirrorIconButtonList.add(buttonDrawLines);
|
||||
|
||||
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
|
||||
drawPlanes = !drawPlanes;
|
||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
});
|
||||
buttonDrawPlanes.setTooltip(Component.literal("Show area"));
|
||||
mirrorIconButtonList.add(buttonDrawPlanes);
|
||||
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
|
||||
if (modifierSettings != null) {
|
||||
Mirror.MirrorSettings m = modifierSettings.getMirrorSettings();
|
||||
buttonMirrorEnabled.setIsChecked(m.enabled);
|
||||
textMirrorPosX.setNumber(m.position.x);
|
||||
textMirrorPosY.setNumber(m.position.y);
|
||||
textMirrorPosZ.setNumber(m.position.z);
|
||||
buttonMirrorX.setIsChecked(m.mirrorX);
|
||||
buttonMirrorY.setIsChecked(m.mirrorY);
|
||||
buttonMirrorZ.setIsChecked(m.mirrorZ);
|
||||
textMirrorRadius.setNumber(m.radius);
|
||||
drawLines = m.drawLines;
|
||||
drawPlanes = m.drawPlanes;
|
||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
if (textMirrorPosX.getNumber() == Math.floor(textMirrorPosX.getNumber())) {
|
||||
toggleOdd = false;
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
} else {
|
||||
toggleOdd = true;
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
}
|
||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
}
|
||||
|
||||
renderables.addAll(mirrorButtonList);
|
||||
renderables.addAll(mirrorIconButtonList);
|
||||
|
||||
setCollapsed(!buttonMirrorEnabled.isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
mirrorNumberFieldList.forEach(GuiNumberField::update);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(PoseStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
boolean isSelected, float partialTicks) {
|
||||
|
||||
int yy = y;
|
||||
int offset = 8;
|
||||
|
||||
buttonMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
|
||||
if (buttonMirrorEnabled.isChecked()) {
|
||||
buttonMirrorEnabled.y = yy;
|
||||
font.draw(ms, "Mirror enabled", left + offset, yy + 2, 0xFFFFFF);
|
||||
|
||||
yy = y + 18;
|
||||
font.draw(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
|
||||
font.draw(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
|
||||
textMirrorPosX.y = yy;
|
||||
font.draw(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
|
||||
textMirrorPosY.y = yy;
|
||||
font.draw(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
|
||||
textMirrorPosZ.y = yy;
|
||||
|
||||
yy = y + 50;
|
||||
font.draw(ms, "Direction", left + offset, yy + 2, 0xFFFFFF);
|
||||
buttonMirrorX.y = yy;
|
||||
buttonMirrorY.y = yy;
|
||||
buttonMirrorZ.y = yy;
|
||||
font.draw(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
|
||||
textMirrorRadius.y = yy - 3;
|
||||
|
||||
yy = y + 72;
|
||||
buttonCurrentPosition.y = yy;
|
||||
buttonToggleOdd.y = yy;
|
||||
buttonDrawLines.y = yy;
|
||||
buttonDrawPlanes.y = yy;
|
||||
|
||||
mirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
mirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
|
||||
} else {
|
||||
buttonMirrorEnabled.y = yy;
|
||||
font.draw(ms, "Mirror disabled", left + offset, yy + 2, 0x999999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void drawTooltip(PoseStack ms, Screen guiScreen, int mouseX, int mouseY) {
|
||||
//Draw tooltips last
|
||||
if (buttonMirrorEnabled.isChecked()) {
|
||||
mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char typedChar, int keyCode) {
|
||||
super.charTyped(typedChar, keyCode);
|
||||
for (GuiNumberField numberField : mirrorNumberFieldList) {
|
||||
numberField.charTyped(typedChar, keyCode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||
mirrorNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||
|
||||
boolean insideMirrorEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||
|
||||
if (insideMirrorEnabledLabel) {
|
||||
buttonMirrorEnabled.playDownSound(this.mc.getSoundManager());
|
||||
buttonMirrorEnabled.onClick(mouseX, mouseY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Mirror.MirrorSettings getMirrorSettings() {
|
||||
boolean mirrorEnabled = buttonMirrorEnabled.isChecked();
|
||||
|
||||
Vec3 mirrorPos = new Vec3(0, 64, 0);
|
||||
try {
|
||||
mirrorPos = new Vec3(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Mirror position not a valid number.");
|
||||
}
|
||||
|
||||
boolean mirrorX = buttonMirrorX.isChecked();
|
||||
boolean mirrorY = buttonMirrorY.isChecked();
|
||||
boolean mirrorZ = buttonMirrorZ.isChecked();
|
||||
|
||||
int mirrorRadius = 50;
|
||||
try {
|
||||
mirrorRadius = (int) textMirrorRadius.getNumber();
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Mirror radius not a valid number.");
|
||||
}
|
||||
|
||||
return new Mirror.MirrorSettings(mirrorEnabled, mirrorPos, mirrorX, mirrorY, mirrorZ, mirrorRadius, drawLines, drawPlanes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Mirror";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpandedHeight() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.ClientEvents;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiCollapsibleScrollEntry;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ModifierSettingsGui extends Screen {
|
||||
private final Map<Class, Class> modifierPanelMap = new HashMap<Class, Class>() {{
|
||||
put(Mirror.class, MirrorPanel.class);
|
||||
put(Array.class, ArrayPanel.class);
|
||||
put(RadialMirror.class, RadialMirrorPanel.class);
|
||||
}};
|
||||
|
||||
private GuiScrollPane scrollPane;
|
||||
private List<BaseModifierPanel> modifierPanels;
|
||||
private Button buttonClose;
|
||||
|
||||
public ModifierSettingsGui() {
|
||||
super(Component.translatable("effortlessbuilding.screen.modifier_settings"));
|
||||
}
|
||||
|
||||
@Override
|
||||
//Create buttons and labels and add them to buttonList/labelList
|
||||
protected void init() {
|
||||
|
||||
scrollPane = new GuiScrollPane(this, font, 8, height - 30);
|
||||
|
||||
initScrollEntries();
|
||||
|
||||
scrollPane.init(renderables);
|
||||
|
||||
//Close button
|
||||
int y = height - 26;
|
||||
buttonClose = new Button(width / 2 - 100, y, 200, 20, Component.literal("Close"), (button) -> {
|
||||
Minecraft.getInstance().player.closeContainer();
|
||||
});
|
||||
addRenderableOnly(buttonClose);
|
||||
}
|
||||
|
||||
private void initScrollEntries() {
|
||||
|
||||
var modifierSettingsList = EffortlessBuildingClient.BUILD_MODIFIERS.getModifierSettingsList();
|
||||
for (BaseModifier modifier : modifierSettingsList) {
|
||||
BaseModifierPanel modifierPanel = createModifierPanel(modifier.getClass().getSimpleName());
|
||||
if (modifierPanel != null) {
|
||||
modifierPanel.setModifier(modifier);
|
||||
scrollPane.AddListEntry(modifierPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BaseModifierPanel createModifierPanel(String type) {
|
||||
switch (type) {
|
||||
case "Mirror": return new MirrorPanel(scrollPane);
|
||||
case "Array": return new ArrayPanel(scrollPane);
|
||||
case "RadialMirror": return new RadialMirrorPanel(scrollPane);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
//Process general logic, i.e. hide buttons
|
||||
public void tick() {
|
||||
scrollPane.updateScreen();
|
||||
|
||||
handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
//Set colors using GL11, use the fontObj field to display text
|
||||
//Use drawTexturedModalRect() to transfers areas of a texture resource to the screen
|
||||
public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(ms);
|
||||
|
||||
scrollPane.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
buttonClose.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
scrollPane.drawTooltip(ms, this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char typedChar, int keyCode) {
|
||||
super.charTyped(typedChar, keyCode);
|
||||
scrollPane.charTyped(typedChar, keyCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int p_96553_, int p_96554_) {
|
||||
if (keyCode == ClientEvents.keyBindings[1].getKey().getValue()) {
|
||||
minecraft.player.closeContainer();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, p_96553_, p_96554_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
renderables.forEach(renderable -> {
|
||||
if (renderable instanceof Button) {
|
||||
Button button = (Button) renderable;
|
||||
button.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
});
|
||||
return scrollPane.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int state) {
|
||||
if (state != 0 || !scrollPane.mouseReleased(mouseX, mouseY, state)) {
|
||||
return super.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleMouseInput() {
|
||||
//super.handleMouseInput();
|
||||
scrollPane.handleMouseInput();
|
||||
|
||||
//Scrolling numbers
|
||||
// int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
// int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
// numberFieldList.forEach(numberField -> numberField.handleMouseInput(mouseX, mouseY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
scrollPane.onGuiClosed();
|
||||
|
||||
//save everything
|
||||
Mirror.MirrorSettings m = mirrorPanel.getMirrorSettings();
|
||||
Array.ArraySettings a = arrayPanel.getArraySettings();
|
||||
RadialMirror.RadialMirrorSettings r = radialMirrorPanel.getRadialMirrorSettings();
|
||||
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(minecraft.player);
|
||||
if (modifierSettings == null) modifierSettings = new ModifierSettingsManager.ModifierSettings();
|
||||
modifierSettings.setMirrorSettings(m);
|
||||
modifierSettings.setArraySettings(a);
|
||||
modifierSettings.setRadialMirrorSettings(r);
|
||||
|
||||
//Sanitize
|
||||
String error = ModifierSettingsManager.sanitize(modifierSettings, minecraft.player);
|
||||
if (!error.isEmpty()) EffortlessBuilding.log(minecraft.player, error);
|
||||
|
||||
ModifierSettingsManager.setModifierSettings(minecraft.player, modifierSettings);
|
||||
|
||||
//Send to server
|
||||
PacketHandler.INSTANCE.sendToServer(new ModifierSettingsMessage(modifierSettings));
|
||||
|
||||
Minecraft.getInstance().mouseHandler.grabMouse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.ClientEvents;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.AbstractSimiScreen;
|
||||
import nl.requios.effortlessbuilding.gui.elements.GuiScrollPane;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ModifiersScreen extends AbstractSimiScreen {
|
||||
protected ModifiersScreenList list;
|
||||
private Button buttonClose;
|
||||
|
||||
public ModifiersScreen() {
|
||||
super(Component.translatable("effortlessbuilding.screen.modifier_settings"));
|
||||
}
|
||||
|
||||
@Override
|
||||
//Create buttons and labels and add them to buttonList/labelList
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
int listWidth = Math.min(width - 80, 300);
|
||||
int yCenter = height / 2;
|
||||
int listL = this.width / 2 - listWidth / 2;
|
||||
int listR = this.width / 2 + listWidth / 2;
|
||||
|
||||
list = new ModifiersScreenList(minecraft, listWidth, height - 80, 35, height - 45, 40);
|
||||
list.setLeftPos(this.width / 2 - list.getWidth() / 2);
|
||||
|
||||
addRenderableWidget(list);
|
||||
|
||||
initScrollEntries();
|
||||
|
||||
//Close button
|
||||
int y = height - 26;
|
||||
buttonClose = new Button(width / 2 - 100, y, 200, 20, Component.literal("Close"), (button) -> {
|
||||
Minecraft.getInstance().player.closeContainer();
|
||||
});
|
||||
addRenderableOnly(buttonClose);
|
||||
}
|
||||
|
||||
private void initScrollEntries() {
|
||||
|
||||
var modifierSettingsList = EffortlessBuildingClient.BUILD_MODIFIERS.getModifierSettingsList();
|
||||
for (BaseModifier modifier : modifierSettingsList) {
|
||||
var entry = createModifierPanel(modifier);
|
||||
list.children().add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
private BaseModifierEntry createModifierPanel(BaseModifier modifier) {
|
||||
if (modifier instanceof Mirror) {
|
||||
return new MirrorEntry(modifier);
|
||||
} else if (modifier instanceof Array) {
|
||||
return new ArrayEntry(modifier);
|
||||
} else if (modifier instanceof RadialMirror) {
|
||||
return new RadialMirrorEntry(modifier);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void addModifier(BaseModifier modifier) {
|
||||
var entry = createModifierPanel(modifier);
|
||||
list.children().add(entry);
|
||||
EffortlessBuildingClient.BUILD_MODIFIERS.addModifierSettings(modifier);
|
||||
}
|
||||
|
||||
private void removeModifier(BaseModifierEntry entry) {
|
||||
list.children().remove(entry);
|
||||
EffortlessBuildingClient.BUILD_MODIFIERS.removeModifierSettings(entry.modifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(@Nonnull Minecraft client, int width, int height) {
|
||||
double scroll = list.getScrollAmount();
|
||||
init(client, width, height);
|
||||
list.setScrollAmount(scroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
EffortlessBuildingClient.BUILD_MODIFIERS.save(minecraft.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int p_96553_, int p_96554_) {
|
||||
if (keyCode == ClientEvents.keyBindings[1].getKey().getValue()) {
|
||||
minecraft.player.closeContainer();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, p_96553_, p_96554_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//Based on Create's ConfigScreenList
|
||||
public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList.Entry> implements TickableGuiEventListener {
|
||||
|
||||
public ModifiersScreenList(Minecraft pMinecraft, int pWidth, int pHeight, int pY0, int pY1, int pItemHeight) {
|
||||
super(pMinecraft, pWidth, pHeight, pY0, pY1, pItemHeight);
|
||||
setRenderBackground(false);
|
||||
setRenderTopAndBottom(false);
|
||||
setRenderSelection(false);
|
||||
headerHeight = 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
|
||||
Color c = new Color(0x60_000000);
|
||||
UIRenderHelper.angledGradient(ms, 90, x0 + width / 2, y0, width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(ms, -90, x0 + width / 2, y1, width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(ms, 0, x0, y0 + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(ms, 180, x1, y0 + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
|
||||
super.render(ms, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderList(PoseStack p_239228_, int p_239229_, int p_239230_, float p_239231_) {
|
||||
Window window = minecraft.getWindow();
|
||||
double d0 = window.getGuiScale();
|
||||
RenderSystem.enableScissor((int) (this.x0 * d0), (int) (window.getHeight() - (this.y1 * d0)), (int) (this.width * d0), (int) (this.height * d0));
|
||||
super.renderList(p_239228_, p_239229_, p_239230_, p_239231_);
|
||||
RenderSystem.disableScissor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
children().stream().forEach(e -> e.mouseClicked(x, y, button));
|
||||
|
||||
return super.mouseClicked(x, y, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowWidth() {
|
||||
return width - 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollbarPosition() {
|
||||
return x0 + this.width - 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
children().forEach(Entry::tick);
|
||||
}
|
||||
|
||||
public static abstract class Entry extends ObjectSelectionList.Entry<Entry> implements TickableGuiEventListener {
|
||||
protected List<GuiEventListener> listeners;
|
||||
|
||||
protected Entry() {
|
||||
listeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
return getGuiListeners().stream().anyMatch(l -> l.mouseClicked(x, y, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return getGuiListeners().stream().anyMatch(l -> l.keyPressed(keyCode, scanCode, modifiers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char ch, int modifiers) {
|
||||
return getGuiListeners().stream().anyMatch(l -> l.charTyped(ch, modifiers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {}
|
||||
|
||||
@Override
|
||||
public void tick() {}
|
||||
|
||||
public List<GuiEventListener> getGuiListeners() {
|
||||
return listeners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getNarration() {
|
||||
return Components.immutableEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||
import nl.requios.effortlessbuilding.gui.elements.*;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class RadialMirrorEntry extends BaseModifierEntry<RadialMirror> {
|
||||
|
||||
public RadialMirrorEntry(BaseModifier modifier) {
|
||||
super((RadialMirror) modifier);
|
||||
}
|
||||
|
||||
// protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
||||
//
|
||||
// protected List<Button> radialMirrorButtonList = new ArrayList<>();
|
||||
// protected List<GuiIconButton> radialMirrorIconButtonList = new ArrayList<>();
|
||||
// protected List<GuiNumberField> radialMirrorNumberFieldList = new ArrayList<>();
|
||||
//
|
||||
// private GuiNumberField textRadialMirrorPosX, textRadialMirrorPosY, textRadialMirrorPosZ, textRadialMirrorSlices, textRadialMirrorRadius;
|
||||
// private GuiCheckBoxFixed buttonRadialMirrorEnabled, buttonRadialMirrorAlternate;
|
||||
// private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
||||
// private boolean drawPlanes, drawLines, toggleOdd;
|
||||
//
|
||||
// public RadialMirrorEntry(GuiScrollPane scrollPane) {
|
||||
// super(scrollPane);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void init(List<Widget> renderables) {
|
||||
// super.init(renderables);
|
||||
//
|
||||
// int y = top - 2;
|
||||
// buttonRadialMirrorEnabled = new GuiCheckBoxFixed(left - 15 + 8, y, "", false) {
|
||||
// @Override
|
||||
// public void onClick(double mouseX, double mouseY) {
|
||||
// super.onClick(mouseX, mouseY);
|
||||
// setCollapsed(!buttonRadialMirrorEnabled.isChecked());
|
||||
// }
|
||||
// };
|
||||
// renderables.add(buttonRadialMirrorEnabled);
|
||||
//
|
||||
// y = top + 18;
|
||||
// textRadialMirrorPosX = new GuiNumberField(font, renderables, left + 58, y, 62, 18);
|
||||
// textRadialMirrorPosX.setNumber(0);
|
||||
// textRadialMirrorPosX.setTooltip(
|
||||
// Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// radialMirrorNumberFieldList.add(textRadialMirrorPosX);
|
||||
//
|
||||
// textRadialMirrorPosY = new GuiNumberField(font, renderables, left + 138, y, 62, 18);
|
||||
// textRadialMirrorPosY.setNumber(64);
|
||||
// textRadialMirrorPosY.setTooltip(Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// radialMirrorNumberFieldList.add(textRadialMirrorPosY);
|
||||
//
|
||||
// textRadialMirrorPosZ = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
// textRadialMirrorPosZ.setNumber(0);
|
||||
// textRadialMirrorPosZ.setTooltip(Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
// radialMirrorNumberFieldList.add(textRadialMirrorPosZ);
|
||||
//
|
||||
// y = top + 47;
|
||||
// textRadialMirrorSlices = new GuiNumberField(font, renderables, left + 55, y, 50, 18);
|
||||
// textRadialMirrorSlices.setNumber(4);
|
||||
// textRadialMirrorSlices.setTooltip(Arrays.asList(Component.literal("The number of repeating slices."), Component.literal("Minimally 2.").withStyle(ChatFormatting.GRAY)));
|
||||
// radialMirrorNumberFieldList.add(textRadialMirrorSlices);
|
||||
//
|
||||
// textRadialMirrorRadius = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
// textRadialMirrorRadius.setNumber(50);
|
||||
// //TODO change to diameter (remove /2)
|
||||
// textRadialMirrorRadius.setTooltip(Arrays.asList(Component.literal("How far the radial mirror reaches from its center position."),
|
||||
// Component.literal("Max: ").withStyle(ChatFormatting.GRAY).append(Component.literal(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).withStyle(ChatFormatting.GOLD)),
|
||||
// Component.literal("Upgradeable in survival with reach upgrades.").withStyle(ChatFormatting.GRAY)));
|
||||
// radialMirrorNumberFieldList.add(textRadialMirrorRadius);
|
||||
//
|
||||
// y = top + 72;
|
||||
// buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
|
||||
// Vec3 pos = new Vec3(Math.floor(mc.player.getX()) + 0.5, Math.floor(mc.player.getY()) + 0.5, Math.floor(mc.player.getZ()) + 0.5);
|
||||
// textRadialMirrorPosX.setNumber(pos.x);
|
||||
// textRadialMirrorPosY.setNumber(pos.y);
|
||||
// textRadialMirrorPosZ.setNumber(pos.z);
|
||||
// });
|
||||
// buttonCurrentPosition.setTooltip(Component.literal("Set radial mirror position to current player position"));
|
||||
// radialMirrorIconButtonList.add(buttonCurrentPosition);
|
||||
//
|
||||
// buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
|
||||
// toggleOdd = !toggleOdd;
|
||||
// buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
// if (toggleOdd) {
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
// textRadialMirrorPosX.setNumber(textRadialMirrorPosX.getNumber() + 0.5);
|
||||
// textRadialMirrorPosY.setNumber(textRadialMirrorPosY.getNumber() + 0.5);
|
||||
// textRadialMirrorPosZ.setNumber(textRadialMirrorPosZ.getNumber() + 0.5);
|
||||
// } else {
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// textRadialMirrorPosX.setNumber(Math.floor(textRadialMirrorPosX.getNumber()));
|
||||
// textRadialMirrorPosY.setNumber(Math.floor(textRadialMirrorPosY.getNumber()));
|
||||
// textRadialMirrorPosZ.setNumber(Math.floor(textRadialMirrorPosZ.getNumber()));
|
||||
// }
|
||||
// });
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// radialMirrorIconButtonList.add(buttonToggleOdd);
|
||||
//
|
||||
// buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
|
||||
// drawLines = !drawLines;
|
||||
// buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
// buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
// });
|
||||
// buttonDrawLines.setTooltip(Component.literal("Show lines"));
|
||||
// radialMirrorIconButtonList.add(buttonDrawLines);
|
||||
//
|
||||
// buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
|
||||
// drawPlanes = !drawPlanes;
|
||||
// buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
// buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
// });
|
||||
// buttonDrawPlanes.setTooltip(Component.literal("Show area"));
|
||||
// radialMirrorIconButtonList.add(buttonDrawPlanes);
|
||||
//
|
||||
// y = top + 76;
|
||||
// buttonRadialMirrorAlternate = new GuiCheckBoxFixed(left + 140, y, " Alternate", false);
|
||||
// radialMirrorButtonList.add(buttonRadialMirrorAlternate);
|
||||
//
|
||||
// ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
|
||||
// if (modifierSettings != null) {
|
||||
// RadialMirror.RadialMirrorSettings r = modifierSettings.getRadialMirrorSettings();
|
||||
// buttonRadialMirrorEnabled.setIsChecked(r.enabled);
|
||||
// textRadialMirrorPosX.setNumber(r.position.x);
|
||||
// textRadialMirrorPosY.setNumber(r.position.y);
|
||||
// textRadialMirrorPosZ.setNumber(r.position.z);
|
||||
// textRadialMirrorSlices.setNumber(r.slices);
|
||||
// buttonRadialMirrorAlternate.setIsChecked(r.alternate);
|
||||
// textRadialMirrorRadius.setNumber(r.radius);
|
||||
// drawLines = r.drawLines;
|
||||
// drawPlanes = r.drawPlanes;
|
||||
// buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
// buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
// buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
// buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
// if (textRadialMirrorPosX.getNumber() == Math.floor(textRadialMirrorPosX.getNumber())) {
|
||||
// toggleOdd = false;
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
// } else {
|
||||
// toggleOdd = true;
|
||||
// buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
// }
|
||||
// buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
// }
|
||||
//
|
||||
// renderables.addAll(radialMirrorButtonList);
|
||||
// renderables.addAll(radialMirrorIconButtonList);
|
||||
//
|
||||
// setCollapsed(!buttonRadialMirrorEnabled.isChecked());
|
||||
// }
|
||||
//
|
||||
// public void updateScreen() {
|
||||
// radialMirrorNumberFieldList.forEach(GuiNumberField::update);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void drawEntry(PoseStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
// boolean isSelected, float partialTicks) {
|
||||
//
|
||||
// int yy = y;
|
||||
// int offset = 8;
|
||||
//
|
||||
// buttonRadialMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
|
||||
// if (buttonRadialMirrorEnabled.isChecked()) {
|
||||
// buttonRadialMirrorEnabled.y = yy;
|
||||
// font.draw(ms, "Radial mirror enabled", left + offset, yy + 2, 0xFFFFFF);
|
||||
//
|
||||
// yy = y + 18;
|
||||
// font.draw(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
|
||||
// font.draw(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
|
||||
// textRadialMirrorPosX.y = yy;
|
||||
// font.draw(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
|
||||
// textRadialMirrorPosY.y = yy;
|
||||
// font.draw(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
|
||||
// textRadialMirrorPosZ.y = yy;
|
||||
//
|
||||
// yy = y + 50;
|
||||
// font.draw(ms, "Slices", left + offset, yy + 2, 0xFFFFFF);
|
||||
// textRadialMirrorSlices.y = yy - 3;
|
||||
// font.draw(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
|
||||
// textRadialMirrorRadius.y = yy - 3;
|
||||
//
|
||||
// yy = y + 72;
|
||||
// buttonCurrentPosition.y = yy;
|
||||
// buttonToggleOdd.y = yy;
|
||||
// buttonDrawLines.y = yy;
|
||||
// buttonDrawPlanes.y = yy;
|
||||
//
|
||||
// yy = y + 76;
|
||||
// buttonRadialMirrorAlternate.y = yy;
|
||||
//
|
||||
// radialMirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
// radialMirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
// radialMirrorNumberFieldList
|
||||
// .forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
|
||||
// } else {
|
||||
// buttonRadialMirrorEnabled.y = yy;
|
||||
// font.draw(ms, "Radial mirror disabled", left + offset, yy + 2, 0x999999);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void drawTooltip(PoseStack ms, Screen guiScreen, int mouseX, int mouseY) {
|
||||
// //Draw tooltips last
|
||||
// if (buttonRadialMirrorEnabled.isChecked()) {
|
||||
// radialMirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
// radialMirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean charTyped(char typedChar, int modifiers) {
|
||||
// super.charTyped(typedChar, modifiers);
|
||||
// for (GuiNumberField numberField : radialMirrorNumberFieldList) {
|
||||
// numberField.charTyped(typedChar, modifiers);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||
// radialMirrorNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||
//
|
||||
// boolean insideRadialMirrorEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||
//
|
||||
// if (insideRadialMirrorEnabledLabel) {
|
||||
// buttonRadialMirrorEnabled.playDownSound(this.mc.getSoundManager());
|
||||
// buttonRadialMirrorEnabled.onClick(mouseX, mouseY);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public RadialMirror.RadialMirrorSettings getRadialMirrorSettings() {
|
||||
// boolean radialMirrorEnabled = buttonRadialMirrorEnabled.isChecked();
|
||||
//
|
||||
// Vec3 radialMirrorPos = new Vec3(0, 64, 0);
|
||||
// try {
|
||||
// radialMirrorPos = new Vec3(textRadialMirrorPosX.getNumber(), textRadialMirrorPosY.getNumber(), textRadialMirrorPosZ
|
||||
// .getNumber());
|
||||
// } catch (NumberFormatException | NullPointerException ex) {
|
||||
// EffortlessBuilding.log(mc.player, "Radial mirror position not a valid number.");
|
||||
// }
|
||||
//
|
||||
// int radialMirrorSlices = 4;
|
||||
// try {
|
||||
// radialMirrorSlices = (int) textRadialMirrorSlices.getNumber();
|
||||
// } catch (NumberFormatException | NullPointerException ex) {
|
||||
// EffortlessBuilding.log(mc.player, "Radial mirror slices not a valid number.");
|
||||
// }
|
||||
//
|
||||
// boolean radialMirrorAlternate = buttonRadialMirrorAlternate.isChecked();
|
||||
//
|
||||
// int radialMirrorRadius = 50;
|
||||
// try {
|
||||
// radialMirrorRadius = (int) textRadialMirrorRadius.getNumber();
|
||||
// } catch (NumberFormatException | NullPointerException ex) {
|
||||
// EffortlessBuilding.log(mc.player, "Mirror radius not a valid number.");
|
||||
// }
|
||||
//
|
||||
// return new RadialMirror.RadialMirrorSettings(radialMirrorEnabled, radialMirrorPos, radialMirrorSlices, radialMirrorAlternate, radialMirrorRadius, drawLines, drawPlanes);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected String getName() {
|
||||
// return "Radial mirror";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getExpandedHeight() {
|
||||
// return 100;
|
||||
// }
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||
import nl.requios.effortlessbuilding.gui.elements.*;
|
||||
import nl.requios.effortlessbuilding.utilities.ReachHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class RadialMirrorPanel extends BaseModifierPanel {
|
||||
|
||||
protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
||||
|
||||
protected List<Button> radialMirrorButtonList = new ArrayList<>();
|
||||
protected List<GuiIconButton> radialMirrorIconButtonList = new ArrayList<>();
|
||||
protected List<GuiNumberField> radialMirrorNumberFieldList = new ArrayList<>();
|
||||
|
||||
private GuiNumberField textRadialMirrorPosX, textRadialMirrorPosY, textRadialMirrorPosZ, textRadialMirrorSlices, textRadialMirrorRadius;
|
||||
private GuiCheckBoxFixed buttonRadialMirrorEnabled, buttonRadialMirrorAlternate;
|
||||
private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
||||
private boolean drawPlanes, drawLines, toggleOdd;
|
||||
|
||||
public RadialMirrorPanel(GuiScrollPane scrollPane) {
|
||||
super(scrollPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(List<Widget> renderables) {
|
||||
super.init(renderables);
|
||||
|
||||
int y = top - 2;
|
||||
buttonRadialMirrorEnabled = new GuiCheckBoxFixed(left - 15 + 8, y, "", false) {
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
super.onClick(mouseX, mouseY);
|
||||
setCollapsed(!buttonRadialMirrorEnabled.isChecked());
|
||||
}
|
||||
};
|
||||
renderables.add(buttonRadialMirrorEnabled);
|
||||
|
||||
y = top + 18;
|
||||
textRadialMirrorPosX = new GuiNumberField(font, renderables, left + 58, y, 62, 18);
|
||||
textRadialMirrorPosX.setNumber(0);
|
||||
textRadialMirrorPosX.setTooltip(
|
||||
Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
radialMirrorNumberFieldList.add(textRadialMirrorPosX);
|
||||
|
||||
textRadialMirrorPosY = new GuiNumberField(font, renderables, left + 138, y, 62, 18);
|
||||
textRadialMirrorPosY.setNumber(64);
|
||||
textRadialMirrorPosY.setTooltip(Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
radialMirrorNumberFieldList.add(textRadialMirrorPosY);
|
||||
|
||||
textRadialMirrorPosZ = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
textRadialMirrorPosZ.setNumber(0);
|
||||
textRadialMirrorPosZ.setTooltip(Arrays.asList(Component.literal("The position of the radial mirror."), Component.literal("For odd numbered builds add 0.5.").withStyle(ChatFormatting.GRAY)));
|
||||
radialMirrorNumberFieldList.add(textRadialMirrorPosZ);
|
||||
|
||||
y = top + 47;
|
||||
textRadialMirrorSlices = new GuiNumberField(font, renderables, left + 55, y, 50, 18);
|
||||
textRadialMirrorSlices.setNumber(4);
|
||||
textRadialMirrorSlices.setTooltip(Arrays.asList(Component.literal("The number of repeating slices."), Component.literal("Minimally 2.").withStyle(ChatFormatting.GRAY)));
|
||||
radialMirrorNumberFieldList.add(textRadialMirrorSlices);
|
||||
|
||||
textRadialMirrorRadius = new GuiNumberField(font, renderables, left + 218, y, 62, 18);
|
||||
textRadialMirrorRadius.setNumber(50);
|
||||
//TODO change to diameter (remove /2)
|
||||
textRadialMirrorRadius.setTooltip(Arrays.asList(Component.literal("How far the radial mirror reaches from its center position."),
|
||||
Component.literal("Max: ").withStyle(ChatFormatting.GRAY).append(Component.literal(String.valueOf(ReachHelper.getMaxReach(mc.player) / 2)).withStyle(ChatFormatting.GOLD)),
|
||||
Component.literal("Upgradeable in survival with reach upgrades.").withStyle(ChatFormatting.GRAY)));
|
||||
radialMirrorNumberFieldList.add(textRadialMirrorRadius);
|
||||
|
||||
y = top + 72;
|
||||
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
|
||||
Vec3 pos = new Vec3(Math.floor(mc.player.getX()) + 0.5, Math.floor(mc.player.getY()) + 0.5, Math.floor(mc.player.getZ()) + 0.5);
|
||||
textRadialMirrorPosX.setNumber(pos.x);
|
||||
textRadialMirrorPosY.setNumber(pos.y);
|
||||
textRadialMirrorPosZ.setNumber(pos.z);
|
||||
});
|
||||
buttonCurrentPosition.setTooltip(Component.literal("Set radial mirror position to current player position"));
|
||||
radialMirrorIconButtonList.add(buttonCurrentPosition);
|
||||
|
||||
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
|
||||
toggleOdd = !toggleOdd;
|
||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
if (toggleOdd) {
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
textRadialMirrorPosX.setNumber(textRadialMirrorPosX.getNumber() + 0.5);
|
||||
textRadialMirrorPosY.setNumber(textRadialMirrorPosY.getNumber() + 0.5);
|
||||
textRadialMirrorPosZ.setNumber(textRadialMirrorPosZ.getNumber() + 0.5);
|
||||
} else {
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
textRadialMirrorPosX.setNumber(Math.floor(textRadialMirrorPosX.getNumber()));
|
||||
textRadialMirrorPosY.setNumber(Math.floor(textRadialMirrorPosY.getNumber()));
|
||||
textRadialMirrorPosZ.setNumber(Math.floor(textRadialMirrorPosZ.getNumber()));
|
||||
}
|
||||
});
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
radialMirrorIconButtonList.add(buttonToggleOdd);
|
||||
|
||||
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
|
||||
drawLines = !drawLines;
|
||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
});
|
||||
buttonDrawLines.setTooltip(Component.literal("Show lines"));
|
||||
radialMirrorIconButtonList.add(buttonDrawLines);
|
||||
|
||||
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
|
||||
drawPlanes = !drawPlanes;
|
||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
});
|
||||
buttonDrawPlanes.setTooltip(Component.literal("Show area"));
|
||||
radialMirrorIconButtonList.add(buttonDrawPlanes);
|
||||
|
||||
y = top + 76;
|
||||
buttonRadialMirrorAlternate = new GuiCheckBoxFixed(left + 140, y, " Alternate", false);
|
||||
radialMirrorButtonList.add(buttonRadialMirrorAlternate);
|
||||
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
|
||||
if (modifierSettings != null) {
|
||||
RadialMirror.RadialMirrorSettings r = modifierSettings.getRadialMirrorSettings();
|
||||
buttonRadialMirrorEnabled.setIsChecked(r.enabled);
|
||||
textRadialMirrorPosX.setNumber(r.position.x);
|
||||
textRadialMirrorPosY.setNumber(r.position.y);
|
||||
textRadialMirrorPosZ.setNumber(r.position.z);
|
||||
textRadialMirrorSlices.setNumber(r.slices);
|
||||
buttonRadialMirrorAlternate.setIsChecked(r.alternate);
|
||||
textRadialMirrorRadius.setNumber(r.radius);
|
||||
drawLines = r.drawLines;
|
||||
drawPlanes = r.drawPlanes;
|
||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||
buttonDrawLines.setTooltip(Component.literal(drawLines ? "Hide lines" : "Show lines"));
|
||||
buttonDrawPlanes.setTooltip(Component.literal(drawPlanes ? "Hide area" : "Show area"));
|
||||
if (textRadialMirrorPosX.getNumber() == Math.floor(textRadialMirrorPosX.getNumber())) {
|
||||
toggleOdd = false;
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to middle of block"), Component.literal("for odd numbered builds")));
|
||||
} else {
|
||||
toggleOdd = true;
|
||||
buttonToggleOdd.setTooltip(Arrays.asList(Component.literal("Set radial mirror position to corner of block"), Component.literal("for even numbered builds")));
|
||||
}
|
||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||
}
|
||||
|
||||
renderables.addAll(radialMirrorButtonList);
|
||||
renderables.addAll(radialMirrorIconButtonList);
|
||||
|
||||
setCollapsed(!buttonRadialMirrorEnabled.isChecked());
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
radialMirrorNumberFieldList.forEach(GuiNumberField::update);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawEntry(PoseStack ms, int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
boolean isSelected, float partialTicks) {
|
||||
|
||||
int yy = y;
|
||||
int offset = 8;
|
||||
|
||||
buttonRadialMirrorEnabled.render(ms, mouseX, mouseY, partialTicks);
|
||||
if (buttonRadialMirrorEnabled.isChecked()) {
|
||||
buttonRadialMirrorEnabled.y = yy;
|
||||
font.draw(ms, "Radial mirror enabled", left + offset, yy + 2, 0xFFFFFF);
|
||||
|
||||
yy = y + 18;
|
||||
font.draw(ms, "Position", left + offset, yy + 5, 0xFFFFFF);
|
||||
font.draw(ms, "X", left + 40 + offset, yy + 5, 0xFFFFFF);
|
||||
textRadialMirrorPosX.y = yy;
|
||||
font.draw(ms, "Y", left + 120 + offset, yy + 5, 0xFFFFFF);
|
||||
textRadialMirrorPosY.y = yy;
|
||||
font.draw(ms, "Z", left + 200 + offset, yy + 5, 0xFFFFFF);
|
||||
textRadialMirrorPosZ.y = yy;
|
||||
|
||||
yy = y + 50;
|
||||
font.draw(ms, "Slices", left + offset, yy + 2, 0xFFFFFF);
|
||||
textRadialMirrorSlices.y = yy - 3;
|
||||
font.draw(ms, "Radius", left + 176 + offset, yy + 2, 0xFFFFFF);
|
||||
textRadialMirrorRadius.y = yy - 3;
|
||||
|
||||
yy = y + 72;
|
||||
buttonCurrentPosition.y = yy;
|
||||
buttonToggleOdd.y = yy;
|
||||
buttonDrawLines.y = yy;
|
||||
buttonDrawPlanes.y = yy;
|
||||
|
||||
yy = y + 76;
|
||||
buttonRadialMirrorAlternate.y = yy;
|
||||
|
||||
radialMirrorButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
radialMirrorIconButtonList.forEach(button -> button.render(ms, mouseX, mouseY, partialTicks));
|
||||
radialMirrorNumberFieldList
|
||||
.forEach(numberField -> numberField.drawNumberField(ms, mouseX, mouseY, partialTicks));
|
||||
} else {
|
||||
buttonRadialMirrorEnabled.y = yy;
|
||||
font.draw(ms, "Radial mirror disabled", left + offset, yy + 2, 0x999999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void drawTooltip(PoseStack ms, Screen guiScreen, int mouseX, int mouseY) {
|
||||
//Draw tooltips last
|
||||
if (buttonRadialMirrorEnabled.isChecked()) {
|
||||
radialMirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
radialMirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(ms, scrollPane.parent, mouseX, mouseY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char typedChar, int keyCode) {
|
||||
super.charTyped(typedChar, keyCode);
|
||||
for (GuiNumberField numberField : radialMirrorNumberFieldList) {
|
||||
numberField.charTyped(typedChar, keyCode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||
radialMirrorNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||
|
||||
boolean insideRadialMirrorEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||
|
||||
if (insideRadialMirrorEnabledLabel) {
|
||||
buttonRadialMirrorEnabled.playDownSound(this.mc.getSoundManager());
|
||||
buttonRadialMirrorEnabled.onClick(mouseX, mouseY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public RadialMirror.RadialMirrorSettings getRadialMirrorSettings() {
|
||||
boolean radialMirrorEnabled = buttonRadialMirrorEnabled.isChecked();
|
||||
|
||||
Vec3 radialMirrorPos = new Vec3(0, 64, 0);
|
||||
try {
|
||||
radialMirrorPos = new Vec3(textRadialMirrorPosX.getNumber(), textRadialMirrorPosY.getNumber(), textRadialMirrorPosZ
|
||||
.getNumber());
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Radial mirror position not a valid number.");
|
||||
}
|
||||
|
||||
int radialMirrorSlices = 4;
|
||||
try {
|
||||
radialMirrorSlices = (int) textRadialMirrorSlices.getNumber();
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Radial mirror slices not a valid number.");
|
||||
}
|
||||
|
||||
boolean radialMirrorAlternate = buttonRadialMirrorAlternate.isChecked();
|
||||
|
||||
int radialMirrorRadius = 50;
|
||||
try {
|
||||
radialMirrorRadius = (int) textRadialMirrorRadius.getNumber();
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
EffortlessBuilding.log(mc.player, "Mirror radius not a valid number.");
|
||||
}
|
||||
|
||||
return new RadialMirror.RadialMirrorSettings(radialMirrorEnabled, radialMirrorPos, radialMirrorSlices, radialMirrorAlternate, radialMirrorRadius, drawLines, drawPlanes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Radial mirror";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpandedHeight() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import java.util.List;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class SlotGui extends AbstractContainerEventHandler implements Widget {
|
||||
protected final Minecraft minecraft;
|
||||
protected final int itemHeight;
|
||||
|
||||
@@ -15,152 +15,152 @@ import java.awt.*;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ModifierRenderer {
|
||||
|
||||
protected static final Color colorX = new Color(255, 72, 52);
|
||||
protected static final Color colorY = new Color(67, 204, 51);
|
||||
protected static final Color colorZ = new Color(52, 247, 255);
|
||||
protected static final Color colorRadial = new Color(52, 247, 255);
|
||||
protected static final int lineAlpha = 200;
|
||||
protected static final int planeAlpha = 50;
|
||||
protected static final Vec3 epsilon = new Vec3(0.001, 0.001, 0.001); //prevents z-fighting
|
||||
|
||||
public static void render(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, ModifierSettingsManager.ModifierSettings modifierSettings) {
|
||||
//Mirror lines and areas
|
||||
Mirror.MirrorSettings m = modifierSettings.getMirrorSettings();
|
||||
if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ)) {
|
||||
Vec3 pos = m.position.add(epsilon);
|
||||
int radius = m.radius;
|
||||
|
||||
if (m.mirrorX) {
|
||||
Vec3 posA = new Vec3(pos.x, pos.y - radius, pos.z - radius);
|
||||
Vec3 posB = new Vec3(pos.x, pos.y + radius, pos.z + radius);
|
||||
|
||||
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorX, m.drawLines, m.drawPlanes, true);
|
||||
}
|
||||
if (m.mirrorY) {
|
||||
Vec3 posA = new Vec3(pos.x - radius, pos.y, pos.z - radius);
|
||||
Vec3 posB = new Vec3(pos.x + radius, pos.y, pos.z + radius);
|
||||
|
||||
drawMirrorPlaneY(matrixStack, renderTypeBuffer, posA, posB, colorY, m.drawLines, m.drawPlanes);
|
||||
}
|
||||
if (m.mirrorZ) {
|
||||
Vec3 posA = new Vec3(pos.x - radius, pos.y - radius, pos.z);
|
||||
Vec3 posB = new Vec3(pos.x + radius, pos.y + radius, pos.z);
|
||||
|
||||
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorZ, m.drawLines, m.drawPlanes, true);
|
||||
}
|
||||
|
||||
//Draw axis coordinated colors if two or more axes are enabled
|
||||
//(If only one is enabled the lines are that planes color)
|
||||
if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ))) {
|
||||
drawMirrorLines(matrixStack, renderTypeBuffer, m);
|
||||
}
|
||||
}
|
||||
|
||||
//Radial mirror lines and areas
|
||||
RadialMirror.RadialMirrorSettings r = modifierSettings.getRadialMirrorSettings();
|
||||
if (r != null && r.enabled) {
|
||||
Vec3 pos = r.position.add(epsilon);
|
||||
int radius = r.radius;
|
||||
|
||||
float angle = 2f * ((float) Math.PI) / r.slices;
|
||||
Vec3 relStartVec = new Vec3(radius, 0, 0);
|
||||
if (r.slices % 4 == 2) relStartVec = relStartVec.yRot(angle / 2f);
|
||||
|
||||
for (int i = 0; i < r.slices; i++) {
|
||||
Vec3 relNewVec = relStartVec.yRot(angle * i);
|
||||
Vec3 newVec = pos.add(relNewVec);
|
||||
|
||||
Vec3 posA = new Vec3(pos.x, pos.y - radius, pos.z);
|
||||
Vec3 posB = new Vec3(newVec.x, pos.y + radius, newVec.z);
|
||||
drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorRadial, r.drawLines, r.drawPlanes, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----Mirror----
|
||||
|
||||
protected static void drawMirrorPlane(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Vec3 posA, Vec3 posB, Color c, boolean drawLines, boolean drawPlanes, boolean drawVerticalLines) {
|
||||
|
||||
// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
|
||||
Matrix4f matrixPos = matrixStack.last().pose();
|
||||
|
||||
if (drawPlanes) {
|
||||
VertexConsumer buffer = RenderHandler.beginPlanes(renderTypeBuffer);
|
||||
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posB.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) posB.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
//backface (using triangle strip)
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posB.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
|
||||
RenderHandler.endPlanes(renderTypeBuffer);
|
||||
}
|
||||
|
||||
if (drawLines) {
|
||||
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
|
||||
Vec3 middle = posA.add(posB).scale(0.5);
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
if (drawVerticalLines) {
|
||||
buffer.vertex(matrixPos, (float) middle.x, (float) posA.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) middle.x, (float) posB.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
}
|
||||
|
||||
RenderHandler.endLines(renderTypeBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void drawMirrorPlaneY(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Vec3 posA, Vec3 posB, Color c, boolean drawLines, boolean drawPlanes) {
|
||||
|
||||
// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
||||
Matrix4f matrixPos = matrixStack.last().pose();
|
||||
|
||||
if (drawPlanes) {
|
||||
VertexConsumer buffer = RenderHandler.beginPlanes(renderTypeBuffer);
|
||||
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
//backface (using triangle strip)
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
|
||||
RenderHandler.endPlanes(renderTypeBuffer);
|
||||
}
|
||||
|
||||
if (drawLines) {
|
||||
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
|
||||
Vec3 middle = posA.add(posB).scale(0.5);
|
||||
buffer.vertex(matrixPos, (float) middle.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) middle.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posA.x, (float) middle.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) posB.x, (float) middle.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
|
||||
RenderHandler.endLines(renderTypeBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void drawMirrorLines(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Mirror.MirrorSettings m) {
|
||||
|
||||
// GL11.glColor4d(100, 100, 100, 255);
|
||||
VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
Matrix4f matrixPos = matrixStack.last().pose();
|
||||
|
||||
Vec3 pos = m.position.add(epsilon);
|
||||
|
||||
buffer.vertex(matrixPos, (float) pos.x - m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) pos.x + m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) pos.x, (float) pos.y - m.radius, (float) pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) pos.x, (float) pos.y + m.radius, (float) pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) pos.x, (float) pos.y, (float) pos.z - m.radius).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||
buffer.vertex(matrixPos, (float) pos.x, (float) pos.y, (float) pos.z + m.radius).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||
|
||||
RenderHandler.endLines(renderTypeBuffer);
|
||||
}
|
||||
// protected static final Color colorX = new Color(255, 72, 52);
|
||||
// protected static final Color colorY = new Color(67, 204, 51);
|
||||
// protected static final Color colorZ = new Color(52, 247, 255);
|
||||
// protected static final Color colorRadial = new Color(52, 247, 255);
|
||||
// protected static final int lineAlpha = 200;
|
||||
// protected static final int planeAlpha = 50;
|
||||
// protected static final Vec3 epsilon = new Vec3(0.001, 0.001, 0.001); //prevents z-fighting
|
||||
//
|
||||
// public static void render(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, ModifierSettingsManager.ModifierSettings modifierSettings) {
|
||||
// //Mirror lines and areas
|
||||
// Mirror.MirrorSettings m = modifierSettings.getMirrorSettings();
|
||||
// if (m != null && m.enabled && (m.mirrorX || m.mirrorY || m.mirrorZ)) {
|
||||
// Vec3 pos = m.position.add(epsilon);
|
||||
// int radius = m.radius;
|
||||
//
|
||||
// if (m.mirrorX) {
|
||||
// Vec3 posA = new Vec3(pos.x, pos.y - radius, pos.z - radius);
|
||||
// Vec3 posB = new Vec3(pos.x, pos.y + radius, pos.z + radius);
|
||||
//
|
||||
// drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorX, m.drawLines, m.drawPlanes, true);
|
||||
// }
|
||||
// if (m.mirrorY) {
|
||||
// Vec3 posA = new Vec3(pos.x - radius, pos.y, pos.z - radius);
|
||||
// Vec3 posB = new Vec3(pos.x + radius, pos.y, pos.z + radius);
|
||||
//
|
||||
// drawMirrorPlaneY(matrixStack, renderTypeBuffer, posA, posB, colorY, m.drawLines, m.drawPlanes);
|
||||
// }
|
||||
// if (m.mirrorZ) {
|
||||
// Vec3 posA = new Vec3(pos.x - radius, pos.y - radius, pos.z);
|
||||
// Vec3 posB = new Vec3(pos.x + radius, pos.y + radius, pos.z);
|
||||
//
|
||||
// drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorZ, m.drawLines, m.drawPlanes, true);
|
||||
// }
|
||||
//
|
||||
// //Draw axis coordinated colors if two or more axes are enabled
|
||||
// //(If only one is enabled the lines are that planes color)
|
||||
// if (m.drawLines && ((m.mirrorX && m.mirrorY) || (m.mirrorX && m.mirrorZ) || (m.mirrorY && m.mirrorZ))) {
|
||||
// drawMirrorLines(matrixStack, renderTypeBuffer, m);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //Radial mirror lines and areas
|
||||
// RadialMirror.RadialMirrorSettings r = modifierSettings.getRadialMirrorSettings();
|
||||
// if (r != null && r.enabled) {
|
||||
// Vec3 pos = r.position.add(epsilon);
|
||||
// int radius = r.radius;
|
||||
//
|
||||
// float angle = 2f * ((float) Math.PI) / r.slices;
|
||||
// Vec3 relStartVec = new Vec3(radius, 0, 0);
|
||||
// if (r.slices % 4 == 2) relStartVec = relStartVec.yRot(angle / 2f);
|
||||
//
|
||||
// for (int i = 0; i < r.slices; i++) {
|
||||
// Vec3 relNewVec = relStartVec.yRot(angle * i);
|
||||
// Vec3 newVec = pos.add(relNewVec);
|
||||
//
|
||||
// Vec3 posA = new Vec3(pos.x, pos.y - radius, pos.z);
|
||||
// Vec3 posB = new Vec3(newVec.x, pos.y + radius, newVec.z);
|
||||
// drawMirrorPlane(matrixStack, renderTypeBuffer, posA, posB, colorRadial, r.drawLines, r.drawPlanes, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //----Mirror----
|
||||
//
|
||||
// protected static void drawMirrorPlane(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Vec3 posA, Vec3 posB, Color c, boolean drawLines, boolean drawPlanes, boolean drawVerticalLines) {
|
||||
//
|
||||
//// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha);
|
||||
// Matrix4f matrixPos = matrixStack.last().pose();
|
||||
//
|
||||
// if (drawPlanes) {
|
||||
// VertexConsumer buffer = RenderHandler.beginPlanes(renderTypeBuffer);
|
||||
//
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posB.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) posB.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// //backface (using triangle strip)
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posB.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
//
|
||||
// RenderHandler.endPlanes(renderTypeBuffer);
|
||||
// }
|
||||
//
|
||||
// if (drawLines) {
|
||||
// VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
//
|
||||
// Vec3 middle = posA.add(posB).scale(0.5);
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// if (drawVerticalLines) {
|
||||
// buffer.vertex(matrixPos, (float) middle.x, (float) posA.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) middle.x, (float) posB.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// }
|
||||
//
|
||||
// RenderHandler.endLines(renderTypeBuffer);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected static void drawMirrorPlaneY(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Vec3 posA, Vec3 posB, Color c, boolean drawLines, boolean drawPlanes) {
|
||||
//
|
||||
//// GL11.glColor4d(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
|
||||
// Matrix4f matrixPos = matrixStack.last().pose();
|
||||
//
|
||||
// if (drawPlanes) {
|
||||
// VertexConsumer buffer = RenderHandler.beginPlanes(renderTypeBuffer);
|
||||
//
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// //backface (using triangle strip)
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) posA.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), planeAlpha).endVertex();
|
||||
//
|
||||
// RenderHandler.endPlanes(renderTypeBuffer);
|
||||
// }
|
||||
//
|
||||
// if (drawLines) {
|
||||
// VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
//
|
||||
// Vec3 middle = posA.add(posB).scale(0.5);
|
||||
// buffer.vertex(matrixPos, (float) middle.x, (float) middle.y, (float) posA.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) middle.x, (float) middle.y, (float) posB.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posA.x, (float) middle.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) posB.x, (float) middle.y, (float) middle.z).color(c.getRed(), c.getGreen(), c.getBlue(), lineAlpha).endVertex();
|
||||
//
|
||||
// RenderHandler.endLines(renderTypeBuffer);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected static void drawMirrorLines(PoseStack matrixStack, MultiBufferSource.BufferSource renderTypeBuffer, Mirror.MirrorSettings m) {
|
||||
//
|
||||
//// GL11.glColor4d(100, 100, 100, 255);
|
||||
// VertexConsumer buffer = RenderHandler.beginLines(renderTypeBuffer);
|
||||
// Matrix4f matrixPos = matrixStack.last().pose();
|
||||
//
|
||||
// Vec3 pos = m.position.add(epsilon);
|
||||
//
|
||||
// buffer.vertex(matrixPos, (float) pos.x - m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) pos.x + m.radius, (float) pos.y, (float) pos.z).color(colorX.getRed(), colorX.getGreen(), colorX.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) pos.x, (float) pos.y - m.radius, (float) pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) pos.x, (float) pos.y + m.radius, (float) pos.z).color(colorY.getRed(), colorY.getGreen(), colorY.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) pos.x, (float) pos.y, (float) pos.z - m.radius).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||
// buffer.vertex(matrixPos, (float) pos.x, (float) pos.y, (float) pos.z + m.radius).color(colorZ.getRed(), colorZ.getGreen(), colorZ.getBlue(), lineAlpha).endVertex();
|
||||
//
|
||||
// RenderHandler.endLines(renderTypeBuffer);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -29,22 +29,22 @@ public class RenderHandler {
|
||||
public static void onRender(RenderLevelStageEvent event) {
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_TRANSLUCENT_BLOCKS) return;
|
||||
|
||||
Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
|
||||
|
||||
// Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
|
||||
//
|
||||
PoseStack ms = event.getPoseStack();
|
||||
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
|
||||
MultiBufferSource.BufferSource buffer = MultiBufferSource.immediate(bufferBuilder);
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
|
||||
|
||||
ms.pushPose();
|
||||
ms.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
|
||||
|
||||
//Mirror and radial mirror lines and areas
|
||||
ModifierRenderer.render(ms, buffer, modifierSettings);
|
||||
|
||||
ms.popPose();
|
||||
// BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
|
||||
// MultiBufferSource.BufferSource buffer = MultiBufferSource.immediate(bufferBuilder);
|
||||
//
|
||||
// Player player = Minecraft.getInstance().player;
|
||||
// ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(player);
|
||||
//
|
||||
// ms.pushPose();
|
||||
// ms.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
|
||||
//
|
||||
// //Mirror and radial mirror lines and areas
|
||||
// ModifierRenderer.render(ms, buffer, modifierSettings);
|
||||
//
|
||||
// ms.popPose();
|
||||
|
||||
renderSubText(ms);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package nl.requios.effortlessbuilding.utilities;
|
||||
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
public class MathHelper {
|
||||
|
||||
public static Vec3i with(Vec3i vec, int index, int value) {
|
||||
return switch (index) {
|
||||
case 0 -> new Vec3i(value, vec.getY(), vec.getZ());
|
||||
case 1 -> new Vec3i(vec.getX(), value, vec.getZ());
|
||||
case 2 -> new Vec3i(vec.getX(), vec.getY(), value);
|
||||
default -> throw new IllegalArgumentException("Index must be between 0 and 2");
|
||||
};
|
||||
}
|
||||
|
||||
public static int get(Vec3i vec, int index) {
|
||||
return switch (index) {
|
||||
case 0 -> vec.getX();
|
||||
case 1 -> vec.getY();
|
||||
case 2 -> vec.getZ();
|
||||
default -> throw new IllegalArgumentException("Index must be between 0 and 2");
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user