Fixed screens, except containerscreen. Fixed clientproxy and BlockRayTraceResult (cast if type = block).

This commit is contained in:
Christian Knaapen
2019-12-06 15:23:05 +01:00
parent ac429ca64e
commit 83b23fe763
16 changed files with 403 additions and 472 deletions

View File

@@ -1,6 +1,8 @@
package nl.requios.effortlessbuilding;
import net.minecraft.block.Block;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item;
import net.minecraft.item.BlockItem;
import net.minecraftforge.event.RegistryEvent;
@@ -18,8 +20,7 @@ public class ModEventHandler {
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
public static void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(EffortlessBuilding.ITEMS);
for (Block block : EffortlessBuilding.BLOCKS)
@@ -27,4 +28,10 @@ public class ModEventHandler {
event.getRegistry().register(new BlockItem(block, new Item.Properties()).setRegistryName(block.getRegistryName()));
}
}
//TODO 1.14 Gui
// @SubscribeEvent
// public static void registerContainerTypes(RegistryEvent.Register<ContainerType<?>> event) {
// event.getRegistry().register()
// }
}

View File

@@ -20,6 +20,8 @@ public class RandomizerBagContainer extends Container {
HOTBAR_START = INV_END + 1, HOTBAR_END = HOTBAR_START + 8;
public RandomizerBagContainer(PlayerInventory parInventoryPlayer, IItemHandler parIInventory) {
//TODO 1.14 Gui
super(null, 0);
bagInventory = parIInventory;
sizeInventory = bagInventory.getSlots();
for (int i = 0; i < sizeInventory; ++i) {

View File

@@ -2,9 +2,9 @@ package nl.requios.effortlessbuilding.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler;
@@ -18,7 +18,7 @@ public class RandomizerBagGuiContainer extends ContainerScreen {
private final IItemHandler inventoryBag;
public RandomizerBagGuiContainer(PlayerInventory inventoryPlayer, IItemHandler inventoryBag) {
super(new RandomizerBagContainer(inventoryPlayer, inventoryBag));
super(new RandomizerBagContainer(inventoryPlayer, inventoryBag), inventoryPlayer, new TranslationTextComponent("effortlessbuilding.screen.randomizer_bag"));
this.inventoryPlayer = inventoryPlayer;
this.inventoryBag = inventoryBag;
@@ -27,7 +27,7 @@ public class RandomizerBagGuiContainer extends ContainerScreen {
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
renderBackground();
super.render(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
@@ -45,6 +45,6 @@ public class RandomizerBagGuiContainer extends ContainerScreen {
minecraft.getTextureManager().bindTexture(guiTextures);
int marginHorizontal = (width - xSize) / 2;
int marginVertical = (height - ySize) / 2;
drawTexturedModalRect(marginHorizontal, marginVertical, 0, 0, xSize, ySize);
blit(marginHorizontal, marginVertical, 0, 0, xSize, ySize);
}
}

View File

@@ -6,10 +6,11 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.IInteractionObject;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.FMLPlayMessages;
@@ -19,8 +20,8 @@ import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.item.ItemRandomizerBag;
import javax.annotation.Nullable;
TODO 1.14 GUI
public class RandomizerBagGuiHandler implements /*IGuiHandler, */IInteractionObject {
public class RandomizerBagGuiHandler implements INamedContainerProvider {
// @Nullable
// @Override
// public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -54,54 +55,40 @@ public class RandomizerBagGuiHandler implements /*IGuiHandler, */IInteractionObj
// return null;
// }
@OnlyIn(Dist.CLIENT)
public static Screen openGui(FMLPlayMessages.OpenContainer openContainer) {
if (openContainer.getId().equals(EffortlessBuilding.RANDOMIZER_BAG_GUI)) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof ItemRandomizerBag) {
IItemHandler itemHandler = player.getHeldItem(Hand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
if (itemHandler != null) {
return new RandomizerBagGuiContainer(player.inventory, itemHandler);
}
}
}
return null;
}
@Override
public Container createContainer(PlayerInventory inventory, PlayerEntity player) {
if (player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof ItemRandomizerBag) {
IItemHandler itemHandler = player.getHeldItem(Hand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
if (itemHandler != null) {
return new RandomizerBagContainer(inventory, itemHandler);
}
}
return null;
}
@Override
public String getGuiID() {
return EffortlessBuilding.RANDOMIZER_BAG_GUI.toString();
}
@Override
public ITextComponent getName() {
return new StringTextComponent("Randomizer Bag");
}
@Override
public boolean hasCustomName() {
return false;
}
// @OnlyIn(Dist.CLIENT)
// public static Screen openGui(FMLPlayMessages.OpenContainer openContainer) {
// if (openContainer.getId().equals(EffortlessBuilding.RANDOMIZER_BAG_GUI)) {
// ClientPlayerEntity player = Minecraft.getInstance().player;
// if (player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof ItemRandomizerBag) {
// IItemHandler itemHandler = player.getHeldItem(Hand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
// if (itemHandler != null) {
// return new RandomizerBagGuiContainer(player.inventory, itemHandler);
// }
// }
// }
// return null;
// }
//
// @Override
// public Container createContainer(PlayerInventory inventory, PlayerEntity player) {
// if (player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof ItemRandomizerBag) {
// IItemHandler itemHandler = player.getHeldItem(Hand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
// if (itemHandler != null) {
// return new RandomizerBagContainer(inventory, itemHandler);
// }
// }
// return null;
// }
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Randomizer Bag");
return new TranslationTextComponent("effortlessbuilding.screen.randomizer_bag");
}
//TODO 1.14 GUI
@Nullable
@Override
public ITextComponent getCustomName() {
public Container createMenu(int containerId, PlayerInventory playerInventory, PlayerEntity player) {
return null;
}
}

View File

@@ -7,7 +7,9 @@ import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
@@ -18,7 +20,6 @@ import com.google.common.base.Stopwatch;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
@@ -41,6 +42,10 @@ public class RadialMenu extends Screen {
public ActionEnum doAction = null;
public boolean actionUsed = false;
public RadialMenu() {
super(new TranslationTextComponent("effortlessbuilding.screen.radial_menu"));
}
private float clampVis(final float f) {
return Math.max( 0.0f, Math.min( 1.0f, f ) );
}
@@ -118,7 +123,7 @@ public class RadialMenu extends Screen {
final int startColor = (int) ( visibility * 98 ) << 24;
final int endColor = (int) ( visibility * 128 ) << 24;
drawGradientRect(0, 0, width, height, startColor, endColor);
fillGradient(0, 0, width, height, startColor, endColor);
GlStateManager.disableTexture();
GlStateManager.enableBlend();
@@ -229,10 +234,10 @@ public class RadialMenu extends Screen {
switchTo = menuRegion.mode;
}
buffer.pos(middleX + x1m1, middleY + y1m1, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + x2m1, middleY + y2m1, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + x2m2, middleY + y2m2, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + x1m2, middleY + y1m2, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + x1m1, middleY + y1m1, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + x2m1, middleY + y2m1, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + x2m2, middleY + y2m2, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + x1m2, middleY + y1m2, blitOffset).color(r, g, b, a).endVertex();
currentMode++;
}
@@ -268,10 +273,10 @@ public class RadialMenu extends Screen {
doAction = btn.action;
}
buffer.pos(middleX + btn.x1, middleY + btn.y1, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x1, middleY + btn.y2, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x2, middleY + btn.y2, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x2, middleY + btn.y1, zLevel).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x1, middleY + btn.y1, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x1, middleY + btn.y2, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x2, middleY + btn.y2, blitOffset).color(r, g, b, a).endVertex();
buffer.pos(middleX + btn.x2, middleY + btn.y1, blitOffset).color(r, g, b, a).endVertex();
}
tessellator.draw();
@@ -279,7 +284,7 @@ public class RadialMenu extends Screen {
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.translatef(0f, 0f, 5f);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.color3f(1f, 1f, 1f);
GlStateManager.disableBlend();
GlStateManager.enableAlphaTest();
@@ -308,10 +313,10 @@ public class RadialMenu extends Screen {
final double v1 = 0;
final double v2 = 16;
buffer.pos(middleX + x1, middleY + y1, zLevel).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x1, middleY + y2, zLevel).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x2, middleY + y2, zLevel).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x2, middleY + y1, zLevel).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x1, middleY + y1, blitOffset).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x1, middleY + y2, blitOffset).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x2, middleY + y2, blitOffset).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + x2, middleY + y1, blitOffset).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
}
//Draw action icons
@@ -334,10 +339,10 @@ public class RadialMenu extends Screen {
final double btny1 = btnmiddleY - 8;
final double btny2 = btnmiddleY + 8;
buffer.pos(middleX + btnx1, middleY + btny1, zLevel).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx1, middleY + btny2, zLevel).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx2, middleY + btny2, zLevel).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx2, middleY + btny1, zLevel).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx1, middleY + btny1, blitOffset).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx1, middleY + btny2, blitOffset).tex(sprite.getInterpolatedU(u1), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx2, middleY + btny2, blitOffset).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v2)).color(f, f, f, a).endVertex();
buffer.pos(middleX + btnx2, middleY + btny1, blitOffset).tex(sprite.getInterpolatedU(u2), sprite.getInterpolatedV(v1)).color(f, f, f, a).endVertex();
}
tessellator.draw();
@@ -385,22 +390,22 @@ public class RadialMenu extends Screen {
//Add keybind in brackets
if (button.action == ActionEnum.UNDO) {
keybind = ClientProxy.keyBindings[4].getKey().getName();
keybind = ClientProxy.keyBindings[4].getLocalizedName();
}
if (button.action == ActionEnum.REDO) {
keybind = ClientProxy.keyBindings[5].getKey().getName();
keybind = ClientProxy.keyBindings[5].getLocalizedName();
}
if (button.action == ActionEnum.REPLACE) {
keybind = ClientProxy.keyBindings[1].getKey().getName();
keybind = ClientProxy.keyBindings[1].getLocalizedName();
}
if (button.action == ActionEnum.OPEN_MODIFIER_SETTINGS) {
keybind = ClientProxy.keyBindings[0].getKey().getName();
keybind = ClientProxy.keyBindings[0].getLocalizedName();
}
if (currentBuildMode.options.length > 0) {
//Add (ctrl) to first two actions of first option
if (button.action == currentBuildMode.options[0].actions[0]
|| button.action == currentBuildMode.options[0].actions[1]) {
keybind = ClientProxy.keyBindings[6].getKey().getName();
keybind = ClientProxy.keyBindings[6].getLocalizedName();
if (keybind.equals("Left Control")) keybind = "Ctrl";
}
}

View File

@@ -1,6 +1,7 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
@@ -31,8 +32,8 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
}
@Override
public int initGui(int id, List<Button> buttons) {
id = super.initGui(id, buttons);
public void init(List<Widget> buttons) {
super.init(buttons);
int y = top;
buttonArrayEnabled = new GuiCheckBox(left - 15 + 8, y, "", false) {
@@ -45,23 +46,23 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
buttons.add(buttonArrayEnabled);
y = top + 20;
textArrayOffsetX = new GuiNumberField(id++, id++, id++, font, buttons, left + 70, y, 50, 18);
textArrayOffsetX = new GuiNumberField(font, buttons, left + 70, y, 50, 18);
textArrayOffsetX.setNumber(0);
textArrayOffsetX.setTooltip("How much each copy is shifted.");
arrayNumberFieldList.add(textArrayOffsetX);
textArrayOffsetY = new GuiNumberField(id++, id++, id++, font, buttons, left + 140, y, 50, 18);
textArrayOffsetY = new GuiNumberField(font, buttons, left + 140, y, 50, 18);
textArrayOffsetY.setNumber(0);
textArrayOffsetY.setTooltip("How much each copy is shifted.");
arrayNumberFieldList.add(textArrayOffsetY);
textArrayOffsetZ = new GuiNumberField(id++, id++, id++, font, buttons, left + 210, y, 50, 18);
textArrayOffsetZ = new GuiNumberField(font, buttons, left + 210, y, 50, 18);
textArrayOffsetZ.setNumber(0);
textArrayOffsetZ.setTooltip("How much each copy is shifted.");
arrayNumberFieldList.add(textArrayOffsetZ);
y = top + 50;
textArrayCount = new GuiNumberField(id++, id++, id++, font, buttons, left + 55, y, 50, 18);
textArrayCount = new GuiNumberField(font, buttons, left + 55, y, 50, 18);
textArrayCount.setNumber(5);
textArrayCount.setTooltip("How many copies should be made.");
arrayNumberFieldList.add(textArrayCount);
@@ -77,8 +78,6 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
}
setCollapsed(!buttonArrayEnabled.isChecked());
return id;
}
public void updateScreen() {

View File

@@ -1,5 +1,6 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
@@ -41,8 +42,8 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
}
@Override
public int initGui(int id, List<Button> buttonList) {
id = super.initGui(id, buttonList);
public void init(List<Widget> buttonList) {
super.init(buttonList);
int y = top - 2;
buttonMirrorEnabled = new GuiCheckBox(left - 15 + 8, y, "", false) {
@@ -55,18 +56,18 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
buttonList.add(buttonMirrorEnabled);
y = top + 18;
textMirrorPosX = new GuiNumberField(id++, id++, id++, font, buttonList, left + 58, y, 62, 18);
textMirrorPosX = new GuiNumberField(font, buttonList, left + 58, y, 62, 18);
textMirrorPosX.setNumber(0);
textMirrorPosX.setTooltip(
Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosX);
textMirrorPosY = new GuiNumberField(id++, id++, id++, font, buttonList, left + 138, y, 62, 18);
textMirrorPosY = new GuiNumberField(font, buttonList, left + 138, y, 62, 18);
textMirrorPosY.setNumber(64);
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosY);
textMirrorPosZ = new GuiNumberField(id++, id++, id++, font, buttonList, left + 218, y, 62, 18);
textMirrorPosZ = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textMirrorPosZ.setNumber(0);
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
mirrorNumberFieldList.add(textMirrorPosZ);
@@ -82,7 +83,7 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
mirrorButtonList.add(buttonMirrorZ);
y = top + 47;
textMirrorRadius = new GuiNumberField(id++, id++, id++, font, buttonList, left + 218, y, 62, 18);
textMirrorRadius = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textMirrorRadius.setNumber(50);
//TODO change to diameter (remove /2)
textMirrorRadius.setTooltip(Arrays.asList("How far the mirror reaches in any direction.",
@@ -91,23 +92,16 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
mirrorNumberFieldList.add(textMirrorRadius);
y = top + 72;
buttonCurrentPosition = new GuiIconButton(id++, left + 5, y, 0, 0, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
Vec3d pos = new Vec3d(Math.floor(mc.player.posX) + 0.5, Math.floor(mc.player.posY) + 0.5, Math.floor(mc.player.posZ) + 0.5);
textMirrorPosX.setNumber(pos.x);
textMirrorPosY.setNumber(pos.y);
textMirrorPosZ.setNumber(pos.z);
}
};
});
buttonCurrentPosition.setTooltip("Set mirror position to current player position");
mirrorIconButtonList.add(buttonCurrentPosition);
buttonToggleOdd = new GuiIconButton(id++, left + 35, y, 0, 20, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
toggleOdd = !toggleOdd;
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
if (toggleOdd) {
@@ -121,32 +115,23 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
}
}
};
});
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
mirrorIconButtonList.add(buttonToggleOdd);
buttonDrawLines = new GuiIconButton(id++, left + 65, y, 0, 40, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
drawLines = !drawLines;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
}
};
});
buttonDrawLines.setTooltip("Show lines");
mirrorIconButtonList.add(buttonDrawLines);
buttonDrawPlanes = new GuiIconButton(id++, left + 95, y, 0, 60, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
drawPlanes = !drawPlanes;
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
}
};
});
buttonDrawPlanes.setTooltip("Show area");
mirrorIconButtonList.add(buttonDrawPlanes);
@@ -181,8 +166,6 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
buttonList.addAll(mirrorIconButtonList);
setCollapsed(!buttonMirrorEnabled.isChecked());
return id;
}
@Override

View File

@@ -3,6 +3,8 @@ package nl.requios.effortlessbuilding.gui.buildmodifier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import nl.requios.effortlessbuilding.EffortlessBuilding;
@@ -25,11 +27,13 @@ public class ModifierSettingsGui extends Screen {
private ArraySettingsGui arraySettingsGui;
private RadialMirrorSettingsGui radialMirrorSettingsGui;
public ModifierSettingsGui() {
super(new TranslationTextComponent("effortlessbuilding.screen.modifier_settings"));
}
@Override
//Create buttons and labels and add them to buttonList/labelList
public void initGui() {
int id = 0;
protected void init() {
scrollPane = new GuiScrollPane(this, font, 8, height - 30);
mirrorSettingsGui = new MirrorSettingsGui(scrollPane);
@@ -41,19 +45,14 @@ public class ModifierSettingsGui extends Screen {
radialMirrorSettingsGui = new RadialMirrorSettingsGui(scrollPane);
scrollPane.AddListEntry(radialMirrorSettingsGui);
id = scrollPane.initGui(id, buttons);
scrollPane.init(buttons);
//Close button
int y = height - 26;
buttonClose = new Button(width / 2 - 100, y, "Close") {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonClose = new Button(width / 2 - 100, y, 200, 20, "Close", (button) -> {
Minecraft.getInstance().player.closeScreen();
}
};
});
buttons.add(buttonClose);
}
@Override
@@ -68,9 +67,9 @@ public class ModifierSettingsGui extends Screen {
//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(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.renderBackground();
scrollPane.drawScreen(mouseX, mouseY, partialTicks);
scrollPane.render(mouseX, mouseY, partialTicks);
buttonClose.render(mouseX, mouseY, partialTicks);
@@ -83,7 +82,7 @@ public class ModifierSettingsGui extends Screen {
super.charTyped(typedChar, keyCode);
scrollPane.charTyped(typedChar, keyCode);
if (keyCode == ClientProxy.keyBindings[0].getKey().getKeyCode()) {
mc.player.closeScreen();
minecraft.player.closeScreen();
}
return false;
}
@@ -115,7 +114,7 @@ public class ModifierSettingsGui extends Screen {
}
@Override
public void onGuiClosed() {
public void onClose() {
scrollPane.onGuiClosed();
//save everything
@@ -123,17 +122,17 @@ public class ModifierSettingsGui extends Screen {
Array.ArraySettings a = arraySettingsGui.getArraySettings();
RadialMirror.RadialMirrorSettings r = radialMirrorSettingsGui.getRadialMirrorSettings();
ModifierSettingsManager.ModifierSettings modifierSettings = ModifierSettingsManager.getModifierSettings(mc.player);
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, mc.player);
if (!error.isEmpty()) EffortlessBuilding.log(mc.player, error);
String error = ModifierSettingsManager.sanitize(modifierSettings, minecraft.player);
if (!error.isEmpty()) EffortlessBuilding.log(minecraft.player, error);
ModifierSettingsManager.setModifierSettings(mc.player, modifierSettings);
ModifierSettingsManager.setModifierSettings(minecraft.player, modifierSettings);
//Send to server
PacketHandler.INSTANCE.sendToServer(new ModifierSettingsMessage(modifierSettings));

View File

@@ -1,5 +1,6 @@
package nl.requios.effortlessbuilding.gui.buildmodifier;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
@@ -41,8 +42,8 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
}
@Override
public int initGui(int id, List<Button> buttonList) {
id = super.initGui(id, buttonList);
public void init(List<Widget> buttonList) {
super.init(buttonList);
int y = top - 2;
buttonRadialMirrorEnabled = new GuiCheckBox(left - 15 + 8, y, "", false) {
@@ -55,29 +56,29 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
buttonList.add(buttonRadialMirrorEnabled);
y = top + 18;
textRadialMirrorPosX = new GuiNumberField(id++, id++, id++, font, buttonList, left + 58, y, 62, 18);
textRadialMirrorPosX = new GuiNumberField(font, buttonList, left + 58, y, 62, 18);
textRadialMirrorPosX.setNumber(0);
textRadialMirrorPosX.setTooltip(
Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
radialMirrorNumberFieldList.add(textRadialMirrorPosX);
textRadialMirrorPosY = new GuiNumberField(id++, id++, id++, font, buttonList, left + 138, y, 62, 18);
textRadialMirrorPosY = new GuiNumberField(font, buttonList, left + 138, y, 62, 18);
textRadialMirrorPosY.setNumber(64);
textRadialMirrorPosY.setTooltip(Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
radialMirrorNumberFieldList.add(textRadialMirrorPosY);
textRadialMirrorPosZ = new GuiNumberField(id++, id++, id++, font, buttonList, left + 218, y, 62, 18);
textRadialMirrorPosZ = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textRadialMirrorPosZ.setNumber(0);
textRadialMirrorPosZ.setTooltip(Arrays.asList("The position of the radial mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
radialMirrorNumberFieldList.add(textRadialMirrorPosZ);
y = top + 47;
textRadialMirrorSlices = new GuiNumberField(id++, id++, id++, font, buttonList, left + 55, y, 50, 18);
textRadialMirrorSlices = new GuiNumberField(font, buttonList, left + 55, y, 50, 18);
textRadialMirrorSlices.setNumber(4);
textRadialMirrorSlices.setTooltip(Arrays.asList("The number of repeating slices.", TextFormatting.GRAY + "Minimally 2."));
radialMirrorNumberFieldList.add(textRadialMirrorSlices);
textRadialMirrorRadius = new GuiNumberField(id++, id++, id++, font, buttonList, left + 218, y, 62, 18);
textRadialMirrorRadius = new GuiNumberField(font, buttonList, left + 218, y, 62, 18);
textRadialMirrorRadius.setNumber(50);
//TODO change to diameter (remove /2)
textRadialMirrorRadius.setTooltip(Arrays.asList("How far the radial mirror reaches from its center position.",
@@ -86,23 +87,16 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
radialMirrorNumberFieldList.add(textRadialMirrorRadius);
y = top + 72;
buttonCurrentPosition = new GuiIconButton(id++, left + 5, y, 0, 0, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonCurrentPosition = new GuiIconButton(left + 5, y, 0, 0, BUILDING_ICONS, button -> {
Vec3d pos = new Vec3d(Math.floor(mc.player.posX) + 0.5, Math.floor(mc.player.posY) + 0.5, Math.floor(mc.player.posZ) + 0.5);
textRadialMirrorPosX.setNumber(pos.x);
textRadialMirrorPosY.setNumber(pos.y);
textRadialMirrorPosZ.setNumber(pos.z);
}
};
});
buttonCurrentPosition.setTooltip("Set radial mirror position to current player position");
radialMirrorIconButtonList.add(buttonCurrentPosition);
buttonToggleOdd = new GuiIconButton(id++, left + 35, y, 0, 20, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonToggleOdd = new GuiIconButton(left + 35, y, 0, 20, BUILDING_ICONS, button -> {
toggleOdd = !toggleOdd;
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
if (toggleOdd) {
@@ -116,32 +110,23 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
textRadialMirrorPosY.setNumber(Math.floor(textRadialMirrorPosY.getNumber()));
textRadialMirrorPosZ.setNumber(Math.floor(textRadialMirrorPosZ.getNumber()));
}
}
};
});
buttonToggleOdd.setTooltip(Arrays.asList("Set radial mirror position to middle of block", "for odd numbered builds"));
radialMirrorIconButtonList.add(buttonToggleOdd);
buttonDrawLines = new GuiIconButton(id++, left + 65, y, 0, 40, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonDrawLines = new GuiIconButton(left + 65, y, 0, 40, BUILDING_ICONS, button -> {
drawLines = !drawLines;
buttonDrawLines.setUseAlternateIcon(drawLines);
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
}
};
});
buttonDrawLines.setTooltip("Show lines");
radialMirrorIconButtonList.add(buttonDrawLines);
buttonDrawPlanes = new GuiIconButton(id++, left + 95, y, 0, 60, BUILDING_ICONS) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
buttonDrawPlanes = new GuiIconButton(left + 95, y, 0, 60, BUILDING_ICONS, button -> {
drawPlanes = !drawPlanes;
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
}
};
});
buttonDrawPlanes.setTooltip("Show area");
radialMirrorIconButtonList.add(buttonDrawPlanes);
@@ -179,8 +164,6 @@ public class RadialMirrorSettingsGui extends GuiCollapsibleScrollEntry {
buttonList.addAll(radialMirrorIconButtonList);
setCollapsed(!buttonRadialMirrorEnabled.isChecked());
return id;
}
public void updateScreen() {

View File

@@ -2,7 +2,7 @@ package nl.requios.effortlessbuilding.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.font;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.api.distmarker.Dist;
@@ -27,14 +27,11 @@ public abstract class GuiCollapsibleScrollEntry implements GuiScrollPane.IScroll
}
@Override
public int initGui(int id, List<Button> buttonList) {
left = scrollPane.width / 2 - 140;
right = scrollPane.width / 2 + 140;
top = scrollPane.height / 2 - 100;
bottom = scrollPane.height / 2 + 100;
return id;
public void init(List<Widget> buttonList) {
left = scrollPane.getWidth() / 2 - 140;
right = scrollPane.getWidth() / 2 + 140;
top = scrollPane.getHeight() / 2 - 100;
bottom = scrollPane.getHeight() / 2 + 100;
}
@Override

View File

@@ -19,12 +19,12 @@ public class GuiIconButton extends Button {
List<String> tooltip = new ArrayList<>();
private boolean useAltIcon = false;
public GuiIconButton(int buttonId, int x, int y, int iconX, int iconY, ResourceLocation resourceLocation) {
this(buttonId, x, y, 20, 20, iconX, iconY, 20, 20, 20, 0, resourceLocation);
public GuiIconButton(int x, int y, int iconX, int iconY, ResourceLocation resourceLocation, Button.IPressable onPress) {
this(x, y, 20, 20, iconX, iconY, 20, 20, 20, 0, resourceLocation, onPress);
}
public GuiIconButton(int buttonId, int x, int y, int width, int height, int iconX, int iconY, int iconWidth, int iconHeight, int iconAltX, int iconAltY, ResourceLocation resourceLocation) {
super(buttonId, x, y, width, height, "");
public GuiIconButton(int x, int y, int width, int height, int iconX, int iconY, int iconWidth, int iconHeight, int iconAltX, int iconAltY, ResourceLocation resourceLocation, Button.IPressable onPress) {
super(x, y, width, height, "", onPress);
this.iconX = iconX;
this.iconY = iconY;
this.iconWidth = iconWidth;
@@ -51,7 +51,7 @@ public class GuiIconButton extends Button {
super.render(mouseX, mouseY, partialTicks);
if (this.visible)
{
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
Minecraft.getInstance().getTextureManager().bindTexture(this.resourceLocation);
int currentIconX = this.iconX;
int currentIconY = this.iconY;
@@ -62,17 +62,18 @@ public class GuiIconButton extends Button {
currentIconY += iconAltY;
}
this.drawTexturedModalRect(this.x, this.y, currentIconX, currentIconY, this.iconWidth, this.iconHeight);
//Draws a textured rectangle at the current z-value. Used to be drawTexturedModalRect in Gui.
this.blit(this.x, this.y, currentIconX, currentIconY, this.iconWidth, this.iconHeight);
}
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(Screen screen, int mouseX, int mouseY) {
boolean flag = mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height;
if (flag) {
List<String> textLines = new ArrayList<>();
textLines.addAll(tooltip);
guiScreen.drawHoveringText(textLines, mouseX - 10, mouseY + 25);
screen.renderTooltip(textLines, mouseX - 10, mouseY + 25);
}
}
}

View File

@@ -3,6 +3,7 @@ package nl.requios.effortlessbuilding.gui.elements;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;
@@ -25,34 +26,27 @@ public class GuiNumberField extends AbstractGui {
List<String> tooltip = new ArrayList<>();
public GuiNumberField(int id1, int id2, int id3, FontRenderer font,
List<Button> buttonList, int x, int y, int width, int height) {
public GuiNumberField(FontRenderer font, List<Widget> buttonList, int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
textField = new TextFieldWidget(id1, font, x + buttonWidth + 1, y + 1, width - 2 * buttonWidth - 2, height - 2);
minusButton = new Button(id2, x, y - 1, buttonWidth, height + 2, "-") {
@Override
public void onClick(double mouseX, double mouseY) {
textField = new TextFieldWidget(font, x + buttonWidth + 1, y + 1, width - 2 * buttonWidth - 2, height - 2, "");
minusButton = new Button(x, y - 1, buttonWidth, height + 2, "-", button -> {
float valueChanged = 1f;
if (Screen.isCtrlKeyDown()) valueChanged = 5f;
if (Screen.isShiftKeyDown()) valueChanged = 10f;
if (Screen.hasControlDown()) valueChanged = 5f;
if (Screen.hasShiftDown()) valueChanged = 10f;
setNumber(getNumber() - valueChanged);
}
};
plusButton = new Button(id3, x + width - buttonWidth, y - 1, buttonWidth, height + 2, "+") {
@Override
public void onClick(double mouseX, double mouseY) {
});
plusButton = new Button(x + width - buttonWidth, y - 1, buttonWidth, height + 2, "+", button -> {
float valueChanged = 1f;
if (Screen.isCtrlKeyDown()) valueChanged = 5f;
if (Screen.isShiftKeyDown()) valueChanged = 10f;
if (Screen.hasControlDown()) valueChanged = 5f;
if (Screen.hasShiftDown()) valueChanged = 10f;
setNumber(getNumber() + valueChanged);
}
};
});
buttonList.add(minusButton);
buttonList.add(plusButton);
@@ -88,7 +82,7 @@ public class GuiNumberField extends AbstractGui {
//Rightclicked inside textfield
if (flag && mouseButton == 1) {
textField.setText("");
textField.setFocused(true);
textField.setFocused2(true);
result = true;
}
@@ -100,12 +94,12 @@ public class GuiNumberField extends AbstractGui {
minusButton.y = y - 1;
plusButton.y = y - 1;
textField.drawTextField(mouseX, mouseY, partialTicks);
textField.render(mouseX, mouseY, partialTicks);
minusButton.render(mouseX, mouseY, partialTicks);
plusButton.render(mouseX, mouseY, partialTicks);
}
public void drawTooltip(Screen guiScreen, int mouseX, int mouseY) {
public void drawTooltip(Screen screen, int mouseX, int mouseY) {
boolean insideTextField = mouseX >= x + buttonWidth && mouseX < x + width - buttonWidth && mouseY >= y && mouseY < y + height;
boolean insideMinusButton = mouseX >= x && mouseX < x + buttonWidth && mouseY >= y && mouseY < y + height;
boolean insidePlusButton = mouseX >= x + width - buttonWidth && mouseX < x + width && mouseY >= y && mouseY < y + height;
@@ -128,7 +122,7 @@ public class GuiNumberField extends AbstractGui {
textLines.add("Hold " + TextFormatting.AQUA + "ctrl " + TextFormatting.RESET + "for " + TextFormatting.DARK_GREEN + "5");
}
guiScreen.drawHoveringText(textLines, mouseX - 10, mouseY + 25);
screen.renderTooltip(textLines, mouseX - 10, mouseY + 25);
}

View File

@@ -4,19 +4,15 @@ import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.ArrayList;
import java.util.List;
@@ -50,131 +46,110 @@ public class GuiScrollPane extends SlotGui {
}
@Override
protected int getSize() {
protected int getItemCount() {
return listEntries.size();
}
@Override
protected boolean isSelected(int slotIndex) {
protected boolean isSelectedItem(int slotIndex) {
return false;
}
@Override
protected int getScrollBarX() {
protected int getScrollbarPosition() {
//return width / 2 + 140 + 10;
return width - 15;
}
@Override
public int getListWidth() {
public int getRowWidth() {
return 280;
}
//Removed background
@Override
public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks)
{
if (this.visible)
public void render(int mouseXIn, int mouseYIn, float partialTicks)
{
if (this.visible) {
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
int scrollBarLeft = this.getScrollBarX();
int scrollBarRight = scrollBarLeft + 6;
this.bindAmountScrolled();
this.renderBackground();
int scrollbarLeft = this.getScrollbarPosition();
int scrollbarRight = scrollbarLeft + 6;
this.capYPosition();
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
int insideLeft = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int insideTop = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader) {
this.drawListHeader(insideLeft, insideTop, tessellator);
int insideLeft = this.x0 + this.width / 2 - this.getRowWidth() / 2 + 2;
int insideTop = this.y0 + 4 - (int) this.yo;
if (this.renderHeader) {
this.renderHeader(insideLeft, insideTop, tessellator);
}
//All entries
this.drawSelectionBox(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks);
this.renderList(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks);
GlStateManager.disableDepthTest();
//Dirt overlays on top and bottom
// this.overlayBackground(0, this.top, 255, 255);
// this.overlayBackground(this.bottom, this.height, 255, 255);
// this.renderHoleBackground(0, this.y0, 255, 255);
// this.renderHoleBackground(this.y1, this.height, 255, 255);
GlStateManager.enableBlend();
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
GlStateManager.disableAlphaTest();
GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
// //top fade
//top
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex();
// bufferbuilder.pos((double)this.right, (double)(this.top + 5), 0.0D).tex(1.0D, 1.0D).color(100, 100, 100, 0).endVertex();
// bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex();
// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex();
// bufferbuilder.pos((double)this.x0, (double)(this.y0 + 4), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
// bufferbuilder.pos((double)this.x1, (double)(this.y0 + 4), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
// bufferbuilder.pos((double)this.x1, (double)this.y0, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
// bufferbuilder.pos((double)this.x0, (double)this.y0, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
// tessellator.draw();
// //top line
//bottom
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// tessellator.draw();
// //bottom fade
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex();
// bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(10, 10, 10, 100).endVertex();
// bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex();
// bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex();
// tessellator.draw();
// //bottom line
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
// bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.right, (double)(this.bottom + 1), 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex();
// bufferbuilder.pos((double)this.x0, (double)this.y1, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
// bufferbuilder.pos((double)this.x1, (double)this.y1, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
// bufferbuilder.pos((double)this.x1, (double)(this.y1 - 4), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
// bufferbuilder.pos((double)this.x0, (double)(this.y1 - 4), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
// tessellator.draw();
//Draw scrollbar
int maxScroll = this.getMaxScroll();
if (maxScroll > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = MathHelper.clamp(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / maxScroll + this.top;
if (l1 < this.top)
{
l1 = this.top;
if (maxScroll > 0) {
int k1 = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) / (float) this.getMaxPosition());
k1 = MathHelper.clamp(k1, 32, this.y1 - this.y0 - 8);
int l1 = (int) this.yo * (this.y1 - this.y0 - k1) / maxScroll + this.y0;
if (l1 < this.y0) {
l1 = this.y0;
}
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)scrollBarLeft, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)scrollBarLeft, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) this.y1, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) this.y1, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) this.y0, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) this.y0, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarRight, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) (l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) (l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarRight, (double) l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(scrollBarRight - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(scrollBarRight - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) (l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) (scrollbarRight - 1), (double) (l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) (scrollbarRight - 1), (double) l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double) scrollbarLeft, (double) l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.shadeModel(7424);
GlStateManager.enableAlphaTest();
GlStateManager.disableBlend();
@@ -184,9 +159,9 @@ public class GuiScrollPane extends SlotGui {
//SLOTHEIGHT MODIFICATIONS
//SlotHeight is still relied on for determining how much to scroll
@Override
protected int getContentHeight() {
protected int getMaxPosition() {
//Add every entry height
int height = this.headerPadding;
int height = this.headerHeight;
for (IScrollEntry entry : listEntries) {
height += entry.getHeight();
}
@@ -194,19 +169,19 @@ public class GuiScrollPane extends SlotGui {
}
@Override
protected void drawBackground() {
protected void renderBackground() {
}
@Override
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks) {
this.getListEntry(slotIndex).drawEntry(slotIndex, xPos, yPos, this.getListWidth(), heightIn, mouseXIn, mouseYIn,
protected void renderItem(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks) {
this.getListEntry(slotIndex).drawEntry(slotIndex, xPos, yPos, this.getRowWidth(), heightIn, mouseXIn, mouseYIn,
this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == slotIndex, partialTicks);
}
public int getContentHeight(int count) {
public int getMaxPosition(int count) {
//Add all count entry heights
int height = this.headerPadding;
int height = this.headerHeight;
for (int i = 0; i < count; i++) {
IScrollEntry entry = listEntries.get(i);
height += entry.getHeight();
@@ -215,23 +190,23 @@ public class GuiScrollPane extends SlotGui {
}
public int getSlotIndexFromScreenCoords(double posX, double posY) {
int left = this.left + (this.width - this.getListWidth()) / 2;
int right = this.left + (this.width + this.getListWidth()) / 2;
int left = this.x0 + (this.width - this.getRowWidth()) / 2;
int right = this.x0 + (this.width + this.getRowWidth()) / 2;
double relativeMouseY = getRelativeMouseY(mouseY, 0);
//Iterate over every entry until relativeMouseY falls within its height
for (int i = 0; i < listEntries.size(); i++) {
IScrollEntry entry = listEntries.get(i);
if (relativeMouseY <= entry.getHeight())
return posX < this.getScrollBarX() && posX >= left && posX <= right && i >= 0 &&
relativeMouseY >= 0 && i < this.getSize() ? i : -1;
return posX < this.getScrollbarPosition() && posX >= left && posX <= right && i >= 0 &&
relativeMouseY >= 0 && i < this.getItemCount() ? i : -1;
relativeMouseY -= entry.getHeight();
}
return -1;
}
@Override
protected boolean mouseClicked(int index, int button, double mouseX, double mouseY) {
public boolean mouseClicked(double mouseX, double mouseY, int button) {
int selectedSlot = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
double relativeX = getRelativeMouseX(mouseX);
@@ -263,12 +238,12 @@ public class GuiScrollPane extends SlotGui {
}
@Override
public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_) {
for (int i = 0; i < this.getSize(); ++i)
public boolean mouseReleased(double mouseX, double mouseY, int button) {
for (int i = 0; i < this.getItemCount(); ++i)
{
double relativeX = getRelativeMouseX(mouseX);
double relativeY = getRelativeMouseY(mouseY, i);
this.getListEntry(i).mouseReleased(i, (int) p_mouseReleased_1_, (int) p_mouseReleased_3_, p_mouseReleased_5_, (int) relativeX, (int) relativeY);
this.getListEntry(i).mouseReleased(i, (int) mouseX, (int) mouseY, button, (int) relativeX, (int) relativeY);
}
this.visible = true;
@@ -277,45 +252,39 @@ public class GuiScrollPane extends SlotGui {
public void handleMouseInput() {
if (this.isMouseInList(this.mouseX, this.mouseY)) {
if (mc.mouseHelper.isLeftDown() && this.mouseY >= this.top &&
this.mouseY <= this.bottom) {
int i = this.left + (this.width - this.getListWidth()) / 2;
int j = this.left + (this.width + this.getListWidth()) / 2;
if (minecraft.mouseHelper.isLeftDown() && this.mouseY >= this.y0 &&
this.mouseY <= this.y1) {
int i = this.x0 + (this.width - this.getRowWidth()) / 2;
int j = this.x0 + (this.width + this.getRowWidth()) / 2;
int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY);
double relativeMouseY = getRelativeMouseY(mouseY, slotIndex);
if (slotIndex > -1) {
this.mouseClicked(slotIndex, 0, this.mouseX, this.mouseY);
this.selectedElement = slotIndex;
this.mouseClicked(this.mouseX, this.mouseY, 0);
} else if (this.mouseX >= i && this.mouseX <= j && relativeMouseY < 0) {
this.clickedHeader(this.mouseX - i, this.mouseY - this.top + (int) this.amountScrolled - 4);
this.clickedHeader(this.mouseX - i, this.mouseY - this.y0 + (int) this.yo - 4);
}
}
if (mc.mouseHelper.isLeftDown() && this.isVisible()) {
if (this.initialClickY == -1) {
if (minecraft.mouseHelper.isLeftDown() && this.isVisible()) {
if (this.yDrag == -1) {
boolean flag1 = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom) {
int i2 = this.left + (this.width - this.getListWidth()) / 2;
int j2 = this.left + (this.width + this.getListWidth()) / 2;
if (this.mouseY >= this.y0 && this.mouseY <= this.y1) {
int i2 = this.x0 + (this.width - this.getRowWidth()) / 2;
int j2 = this.x0 + (this.width + this.getRowWidth()) / 2;
int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY);
double relativeMouseY = getRelativeMouseY(mouseY, slotIndex);
if (slotIndex > -1) {
//TODO 1.13 use flag
boolean flag = slotIndex == this.selectedElement &&
Util.milliTime() - this.lastClicked < 250L;
this.mouseClicked(slotIndex, this.mouseX, this.mouseY);
this.selectedElement = slotIndex;
this.lastClicked = Util.milliTime();
} else if (this.mouseX >= i2 && this.mouseX <= j2 && relativeMouseY < 0) {
this.clickedHeader(this.mouseX - i2,
this.mouseY - this.top + (int) this.amountScrolled - 4);
this.mouseY - this.y0 + (int) this.yo - 4);
flag1 = false;
}
int i3 = this.getScrollBarX();
int i3 = this.getScrollbarPosition();
int j1 = i3 + 6;
if (this.mouseX >= i3 && this.mouseX <= j1) {
@@ -326,60 +295,45 @@ public class GuiScrollPane extends SlotGui {
maxScroll = 1;
}
int l1 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) /
(float) this.getContentHeight());
l1 = MathHelper.clamp(l1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float) (this.bottom - this.top - l1) / (float) maxScroll;
int l1 = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) /
(float) this.getMaxPosition());
l1 = MathHelper.clamp(l1, 32, this.y1 - this.y0 - 8);
this.scrollMultiplier /= (float) (this.y1 - this.y0 - l1) / (float) maxScroll;
} else {
this.scrollMultiplier = 1.0F;
}
if (flag1) {
this.initialClickY = this.mouseY;
this.yDrag = this.mouseY;
} else {
this.initialClickY = -2;
this.yDrag = -2;
}
} else {
this.initialClickY = -2;
this.yDrag = -2;
}
} else if (this.initialClickY >= 0) {
this.amountScrolled -= (float) (this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = this.mouseY;
} else if (this.yDrag >= 0) {
this.yo -= (float) (this.mouseY - this.yDrag) * this.scrollMultiplier;
this.yDrag = this.mouseY;
}
} else {
this.initialClickY = -1;
this.yDrag = -1;
}
}
}
//Through forge event instead of through the parent, because the parent no longer has scroll functionality in 1.13
@SubscribeEvent
public void mouseScrolled(GuiScreenEvent.MouseScrollEvent.Pre event) {
double scrollDelta = event.getScrollDelta();
if (scrollDelta != 0) {
if (scrollDelta > 0) {
scrollDelta = -1;
} else if (scrollDelta < 0) {
scrollDelta = 1;
}
this.amountScrolled += (float) (scrollDelta * this.slotHeight / 2);
}
}
//Draw in center if it fits
@Override
protected void drawSelectionBox(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks)
protected void renderList(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks)
{
int size = this.getSize();
int itemCount = this.getItemCount();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
//Find y to start with
int y = this.headerPadding + insideTop;
int contentHeight = getContentHeight();
int insideHeight = this.bottom - this.top - 4;
int y = this.headerHeight + insideTop;
int contentHeight = getMaxPosition();
int insideHeight = this.y1 - this.y0 - 4;
if (contentHeight < insideHeight) {
//it fits, so we can center it vertically
@@ -387,66 +341,68 @@ public class GuiScrollPane extends SlotGui {
}
//Draw all entries
for (int i = 0; i < size; ++i)
for (int i = 0; i < itemCount; ++i)
{
int entryHeight = listEntries.get(i).getHeight();
int entryHeight2 = entryHeight - 4;
if (y > this.bottom || y + entryHeight2 < this.top)
if (y > this.y1 || y + entryHeight2 < this.y0)
{
this.updateItemPos(i, insideLeft, y, partialTicks);
this.updateItemPosition(i, insideLeft, y, partialTicks);
}
if (this.showSelectionBox && this.isSelected(i))
{
int i1 = this.left + this.width / 2 - this.getListWidth() / 2;
int j1 = this.left + this.width / 2 + this.getListWidth() / 2;
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i1, (double)(y + entryHeight2 + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j1, (double)(y + entryHeight2 + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j1, (double)(y - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)i1, (double)(y - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(y + entryHeight2 + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y + entryHeight2 + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(y - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
if (this.renderSelection && this.isSelectedItem(i)) {
int i1 = this.x0 + this.width / 2 - this.getRowWidth() / 2;
int j1 = this.x0 + this.width / 2 + this.getRowWidth() / 2;
GlStateManager.disableTexture();
float f = this.isFocused() ? 1.0F : 0.5F;
GlStateManager.color4f(f, f, f, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)i1, (double)(y + entryHeight2 + 2), 0.0D).endVertex();
bufferbuilder.pos((double)j1, (double)(y + entryHeight2 + 2), 0.0D).endVertex();
bufferbuilder.pos((double)j1, (double)(y - 2), 0.0D).endVertex();
bufferbuilder.pos((double)i1, (double)(y - 2), 0.0D).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.color4f(0.0F, 0.0F, 0.0F, 1.0F);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)(i1 + 1), (double)(y + entryHeight2 + 1), 0.0D).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y + entryHeight2 + 1), 0.0D).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(y - 1), 0.0D).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(y - 1), 0.0D).endVertex();
tessellator.draw();
GlStateManager.enableTexture();
}
this.drawSlot(i, insideLeft, y, entryHeight2, mouseXIn, mouseYIn, partialTicks);
this.renderItem(i, insideLeft, y, entryHeight2, mouseXIn, mouseYIn, partialTicks);
y += entryHeight;
}
}
private double getRelativeMouseX(double mouseX) {
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int j = this.x0 + this.width / 2 - this.getRowWidth() / 2 + 2;
return mouseX - j;
}
private double getRelativeMouseY(double mouseY, int contentIndex) {
int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(contentIndex) + this.headerPadding;
int k = this.y0 + 4 - this.getScroll() + getMaxPosition(contentIndex) + this.headerHeight;
double relativeMouseY = mouseY - k;
//Content might be centered, adjust relative mouse y accordingly
int contentHeight = getContentHeight();
int insideHeight = this.bottom - this.top - 4;
int contentHeight = getMaxPosition();
int insideHeight = this.y1 - this.y0 - 4;
if (contentHeight < insideHeight) {
//it fits, so we can center it vertically
relativeMouseY -= (insideHeight - contentHeight) / 2;
relativeMouseY -= (insideHeight - contentHeight) / 2f;
}
return relativeMouseY;
}
//PASSTHROUGHS
public int initGui(int id, List<Button> buttonList) {
public void init(List<Widget> buttonList) {
for (IScrollEntry entry : this.listEntries) {
id = entry.initGui(id, buttonList);
entry.init(buttonList);
}
return id;
}
public void updateScreen() {
@@ -471,8 +427,17 @@ public class GuiScrollPane extends SlotGui {
entry.onGuiClosed();
}
//Make protected values available
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public interface IScrollEntry {
int initGui(int id, List<Button> buttonList);
void init(List<Widget> buttonList);
void updateScreen();

View File

@@ -55,8 +55,8 @@ import java.util.function.Supplier;
@Mod.EventBusSubscriber(value = {Dist.CLIENT})
public class ClientProxy implements IProxy {
public static KeyBinding[] keyBindings;
public static BlockRayTraceResult previousLookAt;
public static BlockRayTraceResult currentLookAt;
public static RayTraceResult previousLookAt;
public static RayTraceResult currentLookAt;
private static int placeCooldown = 0;
private static int breakCooldown = 0;
private static boolean shadersInitialized = false;
@@ -83,10 +83,10 @@ public class ClientProxy implements IProxy {
keyBindings[2] = new KeyBinding("key.effortlessbuilding.creative.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_F4, 0), "key.effortlessbuilding.category");
keyBindings[3] = new KeyBinding("key.effortlessbuilding.mode.desc", KeyConflictContext.IN_GAME, InputMappings.getInputByCode(GLFW.GLFW_KEY_LEFT_ALT, 0), "key.effortlessbuilding.category") {
@Override
public boolean func_197983_b(KeyBinding other) {
public boolean conflicts(KeyBinding other) {
//Does not conflict with Chisels and Bits radial menu
if (other.getKey().getKeyCode() == getKey().getKeyCode() && other.getKeyDescription().equals("mod.chiselsandbits.other.mode")) return false;
return super.func_197983_b(other);
return super.conflicts(other);
}
};
keyBindings[4] = new KeyBinding("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputMappings.getInputByCode(GLFW.GLFW_KEY_Z, 0), "key.effortlessbuilding.category");
@@ -105,29 +105,20 @@ public class ClientProxy implements IProxy {
return (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT ? Minecraft.getInstance().player : ctx.get().getSender());
}
@SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() == Minecraft.getInstance().player) {
event.getWorld().addEventListener(new RenderHandler());
}
}
@SubscribeEvent
public static void onTextureStitch(final TextureStitchEvent.Pre event) {
//register icon textures
final AtlasTexture map = event.getMap();
for ( final BuildModes.BuildModeEnum mode : BuildModes.BuildModeEnum.values() )
{
final ResourceLocation sprite = new ResourceLocation(EffortlessBuilding.MODID, "icons/" + mode.name().toLowerCase());
map.registerSprite(Minecraft.getInstance().getResourceManager(), sprite);
event.addSprite(sprite);
buildModeIcons.put(mode, sprite);
}
for ( final ModeOptions.ActionEnum action : ModeOptions.ActionEnum.values() )
{
final ResourceLocation sprite = new ResourceLocation(EffortlessBuilding.MODID, "icons/" + action.name().toLowerCase());
map.registerSprite(Minecraft.getInstance().getResourceManager(), sprite);
event.addSprite(sprite);
modeOptionIcons.put(action, sprite);
}
}
@@ -162,7 +153,7 @@ public class ClientProxy implements IProxy {
currentLookAt = objectMouseOver;
previousLookAt = objectMouseOver;
} else {
if (currentLookAt.getPos() != objectMouseOver.getPos()) {
if (((BlockRayTraceResult) currentLookAt).getPos() != ((BlockRayTraceResult) objectMouseOver).getPos()) {
previousLookAt = currentLookAt;
currentLookAt = objectMouseOver;
}
@@ -210,22 +201,28 @@ public class ClientProxy implements IProxy {
ItemStack itemStack = CompatHelper.getItemBlockFromStack(currentItemStack);
//find position in distance
BlockRayTraceResult lookingAt = getLookingAt(player);
BuildModes.onBlockPlacedMessage(player, lookingAt == null ? new BlockPlacedMessage() : new BlockPlacedMessage(lookingAt, true));
PacketHandler.INSTANCE.sendToServer(lookingAt == null ? new BlockPlacedMessage() : new BlockPlacedMessage(lookingAt, true));
RayTraceResult lookingAt = getLookingAt(player);
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK) {
BlockRayTraceResult blockLookingAt = (BlockRayTraceResult) lookingAt;
BuildModes.onBlockPlacedMessage(player, new BlockPlacedMessage(blockLookingAt, true));
PacketHandler.INSTANCE.sendToServer(new BlockPlacedMessage(blockLookingAt, true));
//play sound if further than normal
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK &&
(lookingAt.getHitVec().subtract(player.getEyePosition(1f))).lengthSquared() > 25f &&
if ((blockLookingAt.getHitVec().subtract(player.getEyePosition(1f))).lengthSquared() > 25f &&
itemStack.getItem() instanceof BlockItem) {
BlockState state = ((BlockItem) itemStack.getItem()).getBlock().getDefaultState();
BlockPos blockPos = lookingAt.getPos();
BlockPos blockPos = blockLookingAt.getPos();
SoundType soundType = state.getBlock().getSoundType(state, player.world, blockPos, player);
player.world.playSound(player, player.getPosition(), soundType.getPlaceSound(), SoundCategory.BLOCKS,
0.4f, soundType.getPitch() * 1f);
player.swingArm(Hand.MAIN_HAND);
}
} else {
BuildModes.onBlockPlacedMessage(player, new BlockPlacedMessage());
PacketHandler.INSTANCE.sendToServer(new BlockPlacedMessage());
}
}
}
else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
@@ -248,21 +245,27 @@ public class ClientProxy implements IProxy {
// moving it to after buildmodes fixes that, but introduces this bug
if (!ReachHelper.canBreakFar(player)) return;
BlockRayTraceResult lookingAt = getLookingAt(player);
BuildModes.onBlockBrokenMessage(player, lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt));
PacketHandler.INSTANCE.sendToServer(lookingAt == null ? new BlockBrokenMessage() : new BlockBrokenMessage(lookingAt));
RayTraceResult lookingAt = getLookingAt(player);
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK) {
BlockRayTraceResult blockLookingAt = (BlockRayTraceResult) lookingAt;
BuildModes.onBlockBrokenMessage(player, new BlockBrokenMessage(blockLookingAt));
PacketHandler.INSTANCE.sendToServer(new BlockBrokenMessage(blockLookingAt));
//play sound if further than normal
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK &&
(lookingAt.getHitVec().subtract(player.getEyePosition(1f))).lengthSquared() > 25f) {
if ((blockLookingAt.getHitVec().subtract(player.getEyePosition(1f))).lengthSquared() > 25f) {
BlockPos blockPos = lookingAt.getPos();
BlockPos blockPos = blockLookingAt.getPos();
BlockState state = player.world.getBlockState(blockPos);
SoundType soundtype = state.getBlock().getSoundType(state, player.world, blockPos, player);
player.world.playSound(player, player.getPosition(), soundtype.getBreakSound(), SoundCategory.BLOCKS,
0.4f, soundtype.getPitch() * 1f);
player.swingArm(Hand.MAIN_HAND);
}
} else {
BuildModes.onBlockBrokenMessage(player, new BlockBrokenMessage());
PacketHandler.INSTANCE.sendToServer(new BlockBrokenMessage());
}
}
else if (buildMode == BuildModes.BuildModeEnum.NORMAL_PLUS) {
breakCooldown--;
@@ -371,7 +374,7 @@ public class ClientProxy implements IProxy {
}
@Nullable
public static BlockRayTraceResult getLookingAt(PlayerEntity player) {
public static RayTraceResult getLookingAt(PlayerEntity player) {
World world = player.world;
//base distance off of player ability (config)
@@ -381,7 +384,7 @@ public class ClientProxy implements IProxy {
Vec3d start = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
Vec3d end = new Vec3d(player.posX + look.x * raytraceRange, player.posY + player.getEyeHeight() + look.y * raytraceRange, player.posZ + look.z * raytraceRange);
// return player.rayTrace(raytraceRange, 1f, RayTraceFluidMode.NEVER);
//TODO 1.14 check if correct, make sure it is a blockraytraceresult
//TODO 1.14 check if correct
return world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player));
}

View File

@@ -95,7 +95,7 @@ public class BlockPreviewRenderer {
});
//Render block previews
BlockRayTraceResult lookingAt = ClientProxy.getLookingAt(player);
RayTraceResult lookingAt = ClientProxy.getLookingAt(player);
if (modeSettings.getBuildMode() == BuildModes.BuildModeEnum.NORMAL) lookingAt = Minecraft.getInstance().objectMouseOver;
ItemStack mainhand = player.getHeldItemMainhand();
@@ -107,14 +107,15 @@ public class BlockPreviewRenderer {
//Checking for null is necessary! Even in vanilla when looking down ladders it is occasionally null (instead of Type MISS)
if (lookingAt != null && lookingAt.getType() == RayTraceResult.Type.BLOCK) {
startPos = lookingAt.getPos();
BlockRayTraceResult blockLookingAt = (BlockRayTraceResult) lookingAt;
startPos = blockLookingAt.getPos();
//Check if tool (or none) in hand
//TODO 1.13 replaceable
boolean replaceable = player.world.getBlockState(startPos).getBlock().getMaterial(player.world.getBlockState(startPos)).isReplaceable();
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, lookingAt.getFace());
boolean becomesDoubleSlab = SurvivalHelper.doesBecomeDoubleSlab(player, startPos, blockLookingAt.getFace());
if (!modifierSettings.doQuickReplace() && !toolInHand && !replaceable && !becomesDoubleSlab) {
startPos = startPos.offset(lookingAt.getFace());
startPos = startPos.offset(blockLookingAt.getFace());
}
//Get under tall grass and other replaceable blocks
@@ -122,8 +123,8 @@ public class BlockPreviewRenderer {
startPos = startPos.down();
}
sideHit = lookingAt.getFace();
hitVec = lookingAt.getHitVec();
sideHit = blockLookingAt.getFace();
hitVec = blockLookingAt.getHitVec();
}
//Dont render if in normal mode and modifiers are disabled
@@ -265,10 +266,11 @@ public class BlockPreviewRenderer {
RenderHandler.beginLines();
//Draw outlines if tool in hand
//Find proper raytrace: either normal range or increased range depending on canBreakFar
BlockRayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver;
BlockRayTraceResult breakingRaytrace = ReachHelper.canBreakFar(player) ? lookingAt : objectMouseOver;
RayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver;
RayTraceResult breakingRaytrace = ReachHelper.canBreakFar(player) ? lookingAt : objectMouseOver;
if (toolInHand && breakingRaytrace != null && breakingRaytrace.getType() == RayTraceResult.Type.BLOCK) {
List<BlockPos> breakCoordinates = BuildModifiers.findCoordinates(player, breakingRaytrace.getPos());
BlockRayTraceResult blockBreakingRaytrace = (BlockRayTraceResult) breakingRaytrace;
List<BlockPos> breakCoordinates = BuildModifiers.findCoordinates(player, blockBreakingRaytrace.getPos());
//Only render first outline if further than normal reach
boolean excludeFirst = objectMouseOver != null && objectMouseOver.getType() == RayTraceResult.Type.BLOCK;

View File

@@ -1,4 +1,8 @@
{
"effortlessbuilding.screen.modifier_settings": "Modifier Settings",
"effortlessbuilding.screen.radial_menu": "Build Modes",
"effortlessbuilding.screen.randomizer_bag": "Randomizer Bag",
"key.effortlessbuilding.category": "Effortless Building",
"key.effortlessbuilding.hud.desc": "Modifier Menu",
"key.effortlessbuilding.replace.desc": "Toggle QuickReplace",