mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 23:53:41 +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;
|
package com.simibubi.create.content.contraptions.goggles;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
import com.simibubi.create.foundation.utility.Lang;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
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.FluidStack;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
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
|
* Implement this Interface in the TileEntity class that wants to add info to the screen
|
||||||
* */
|
* */
|
||||||
public interface IHaveGoggleInformation {
|
public interface IHaveGoggleInformation {
|
||||||
|
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
Format numberFormat = new Format();
|
||||||
String spacing = " ";
|
String spacing = " ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +34,7 @@ public interface IHaveGoggleInformation {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String format(double d) {
|
static String format(double d) {
|
||||||
return decimalFormat.format(d);
|
return numberFormat.get().format(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean containedFluidTooltip(List<String> tooltip, boolean isPlayerSneaking,
|
default boolean containedFluidTooltip(List<String> tooltip, boolean isPlayerSneaking,
|
||||||
|
@ -89,4 +90,23 @@ public interface IHaveGoggleInformation {
|
||||||
return true;
|
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.CouplingRenderer;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController;
|
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.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.contraptions.relays.belt.item.BeltConnectorHandler;
|
||||||
import com.simibubi.create.content.curiosities.tools.ExtendoGripRenderHandler;
|
import com.simibubi.create.content.curiosities.tools.ExtendoGripRenderHandler;
|
||||||
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
|
import com.simibubi.create.content.curiosities.zapper.ZapperItem;
|
||||||
|
@ -124,6 +125,13 @@ public class ClientEvents {
|
||||||
AnimationTickHolder.reset();
|
AnimationTickHolder.reset();
|
||||||
((ClientWorld) world).loadedTileEntityList.forEach(CreateClient.kineticRenderer::add);
|
((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
|
@SubscribeEvent
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.simibubi.create.foundation;
|
package com.simibubi.create.foundation;
|
||||||
|
|
||||||
import com.simibubi.create.CreateClient;
|
import com.simibubi.create.CreateClient;
|
||||||
|
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
||||||
import com.simibubi.create.foundation.block.render.SpriteShifter;
|
import com.simibubi.create.foundation.block.render.SpriteShifter;
|
||||||
|
|
||||||
import net.minecraft.client.resources.ReloadListener;
|
import net.minecraft.client.resources.ReloadListener;
|
||||||
import net.minecraft.profiler.IProfiler;
|
import net.minecraft.profiler.IProfiler;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.resources.IResourceManager;
|
||||||
|
@ -18,6 +18,7 @@ public class ResourceReloadHandler extends ReloadListener<Object> {
|
||||||
protected void apply(Object $, IResourceManager resourceManagerIn, IProfiler profilerIn) {
|
protected void apply(Object $, IResourceManager resourceManagerIn, IProfiler profilerIn) {
|
||||||
SpriteShifter.reloadUVs();
|
SpriteShifter.reloadUVs();
|
||||||
CreateClient.invalidateRenderers();
|
CreateClient.invalidateRenderers();
|
||||||
|
IHaveGoggleInformation.numberFormat.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.simibubi.create.foundation.ponder.content;
|
package com.simibubi.create.foundation.ponder.content;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
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.AbstractSimiScreen;
|
||||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||||
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
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.MainWindow;
|
||||||
import net.minecraft.client.gui.widget.Widget;
|
import net.minecraft.client.gui.widget.Widget;
|
||||||
import net.minecraft.client.renderer.Rectangle2d;
|
import net.minecraft.client.renderer.Rectangle2d;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,7 +35,7 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
|
|
||||||
protected final List<Item> items;
|
protected final List<Item> items;
|
||||||
private final double itemXmult = 0.5;
|
private final double itemXmult = 0.5;
|
||||||
private final double itemYmult = 0.75;
|
private double itemYmult = 0.75;
|
||||||
protected Rectangle2d itemArea;
|
protected Rectangle2d itemArea;
|
||||||
|
|
||||||
private ItemStack hoveredItem = ItemStack.EMPTY;
|
private ItemStack hoveredItem = ItemStack.EMPTY;
|
||||||
|
@ -45,11 +49,31 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
|
//populate lists
|
||||||
widgets.clear();
|
widgets.clear();
|
||||||
|
|
||||||
chapters.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(
|
LayoutHelper layout = LayoutHelper.centeredHorizontal(
|
||||||
chapters.size(),
|
chapters.size(),
|
||||||
MathHelper.clamp((int) Math.ceil(chapters.size() / 4f), 1, 4),
|
MathHelper.clamp((int) Math.ceil(chapters.size() / 4f), 1, 4),
|
||||||
|
@ -73,24 +97,15 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
layout.next();
|
layout.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
items.clear();
|
//setup items
|
||||||
PonderRegistry.all.keySet()
|
if (!hasChapters) {
|
||||||
.stream()
|
itemYmult = 0.5;
|
||||||
.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);
|
|
||||||
|
|
||||||
|
int maxItemRows = hasChapters ? 4 : 7;
|
||||||
layout = LayoutHelper.centeredHorizontal(
|
layout = LayoutHelper.centeredHorizontal(
|
||||||
items.size(),
|
items.size(),
|
||||||
MathHelper.clamp((int) Math.ceil(items.size() / 11f), 1, 4),
|
MathHelper.clamp((int) Math.ceil(items.size() / 11f), 1, maxItemRows),
|
||||||
28,
|
28,
|
||||||
28,
|
28,
|
||||||
8
|
8
|
||||||
|
@ -100,8 +115,13 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
int itemCenterY = (int) (height * itemYmult);
|
int itemCenterY = (int) (height * itemYmult);
|
||||||
|
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
PonderButton button = new PonderButton(itemCenterX + layout.getX() + 4, itemCenterY + layout.getY() + 4, (x, y) -> {})
|
PonderButton button = new PonderButton(itemCenterX + layout.getX() + 4, itemCenterY + layout.getY() + 4, (x, y) -> {
|
||||||
.showing(new ItemStack(item));
|
if (!PonderRegistry.all.containsKey(item.getRegistryName()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
centerScalingOn(x, y);
|
||||||
|
ScreenOpener.transitionTo(PonderUI.of(new ItemStack(item)));
|
||||||
|
}).showing(new ItemStack(item));
|
||||||
|
|
||||||
button.fade(1);
|
button.fade(1);
|
||||||
widgets.add(button);
|
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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
@ -132,6 +161,7 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
int x = (int) (width * chapterXmult);
|
int x = (int) (width * chapterXmult);
|
||||||
int y = (int) (height * chapterYmult);
|
int y = (int) (height * chapterYmult);
|
||||||
|
|
||||||
|
if (!chapters.isEmpty()) {
|
||||||
RenderSystem.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
RenderSystem.translated(x, y, 0);
|
RenderSystem.translated(x, y, 0);
|
||||||
|
|
||||||
|
@ -139,7 +169,7 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
drawString(font, "Topics to Ponder about", chapterArea.getX() - 5, chapterArea.getY() - 25, 0xffddeeff);
|
drawString(font, "Topics to Ponder about", chapterArea.getX() - 5, chapterArea.getY() - 25, 0xffddeeff);
|
||||||
|
|
||||||
RenderSystem.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
x = (int) (width * itemXmult);
|
x = (int) (width * itemXmult);
|
||||||
y = (int) (height * itemYmult);
|
y = (int) (height * itemYmult);
|
||||||
|
@ -166,6 +196,31 @@ public class PonderIndexScreen extends AbstractSimiScreen {
|
||||||
RenderSystem.popMatrix();
|
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() {
|
public ItemStack getHoveredTooltipItem() {
|
||||||
return hoveredItem;
|
return hoveredItem;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue