Skip to content

Commit 9d6f500

Browse files
committed
- Added structure upgrade preview.
- Attempted to fix some syntax issues when serializing NBT to JSON. - RecipeCheckEvent is now split into START, END phases, so it now fires twice. - Deprecated RecipePrimer#addCheckHandler and replaced it with RecipePrimer#addPostCheckHandler. - Deprecated DynamicMachineUpgradeBuilder#addRecipeCheckHandler and replaced it with DynamicMachineUpgradeBuilder#addRecipePostTickHandler. - The subitem chances of RequirementIngredientArray act only on the weights of the outputs, while the inputs play no role. - Added `enableDurationMultiplier` option to the configuration file. - BlockArray supports configuring `preview-tag` when parsing JSON. - Standardized item rendering (unified use of IngredientItemStackRenderer). - Bump version.
1 parent d6592dc commit 9d6f500

43 files changed

Lines changed: 871 additions & 314 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313
// Project properties
1414
group = "hellfirepvp.modularmachinery"
15-
version = "2.0.0-pre1"
15+
version = "2.0.0-pre2"
1616

1717
// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
1818
java {

src/main/java/com/cleanroommc/client/preview/renderer/scene/WorldSceneRenderer.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enum CacheState {
8282
private final LRMap<Collection<BlockPos>, ISceneRenderHook> renderedBlocksMap;
8383
private final LRVertexBuffer vertexBuffers = new LRVertexBuffer();
8484

85-
protected Set<BlockPos> tileEntities;
85+
protected Set<BlockPos> tileEntities = new HashSet<>();
8686
protected boolean useCache;
8787
protected AtomicReference<CacheState> cacheState;
8888
protected int maxProgress;
@@ -157,7 +157,7 @@ public WorldSceneRenderer deleteCacheBuffer() {
157157
layerBufferBuilders.clear();
158158
});
159159
}
160-
this.tileEntities = null;
160+
tileEntities.clear();
161161
useCache = false;
162162
cacheState.set(CacheState.UNUSED);
163163
return this;
@@ -223,7 +223,7 @@ public RayTraceResult getLastTraceResult() {
223223

224224
public void render(float x, float y, float width, float height, int mouseX, int mouseY) {
225225
// setupCamera
226-
PositionedRect positionedRect = getPositionedRect((int)x, (int)y, (int)width, (int)height);
226+
PositionedRect positionedRect = getPositionedRect((int) x, (int) y, (int) width, (int) height);
227227
PositionedRect mouse = getPositionedRect(mouseX, mouseY, 0, 0);
228228
mouseX = mouse.position.x;
229229
mouseY = mouse.position.y;
@@ -232,12 +232,10 @@ public void render(float x, float y, float width, float height, int mouseX, int
232232
drawWorld();
233233
// check lookingAt
234234
this.lastTraceResult = null;
235-
if (onLookingAt != null && mouseX > positionedRect.position.x && mouseX < positionedRect.position.x + positionedRect.size.width
236-
&& mouseY > positionedRect.position.y && mouseY < positionedRect.position.y + positionedRect.size.height) {
235+
if (onLookingAt != null && isMouseOver(positionedRect, mouseX, mouseY)) {
237236
Vector3f hitPos = unProject(mouseX, mouseY);
238237
RayTraceResult result = rayTrace(hitPos);
239238
if (result != null) {
240-
this.lastTraceResult = null;
241239
this.lastTraceResult = result;
242240
onLookingAt.accept(result);
243241
}
@@ -246,6 +244,11 @@ public void render(float x, float y, float width, float height, int mouseX, int
246244
resetCamera();
247245
}
248246

247+
protected static boolean isMouseOver(final PositionedRect positionedRect, final int mouseX, final int mouseY) {
248+
return mouseX > positionedRect.position.x && mouseX < positionedRect.position.x + positionedRect.size.width
249+
&& mouseY > positionedRect.position.y && mouseY < positionedRect.position.y + positionedRect.size.height;
250+
}
251+
249252
public Vector3f getEyePos() {
250253
return eyePos;
251254
}
@@ -275,7 +278,7 @@ public void setCameraLookAt(Vector3 eyePos, Vector3f lookAt, Vector3f worldUp) {
275278

276279
public void setCameraLookAt(Vector3f lookAt, double radius, double rotationPitch, double rotationYaw) {
277280
Vector3 vecX = new Vector3(Math.cos(rotationPitch), 0, Math.sin(rotationPitch));
278-
Vector3 vecY = new Vector3(0, Math.tan(rotationYaw) * vecX.mag(),0);
281+
Vector3 vecY = new Vector3(0, Math.tan(rotationYaw) * vecX.mag(), 0);
279282
Vector3 pos = vecX.copy().add(vecY).normalize().multiply(radius);
280283
setCameraLookAt(pos.add(lookAt.x, lookAt.y, lookAt.z), lookAt, worldUp);
281284
}
@@ -639,7 +642,7 @@ private void renderTESR(final int pass, float particle, boolean checkDisabledMod
639642
RenderHelper.enableStandardItemLighting();
640643
ForgeHooksClient.setRenderPass(pass);
641644
if (!useCache) {
642-
renderedBlocksMap.getMap().forEach((renderedBlocks, hook)->{
645+
renderedBlocksMap.getMap().forEach((renderedBlocks, hook) -> {
643646
if (hook != null) {
644647
hook.apply(true, pass, null);
645648
} else {
@@ -658,14 +661,10 @@ private void renderTESR(final int pass, float particle, boolean checkDisabledMod
658661
}
659662
});
660663
} else {
661-
if (tileEntities != null) {
662-
for (BlockPos pos : tileEntities) {
663-
TileEntity tile = getWorld().getTileEntity(pos);
664-
if (tile != null) {
665-
if (tile.shouldRenderInPass(pass)) {
666-
TileEntityRendererDispatcher.instance.render(tile, pos.getX(), pos.getY(), pos.getZ(), particle);
667-
}
668-
}
664+
for (BlockPos pos : tileEntities) {
665+
TileEntity tile = getWorld().getTileEntity(pos);
666+
if (tile != null && tile.shouldRenderInPass(pass)) {
667+
TileEntityRendererDispatcher.instance.render(tile, pos.getX(), pos.getY(), pos.getZ(), particle);
669668
}
670669
}
671670
}
@@ -804,7 +803,7 @@ protected RayTraceResult screenPos2BlockPosFace(int mouseX, int mouseY, int x, i
804803
* @param depth should pass Depth Test
805804
* @return x, y, z
806805
*/
807-
protected Vector3f blockPos2ScreenPos(BlockPos pos, boolean depth, int x, int y, int width, int height){
806+
protected Vector3f blockPos2ScreenPos(BlockPos pos, boolean depth, int x, int y, int width, int height) {
808807
// render a frame
809808
GlStateManager.enableDepth();
810809
setupCamera(getPositionedRect(x, y, width, height));

src/main/java/com/cleanroommc/client/util/BlockInfo.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.cleanroommc.client.util;
22

33
import com.cleanroommc.client.util.world.DummyWorld;
4+
import hellfirepvp.modularmachinery.ModularMachinery;
45
import net.minecraft.block.Block;
56
import net.minecraft.block.state.IBlockState;
67
import net.minecraft.init.Blocks;
78
import net.minecraft.item.Item;
89
import net.minecraft.item.ItemStack;
10+
import net.minecraft.nbt.NBTTagCompound;
911
import net.minecraft.tileentity.TileEntity;
1012
import net.minecraft.util.math.BlockPos;
1113
import net.minecraft.world.World;
@@ -17,6 +19,7 @@ public class BlockInfo {
1719
private final IBlockState blockState;
1820
private TileEntity tileEntity;
1921
private final ItemStack itemStack;
22+
private NBTTagCompound teTag;
2023

2124
public BlockInfo(Block block) {
2225
this(block.getDefaultState());
@@ -31,9 +34,14 @@ public BlockInfo(IBlockState blockState, TileEntity tileEntity) {
3134
}
3235

3336
public BlockInfo(IBlockState blockState, TileEntity tileEntity, ItemStack itemStack) {
37+
this(blockState, tileEntity, itemStack, null);
38+
}
39+
40+
public BlockInfo(final IBlockState blockState, final TileEntity tileEntity, final ItemStack itemStack, final NBTTagCompound teTag) {
3441
this.blockState = blockState;
3542
this.tileEntity = tileEntity;
3643
this.itemStack = itemStack;
44+
this.teTag = teTag;
3745
}
3846

3947
public static BlockInfo fromBlockState(IBlockState state) {
@@ -64,10 +72,30 @@ public ItemStack getItemStackForm() {
6472
return itemStack == null ? new ItemStack(Item.getItemFromBlock(blockState.getBlock()), 1, blockState.getBlock().damageDropped(blockState)) : itemStack;
6573
}
6674

75+
public NBTTagCompound getTeTag() {
76+
return teTag;
77+
}
78+
79+
public BlockInfo setTeTag(final NBTTagCompound teTag) {
80+
this.teTag = teTag;
81+
return this;
82+
}
83+
6784
public void apply(World world, BlockPos pos) {
6885
world.setBlockState(pos, blockState);
69-
if (tileEntity != null) {
70-
world.setTileEntity(pos, tileEntity);
86+
if (tileEntity == null) {
87+
return;
88+
}
89+
world.setTileEntity(pos, tileEntity);
90+
if (teTag == null) {
91+
return;
92+
}
93+
try {
94+
tileEntity.readFromNBT(teTag);
95+
} catch (Exception e) {
96+
ModularMachinery.log.warn("Failed to apply NBT to TileEntity!", e);
97+
world.removeTileEntity(pos);
98+
world.setTileEntity(pos, blockState.getBlock().createTileEntity(world, blockState));
7199
}
72100
}
73101
}

src/main/java/github/kasuminova/mmce/client/gui/widget/MultiLineLabel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import net.minecraft.client.gui.FontRenderer;
1010
import net.minecraft.client.renderer.GlStateManager;
1111

12-
import java.util.ArrayList;
13-
import java.util.Collections;
1412
import java.util.LinkedList;
1513
import java.util.List;
1614

1715
public class MultiLineLabel extends DynamicWidget {
18-
public static final int DEFAULT_FONT_HEIGHT = 9;
16+
public static final int DEFAULT_FONT_HEIGHT = 10;
1917

2018
protected List<String> contents;
2119

src/main/java/github/kasuminova/mmce/client/gui/widget/preview/SelectedBlockIngredientList.java renamed to src/main/java/github/kasuminova/mmce/client/gui/widget/preview/IngredientListVertical.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
import net.minecraft.client.gui.GuiScreen;
1010
import net.minecraft.client.renderer.GlStateManager;
1111
import net.minecraft.item.ItemStack;
12+
import net.minecraft.util.ResourceLocation;
13+
import org.lwjgl.opengl.GL11;
1214

1315
import java.util.List;
1416

1517
import static github.kasuminova.mmce.client.gui.widget.preview.MachineStructurePreviewPanel.WIDGETS_TEX_LOCATION;
1618

17-
public class SelectedBlockIngredientList extends IngredientList {
19+
public class IngredientListVertical extends IngredientList {
20+
protected ResourceLocation listBgTexLocation = WIDGETS_TEX_LOCATION;
1821
protected int listBgTexX = 229;
1922
protected int listBgTexY = 125;
2023
protected int listBgTexWidth = 25;
2124
protected int listBgTexWidthWithNoScrollbar = 18;
2225
protected int listBgTexHeight = 126;
2326

24-
public SelectedBlockIngredientList() {
27+
public IngredientListVertical() {
2528
setWidthHeight(25, 126);
2629
}
2730

@@ -37,12 +40,19 @@ public void initWidget(final WidgetGui gui) {
3740
.setUnavailableTextureXY(208, 175)
3841
.setTextureLocation(WIDGETS_TEX_LOCATION)
3942
.setWidthHeight(6, 17);
43+
checkScrollbarRange();
4044
}
4145

4246
@Override
4347
public void update(final WidgetGui gui) {
4448
super.update(gui);
45-
scrollbar.setDisabled(scrollbar.getRange() <= 0);
49+
checkScrollbarRange();
50+
}
51+
52+
protected void checkScrollbarRange() {
53+
boolean shouldDisable = scrollbar.getRange() <= 0;
54+
scrollbar.setDisabled(shouldDisable);
55+
setWidth(scrollbar.isDisabled() ? listBgTexWidthWithNoScrollbar : listBgTexWidth);
4656
}
4757

4858
@Override
@@ -65,19 +75,18 @@ protected void renderInternal(final WidgetGui gui, final RenderSize renderSize,
6575

6676
protected void drawListBg(final WidgetGui widgetGui, final RenderPos renderPos) {
6777
GuiScreen gui = widgetGui.getGui();
68-
gui.mc.getTextureManager().bindTexture(WIDGETS_TEX_LOCATION);
78+
gui.mc.getTextureManager().bindTexture(listBgTexLocation);
6979
GlStateManager.enableBlend();
7080
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
7181
gui.drawTexturedModalRect(
7282
renderPos.posX(), renderPos.posY(),
7383
listBgTexX, listBgTexY,
7484
scrollbar.isDisabled() ? listBgTexWidthWithNoScrollbar : listBgTexWidth, listBgTexHeight
7585
);
76-
GlStateManager.disableBlend();
7786
}
7887

7988
@Override
80-
public SelectedBlockIngredientList setStackList(final List<ItemStack> list) {
89+
public IngredientListVertical setStackList(final List<ItemStack> list) {
8190
getWidgets().clear();
8291
list.stream().map(SlotVirtual::ofJEI).forEach(this::addWidget);
8392
return this;

0 commit comments

Comments
 (0)