Skip to content

Commit

Permalink
Fixed everything
Browse files Browse the repository at this point in the history
  • Loading branch information
MineDragonCZ committed Jul 14, 2023
1 parent 8856f5e commit d5601c4
Show file tree
Hide file tree
Showing 27 changed files with 673 additions and 244 deletions.
3 changes: 2 additions & 1 deletion src/main/java/tauri/dev/jsg/block/energy/ZPMBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tauri.dev.jsg.item.energy.ZPMItemBlock;
import tauri.dev.jsg.power.zpm.IEnergyStorageZPM;
import tauri.dev.jsg.power.zpm.ZPMEnergyStorage;
import tauri.dev.jsg.power.zpm.ZPMItemEnergyStorage;
import tauri.dev.jsg.renderer.zpm.ZPMRenderer;
import tauri.dev.jsg.tileentity.energy.ZPMTile;

Expand Down Expand Up @@ -69,7 +70,7 @@ public List<ItemStack> getDrops(IBlockAccess world, @Nonnull BlockPos pos, @Nonn
ZPMEnergyStorage capacitorEnergyStorage = (ZPMEnergyStorage) world.getTileEntity(pos).getCapability(CapabilityEnergyZPM.ENERGY, null);

ItemStack stack = new ItemStack(this);
((ZPMEnergyStorage) stack.getCapability(CapabilityEnergyZPM.ENERGY, null)).setEnergyStored(capacitorEnergyStorage.getEnergyStored());
((ZPMItemEnergyStorage) stack.getCapability(CapabilityEnergyZPM.ENERGY, null)).setEnergyStored(capacitorEnergyStorage.getEnergyStored());

return Collections.singletonList(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import tauri.dev.jsg.stargate.network.StargateAddress;
import tauri.dev.jsg.stargate.network.StargateAddressDynamic;
import tauri.dev.jsg.stargate.network.StargatePos;
import tauri.dev.jsg.tileentity.stargate.StargateAbstractBaseTile;
import tauri.dev.jsg.stargate.network.SymbolTypeEnum;
import tauri.dev.jsg.util.BlockHelpers;

import java.util.*;
Expand Down Expand Up @@ -52,6 +52,16 @@ public void generateAddressEntries() {
e.address = a;
entries.add(e);
}

Map<StargatePos, Map<SymbolTypeEnum, StargateAddress>> notGeneratedMap = guiBase.stargateNetwork.getMapNotGenerated();
for (StargatePos pos : notGeneratedMap.keySet()) {
StargateEntry e = new StargateEntry();
e.pos = pos;
e.address = notGeneratedMap.get(pos).get(Objects.requireNonNull(guiBase.gateTile).getSymbolType());
e.notGenerated = true;
e.defaultName = "[NOT GENERATED GATE] ";
entries.add(e);
}
sortEntries();
}

Expand All @@ -70,8 +80,13 @@ public void generateAddressEntriesBoxes(boolean reset) {
StargatePos p = e.pos;
String name = (p.getName() != null && !p.getName().equalsIgnoreCase("") ? p.getName() : BlockHelpers.blockPosToBetterString(p.gatePos));
final int finalIndex = index;
GuiTextField field = new JSGTextField(index, Minecraft.getMinecraft().fontRenderer, guiLeft, 0, 120, 20, name).setActionCallback(() -> renameEntry(finalIndex));
field.setText(name);
JSGTextField field = new JSGTextField(index, Minecraft.getMinecraft().fontRenderer, guiLeft, 0, 120, 20, e.defaultName + name);
field.setText(e.defaultName + name);
if (!e.notGenerated) {
field.setActionCallback(() -> renameEntry(finalIndex));
} else {
field.setEnabled(false);
}
ArrowButton btn = (ArrowButton) new ArrowButton(index, guiLeft + 120 + 5, 0, ArrowButton.ArrowType.RIGHT).setFgColor(GuiUtils.getColorCode('a', true)).setActionCallback(() -> dialGate(finalIndex));
if (e.pos.gatePos.equals(Objects.requireNonNull(guiBase.gateTile).getPos()) && e.pos.dimensionID == guiBase.gateTile.world().provider.getDimension()) {
btn.setEnabled(false);
Expand All @@ -87,13 +102,12 @@ public void generateAddressEntriesBoxes(boolean reset) {
public void sortEntries() {
ArrayList<StargateEntry> newList = new ArrayList<>();
for (StargateEntry e : entries) {
if (e.pos.getName() != null && !e.pos.getName().equals(""))
if (!e.pos.getName().equals(""))
newList.add(e);
}
for (StargateEntry e : entries) {
if (e.pos.getName() != null && !e.pos.getName().equals(""))
continue;
newList.add(e);
if (e.pos.getName().equals(""))
newList.add(e);
}
entries = newList;
}
Expand All @@ -103,14 +117,27 @@ public void dialGate(int index) {
EnumHand hand = guiBase.getHand();
StargateEntry entry = entries.get(index);
StargatePos pos = entry.pos;
StargateAbstractBaseTile tile = pos.getTileEntity();
if (!tile.getStargateState().idle() && !tile.getStargateState().engaged()) return;
if (guiBase.gateTile == null || guiBase.imaginaryGateTile == null){
guiBase.notifer.setText("Linked gate is NULL!", Notifier.EnumAlertType.ERROR, 5);
return;
}
if (!guiBase.imaginaryGateTile.getStargateState().idle() && !guiBase.imaginaryGateTile.getStargateState().engaged()){
guiBase.notifer.setText("Stargate is busy!", Notifier.EnumAlertType.WARNING, 5);
return;
}

if(!guiBase.imaginaryGateTile.getStargateState().engaged())
guiBase.notifer.setText("Dialing gate " + (pos.getName().equals("") ? DimensionManager.getProviderType(pos.dimensionID).getName() : pos.getName()), Notifier.EnumAlertType.INFO, 5);
else
guiBase.notifer.setText("Closing gate...", Notifier.EnumAlertType.INFO, 5);

int symbolsCount = Objects.requireNonNull(guiBase.gateTile).getMinimalSymbolsToDial(pos.getGateSymbolType(), pos);

JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(hand, new StargateAddressDynamic(entry.address), symbolsCount, guiBase.gateTile.getPos()));
} catch (Exception e) {
JSG.error(e);
}
catch (Exception e){
JSG.error("Error ", e);
guiBase.notifer.setText("Unknown error! (" + e.getMessage() + ")", Notifier.EnumAlertType.ERROR, 5);
}
}

Expand All @@ -119,9 +146,10 @@ public void renameEntry(int index) {
EnumHand hand = guiBase.getHand();
GuiTextField field = entriesTextFields.get(index);
JSGPacketHandler.INSTANCE.sendToServer(new EntryActionToServer(hand, field.getText(), entries.get(index).pos));
//entries.get(index).pos.getTileEntity().renameStargatePos(field.getText());
guiBase.notifer.setText("Gate renamed to " + field.getText(), Notifier.EnumAlertType.INFO, 5);
} catch (Exception e) {
JSG.error(e);
guiBase.notifer.setText("Unknown error! (" + e.getMessage() + ")", Notifier.EnumAlertType.ERROR, 5);
}
}

Expand Down Expand Up @@ -156,16 +184,16 @@ public void renderFg() {
for (GuiTextField f : entriesTextFields) {
StargateEntry e = entries.get(f.getId());
if (!canNotRenderEntry(f.y) && GuiHelper.isPointInRegion(f.x, f.y, f.width, f.height, guiBase.mouseX, guiBase.mouseY)) {
guiBase.drawHoveringText(Arrays.asList(
Util.drawHoveringText(Arrays.asList(
"Type: " + e.pos.getGateSymbolType().toString(),
"Pos: " + e.pos.gatePos.toString(),
"Dim: " + e.pos.dimensionID + " (" + DimensionManager.getProviderType(e.pos.dimensionID).getName() + ")"
), guiBase.mouseX, guiBase.mouseY);
), guiBase.mouseX, guiBase.mouseY, guiBase.width, guiBase.height, -1, guiBase.mc.fontRenderer);
}
}
for (ArrowButton f : dialButtons) {
if (!canNotRenderEntry(f.y) && f.enabled && GuiHelper.isPointInRegion(f.x, f.y, f.width, f.height, guiBase.mouseX, guiBase.mouseY)) {
guiBase.drawHoveringText(Collections.singletonList("Dial this address"), guiBase.mouseX, guiBase.mouseY);
Util.drawHoveringText(Collections.singletonList("Dial this address"), guiBase.mouseX, guiBase.mouseY, guiBase.width, guiBase.height, -1, guiBase.mc.fontRenderer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class GuiAdminController extends JSGTexturedGui {
public int guiRight;
public int guiBottom;

public Notifier notifer = new Notifier();

public GuiAdminController(EntityPlayer player, World world, BlockPos pos, StargateNetwork stargateNetwork) {
super(512, 256, 512, 256);
this.world = world;
Expand Down Expand Up @@ -121,7 +123,7 @@ public void renderStargate() {
GlStateManager.enableAlpha();
GlStateManager.color(1, 1, 1);

GlStateManager.translate(gateCenter[0], gateCenter[1], 0);
GlStateManager.translate(gateCenter[0], gateCenter[1], 1);
GlStateManager.scale(-17, -17, -17);

GlStateManager.pushMatrix();
Expand Down Expand Up @@ -184,15 +186,21 @@ public void drawForeground(int mouseX, int mouseY, float partialTicks) {
renderControlButtons();
renderGateInfo();

notifer.render(this, 117, 4);

// Render foreground
GlStateManager.pushMatrix();
GlStateManager.enableDepth();
GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, 180);
addressesSection.renderFg();
GlStateManager.translate(0, 0, -180);
GlStateManager.popMatrix();

// render gate model
// Should be last
renderStargate();
GlStateManager.disableDepth();
GlStateManager.popMatrix();
}

@Override
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/tauri/dev/jsg/gui/admincontroller/Notifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tauri.dev.jsg.gui.admincontroller;

import tauri.dev.jsg.util.JSGMinecraftHelper;

import javax.annotation.Nonnull;

@SuppressWarnings("all")
public class Notifier {
private String lastText = null;
private int color = 0x202020;
private long lastTextEntered = 0;
private int showSeconds = 0;

public enum EnumAlertType{
INFO(0x21CEB7),
WARNING(0xCEA021),
ERROR(0xCE2121);

private final int color;
EnumAlertType(int color){
this.color = color;
}
}

public void clearText(){
this.lastText = null;
}

public void setText(@Nonnull String text, @Nonnull EnumAlertType type, int secondsToShow){
lastTextEntered = JSGMinecraftHelper.getClientTick();
showSeconds = secondsToShow;
lastText = text;
color = type.color;
}

public void render(GuiAdminController baseGui, int x, int y){
if((JSGMinecraftHelper.getClientTick() - lastTextEntered) > (showSeconds * 20L) || lastText == null) return;
baseGui.drawString(baseGui.mc.fontRenderer, lastText, x, y, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
public class StargateEntry {
public StargatePos pos;
public StargateAddress address;

public boolean notGenerated = false;
public String defaultName = "";
}
130 changes: 130 additions & 0 deletions src/main/java/tauri/dev/jsg/gui/admincontroller/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package tauri.dev.jsg.gui.admincontroller;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;

import java.util.ArrayList;
import java.util.List;

import static net.minecraftforge.fml.client.config.GuiUtils.drawGradientRect;

public class Util {
/**
* Method grabbed from {@link net.minecraftforge.fml.client.config.GuiUtils}
*/
public static void drawHoveringText(List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font) {
if (!textLines.isEmpty()) {
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
int tooltipTextWidth = 0;

for (String textLine : textLines) {
int textLineWidth = font.getStringWidth(textLine);

if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
}
}

boolean needsWrap = false;

int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
tooltipX = mouseX - 16 - tooltipTextWidth;
if (tooltipX < 4) // if the tooltip doesn't fit on the screen
{
if (mouseX > screenWidth / 2) {
tooltipTextWidth = mouseX - 12 - 8;
} else {
tooltipTextWidth = screenWidth - 16 - mouseX;
}
needsWrap = true;
}
}

if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) {
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}

if (needsWrap) {
int wrappedTooltipWidth = 0;
List<String> wrappedTextLines = new ArrayList<>();
for (int i = 0; i < textLines.size(); i++) {
String textLine = textLines.get(i);
List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth);
if (i == 0) {
titleLinesCount = wrappedLine.size();
}

for (String line : wrappedLine) {
int lineWidth = font.getStringWidth(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;

if (mouseX > screenWidth / 2) {
tooltipX = mouseX - 16 - tooltipTextWidth;
} else {
tooltipX = mouseX + 12;
}
}

int tooltipY = mouseY - 12;
int tooltipHeight = 8;

if (textLines.size() > 1) {
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
tooltipHeight += 2; // gap between title lines and next lines
}
}

if (tooltipY < 4) {
tooltipY = 4;
} else if (tooltipY + tooltipHeight + 4 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 4;
}

final int zLevel = 300;
int backgroundColor = 0xF0100010;
int borderColorStart = 0x505000FF;
int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);

GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, zLevel + 5);
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
String line = textLines.get(lineNumber);
font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1);

if (lineNumber + 1 == titleLinesCount) {
tooltipY += 2;
}

tooltipY += 10;
}
GlStateManager.popMatrix();

GlStateManager.enableLighting();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public ActionResult<ItemStack> onItemRightClick(World world, @Nonnull EntityPlay
int symbolsNeeded = (sameType ? (sameDim ? 6 : 7) : 8);
maxSymbols = Math.min(symbolsNeeded, maxSymbols);
}*/
gateTile.dialAddress(address, maxSymbols);
gateTile.dialAddress(address, maxSymbols, false);
player.sendStatusMessage(new TextComponentTranslation("item.jsg.universe_dialer.dial_start"), true);
if(player instanceof EntityPlayerMP)
JSGSoundHelper.playSoundToPlayer(((EntityPlayerMP) player), SoundEventEnum.UNIVERSE_DIALER_START_DIAL, player.getPosition());
Expand Down
Loading

0 comments on commit d5601c4

Please sign in to comment.