mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 17:53:42 +01:00
Merge branch 'mc1.15/dev' of https://github.com/Creators-of-Create/Create into mc1.15/dev
This commit is contained in:
commit
d252a204ef
4 changed files with 116 additions and 32 deletions
|
@ -1,10 +1,7 @@
|
|||
package com.simibubi.create.content.contraptions.goggles;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
@ -13,12 +10,16 @@ import net.minecraftforge.common.util.LazyOptional;
|
|||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/*
|
||||
* Implement this Interface in the TileEntity class that wants to add info to the screen
|
||||
* */
|
||||
public interface IHaveGoggleInformation {
|
||||
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
Format numberFormat = new Format();
|
||||
String spacing = " ";
|
||||
|
||||
/**
|
||||
|
@ -33,7 +34,7 @@ public interface IHaveGoggleInformation {
|
|||
}
|
||||
|
||||
static String format(double d) {
|
||||
return decimalFormat.format(d);
|
||||
return numberFormat.get().format(d);
|
||||
}
|
||||
|
||||
default boolean containedFluidTooltip(List<String> tooltip, boolean isPlayerSneaking,
|
||||
|
@ -89,4 +90,23 @@ public interface IHaveGoggleInformation {
|
|||
return true;
|
||||
}
|
||||
|
||||
class Format {
|
||||
|
||||
private NumberFormat format = NumberFormat.getNumberInstance(Locale.ROOT);;
|
||||
|
||||
private Format() {}
|
||||
|
||||
public NumberFormat get() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
format = NumberFormat.getInstance(Minecraft.getInstance().getLanguageManager().getCurrentLanguage().getJavaLocale());
|
||||
format.setMaximumFractionDigits(2);
|
||||
format.setMinimumFractionDigits(0);
|
||||
format.setGroupingUsed(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.tra
|
|||
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController;
|
||||
import com.simibubi.create.content.contraptions.components.turntable.TurntableHandler;
|
||||
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
|
||||
import com.simibubi.create.content.curiosities.tools.ExtendoGripRenderHandler;
|
||||
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
|
||||
|
@ -124,6 +125,13 @@ public class ClientEvents {
|
|||
AnimationTickHolder.reset();
|
||||
((ClientWorld) world).loadedTileEntityList.forEach(CreateClient.kineticRenderer::add);
|
||||
}
|
||||
|
||||
/*
|
||||
i was getting nullPointers when trying to call this during client setup,
|
||||
so i assume minecraft's language manager isn't yet fully loaded at that time.
|
||||
not sure where else to call this tho :S
|
||||
*/
|
||||
IHaveGoggleInformation.numberFormat.update();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.simibubi.create.foundation;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.foundation.block.render.SpriteShifter;
|
||||
|
||||
import net.minecraft.client.resources.ReloadListener;
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
|
@ -18,6 +18,7 @@ public class ResourceReloadHandler extends ReloadListener<Object> {
|
|||
protected void apply(Object $, IResourceManager resourceManagerIn, IProfiler profilerIn) {
|
||||
SpriteShifter.reloadUVs();
|
||||
CreateClient.invalidateRenderers();
|
||||
IHaveGoggleInformation.numberFormat.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.simibubi.create.foundation.ponder.content;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.components.crank.ValveHandleBlock;
|
||||
import com.simibubi.create.foundation.gui.AbstractSimiScreen;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||
|
@ -13,10 +15,12 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.client.MainWindow;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.Rectangle2d;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -31,7 +35,7 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
|
||||
protected final List<Item> items;
|
||||
private final double itemXmult = 0.5;
|
||||
private final double itemYmult = 0.75;
|
||||
private double itemYmult = 0.75;
|
||||
protected Rectangle2d itemArea;
|
||||
|
||||
private ItemStack hoveredItem = ItemStack.EMPTY;
|
||||
|
@ -45,11 +49,31 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
protected void init() {
|
||||
super.init();
|
||||
|
||||
//populate lists
|
||||
widgets.clear();
|
||||
|
||||
chapters.clear();
|
||||
chapters.addAll(PonderRegistry.chapters.getAllChapters());
|
||||
//chapters.addAll(PonderRegistry.chapters.getAllChapters());
|
||||
|
||||
items.clear();
|
||||
PonderRegistry.all.keySet()
|
||||
.stream()
|
||||
.map(key -> {
|
||||
Item item = ForgeRegistries.ITEMS.getValue(key);
|
||||
if (item == null) {
|
||||
Block b = ForgeRegistries.BLOCKS.getValue(key);
|
||||
if (b != null)
|
||||
item = b.asItem();
|
||||
}
|
||||
return item;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.filter(PonderIndexScreen::exclusions)
|
||||
.forEach(items::add);
|
||||
|
||||
boolean hasChapters = !chapters.isEmpty();
|
||||
|
||||
//setup chapters
|
||||
LayoutHelper layout = LayoutHelper.centeredHorizontal(
|
||||
chapters.size(),
|
||||
MathHelper.clamp((int) Math.ceil(chapters.size() / 4f), 1, 4),
|
||||
|
@ -73,24 +97,15 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
layout.next();
|
||||
}
|
||||
|
||||
items.clear();
|
||||
PonderRegistry.all.keySet()
|
||||
.stream()
|
||||
.map(key -> {
|
||||
Item item = ForgeRegistries.ITEMS.getValue(key);
|
||||
if (item == null) {
|
||||
Block b = ForgeRegistries.BLOCKS.getValue(key);
|
||||
if (b != null)
|
||||
item = b.asItem();
|
||||
}
|
||||
return item;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(items::add);
|
||||
//setup items
|
||||
if (!hasChapters) {
|
||||
itemYmult = 0.5;
|
||||
}
|
||||
|
||||
int maxItemRows = hasChapters ? 4 : 7;
|
||||
layout = LayoutHelper.centeredHorizontal(
|
||||
items.size(),
|
||||
MathHelper.clamp((int) Math.ceil(items.size() / 11f), 1, 4),
|
||||
MathHelper.clamp((int) Math.ceil(items.size() / 11f), 1, maxItemRows),
|
||||
28,
|
||||
28,
|
||||
8
|
||||
|
@ -100,8 +115,13 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
int itemCenterY = (int) (height * itemYmult);
|
||||
|
||||
for (Item item : items) {
|
||||
PonderButton button = new PonderButton(itemCenterX + layout.getX() + 4, itemCenterY + layout.getY() + 4, (x, y) -> {})
|
||||
.showing(new ItemStack(item));
|
||||
PonderButton button = new PonderButton(itemCenterX + layout.getX() + 4, itemCenterY + layout.getY() + 4, (x, y) -> {
|
||||
if (!PonderRegistry.all.containsKey(item.getRegistryName()))
|
||||
return;
|
||||
|
||||
centerScalingOn(x, y);
|
||||
ScreenOpener.transitionTo(PonderUI.of(new ItemStack(item)));
|
||||
}).showing(new ItemStack(item));
|
||||
|
||||
button.fade(1);
|
||||
widgets.add(button);
|
||||
|
@ -111,6 +131,15 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
|
||||
}
|
||||
|
||||
private static boolean exclusions(Item item) {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof ValveHandleBlock && !AllBlocks.COPPER_VALVE_HANDLE.is(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
@ -132,14 +161,15 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
int x = (int) (width * chapterXmult);
|
||||
int y = (int) (height * chapterYmult);
|
||||
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translated(x, y, 0);
|
||||
if (!chapters.isEmpty()) {
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translated(x, y, 0);
|
||||
|
||||
UIRenderHelper.streak(0, chapterArea.getX() - 10, chapterArea.getY() - 20, 20, 220, 0x101010);
|
||||
drawString(font, "Topics to Ponder about", chapterArea.getX() - 5, chapterArea.getY() - 25, 0xffddeeff);
|
||||
|
||||
RenderSystem.popMatrix();
|
||||
UIRenderHelper.streak(0, chapterArea.getX() - 10, chapterArea.getY() - 20, 20, 220, 0x101010);
|
||||
drawString(font, "Topics to Ponder about", chapterArea.getX() - 5, chapterArea.getY() - 25, 0xffddeeff);
|
||||
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
x = (int) (width * itemXmult);
|
||||
y = (int) (height * itemYmult);
|
||||
|
@ -166,6 +196,31 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
|||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
MutableBoolean handled = new MutableBoolean(false);
|
||||
widgets.forEach(w -> {
|
||||
if (handled.booleanValue())
|
||||
return;
|
||||
if (!w.isMouseOver(x, y))
|
||||
return;
|
||||
if (w instanceof PonderButton) {
|
||||
PonderButton btn = (PonderButton) w;
|
||||
btn.runCallback(x, y);
|
||||
handled.setTrue();
|
||||
}
|
||||
});
|
||||
|
||||
if (handled.booleanValue())
|
||||
return true;
|
||||
return super.mouseClicked(x, y, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentTo(AbstractSimiScreen other) {
|
||||
return other instanceof PonderIndexScreen;
|
||||
}
|
||||
|
||||
public ItemStack getHoveredTooltipItem() {
|
||||
return hoveredItem;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue