Skip to content

Commit 66e9517

Browse files
authored
Merge branch 'master' into gh-port-qstorage-mui2
2 parents 283e2d7 + 41f3711 commit 66e9517

File tree

19 files changed

+144
-60
lines changed

19 files changed

+144
-60
lines changed

build.gradle

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//version: 1743737794
1+
//version: 1753288091
22
/*
33
* DO NOT CHANGE THIS FILE!
44
* Also, you may replace this file at any time if there is an update available.
@@ -50,6 +50,8 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
5050

5151

5252
// Project properties
53+
loadProjectProperties()
54+
5355

5456
// Required properties: we don't know how to handle these being missing gracefully
5557
checkPropertyExists("modName")
@@ -870,10 +872,10 @@ if (enableJava17RunTasks.toBoolean()) {
870872

871873
dependencies {
872874
if (modId != 'lwjgl3ify') {
873-
java17Dependencies("io.github.twilightflower:lwjgl3ify:1.0.0")
874-
}
875-
java17PatchDependencies("io.github.twilightflower:lwjgl3ify:1.0.0:forgePatches") {
875+
java17Dependencies("io.github.twilightflower:lwjgl3ify:1.0.1")
876+
java17PatchDependencies("io.github.twilightflower:lwjgl3ify:1.0.1:forgePatches") {
876877
transitive = false
878+
}
877879
}
878880
}
879881

@@ -1009,7 +1011,7 @@ abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {
10091011

10101012
if (project.usesMixins.toBoolean()) {
10111013
this.extraJvmArgs.addAll(project.provider(() -> {
1012-
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(mixinProviderSpec))
1014+
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(project.mixinProviderSpec))
10131015
mixinCfg.canBeConsumed = false
10141016
mixinCfg.canBeResolved = true
10151017
mixinCfg.transitive = false
@@ -1475,14 +1477,28 @@ tasks.register('faq') {
14751477
"To add new dependencies to your project, place them in 'dependencies.gradle', NOT in 'build.gradle' as they would be replaced when the script updates.\n" +
14761478
"To add new repositories to your project, place them in 'repositories.gradle'.\n" +
14771479
"If you need additional gradle code to run, you can place it in a file named 'addon.gradle' (or either of the above, up to you for organization).\n\n" +
1478-
"If your build fails to recognize the syntax of newer Java versions, enable Jabel in your 'gradle.properties' under the option name 'enableModernJavaSyntax'.\n" +
1480+
"If your build fails to recognize the syntax of newer Java versions, enable Jabel in your 'buildscript.properties' under the option name 'enableModernJavaSyntax'.\n" +
14791481
"To see information on how to configure your IDE properly for Java 17, see https://github.com/GregTechCEu/Buildscripts/blob/master/docs/jabel.md\n\n" +
14801482
"Report any issues or feature requests you have for this build script to https://github.com/GregTechCEu/Buildscripts/issues\n")
14811483
}
14821484
}
14831485

14841486

14851487
// Helpers
1488+
def loadProjectProperties() {
1489+
def configFile = file("buildscript.properties")
1490+
if (configFile.exists()) {
1491+
configFile.withReader {
1492+
def prop = new Properties()
1493+
prop.load(it)
1494+
new ConfigSlurper().parse(prop).forEach { String k, def v ->
1495+
project.ext.setProperty(k, v)
1496+
}
1497+
}
1498+
} else {
1499+
print("Failed to read from buildscript.properties, as it did not exist!")
1500+
}
1501+
}
14861502

14871503
def getDefaultArtifactGroup() {
14881504
def lastIndex = project.modGroup.lastIndexOf('.')
@@ -1495,7 +1511,7 @@ def getFile(String relativePath) {
14951511

14961512
def checkPropertyExists(String propertyName) {
14971513
if (!project.hasProperty(propertyName)) {
1498-
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GregTechCEu/Buildscripts/blob/main/gradle.properties")
1514+
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"buildscript.properties\" or \"gradle.properties\". You can find all properties and their description here: https://github.com/GregTechCEu/Buildscripts/blob/main/buildscript.properties and https://github.com/GregTechCEu/Buildscripts/blob/main/gradle.properties")
14991515
}
15001516
}
15011517

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.redstudio.alfheim.lighting;
2+
3+
// stub class to appease javac
4+
public class LightingEngine {
5+
}

src/main/java/gregtech/api/metatileentity/NeighborCacheTileEntityBase.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
import org.jetbrains.annotations.NotNull;
1212
import org.jetbrains.annotations.Nullable;
1313

14+
import java.lang.ref.WeakReference;
1415
import java.util.Arrays;
16+
import java.util.List;
1517

1618
public abstract class NeighborCacheTileEntityBase extends SyncedTileEntityBase implements INeighborCache {
1719

18-
private final TileEntity[] neighbors = new TileEntity[6];
20+
private static final WeakReference<TileEntity> NULL = new WeakReference<>(null);
21+
private static final WeakReference<TileEntity> INVALID = new WeakReference<>(null);
22+
23+
private final List<WeakReference<TileEntity>> neighbors = Arrays.asList(
24+
INVALID, INVALID, INVALID, INVALID, INVALID, INVALID);
1925
private boolean neighborsInvalidated = false;
2026

2127
public NeighborCacheTileEntityBase() {
@@ -24,7 +30,9 @@ public NeighborCacheTileEntityBase() {
2430

2531
protected void invalidateNeighbors() {
2632
if (!this.neighborsInvalidated) {
27-
Arrays.fill(this.neighbors, this);
33+
for (EnumFacing value : EnumFacing.VALUES) {
34+
this.neighbors.set(value.getIndex(), INVALID);
35+
}
2836
this.neighborsInvalidated = true;
2937
}
3038
}
@@ -60,17 +68,34 @@ public void onChunkUnload() {
6068
@Override
6169
public @Nullable TileEntity getNeighbor(@NotNull EnumFacing facing) {
6270
if (world == null || pos == null) return null;
63-
int i = facing.getIndex();
64-
TileEntity neighbor = this.neighbors[i];
65-
if (neighbor == this || (neighbor != null && neighbor.isInvalid())) {
66-
neighbor = world.getTileEntity(pos.offset(facing));
67-
this.neighbors[i] = neighbor;
68-
this.neighborsInvalidated = false;
69-
}
70-
return neighbor;
71+
// if the ref is INVALID, compute neighbor, otherwise, return TE or null
72+
WeakReference<TileEntity> ref = invalidRef(facing) ? computeNeighbor(facing) : getRef(facing);
73+
return ref.get();
74+
}
75+
76+
private boolean invalidRef(EnumFacing facing) {
77+
WeakReference<TileEntity> ref = getRef(facing);
78+
if (ref == INVALID) return true;
79+
TileEntity te = ref.get();
80+
return te != null && te.isInvalid();
81+
}
82+
83+
@NotNull
84+
private WeakReference<TileEntity> computeNeighbor(EnumFacing facing) {
85+
TileEntity te = super.getNeighbor(facing);
86+
// avoid making new references to null TEs
87+
WeakReference<TileEntity> ref = te == null ? NULL : new WeakReference<>(te);
88+
this.neighbors.set(facing.getIndex(), ref);
89+
this.neighborsInvalidated = false;
90+
return ref;
91+
}
92+
93+
@NotNull
94+
private WeakReference<TileEntity> getRef(EnumFacing facing) {
95+
return this.neighbors.get(facing.getIndex());
7196
}
7297

7398
public void onNeighborChanged(@NotNull EnumFacing facing) {
74-
this.neighbors[facing.getIndex()] = this;
99+
this.neighbors.set(facing.getIndex(), INVALID);
75100
}
76101
}

src/main/java/gregtech/api/metatileentity/SyncedTileEntityBase.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
1414
import net.minecraft.tileentity.TileEntity;
1515
import net.minecraft.util.EnumFacing;
16+
import net.minecraft.world.WorldServer;
1617
import net.minecraftforge.common.util.Constants;
1718

1819
import io.netty.buffer.ByteBuf;
@@ -25,6 +26,7 @@
2526

2627
public abstract class SyncedTileEntityBase extends BlockStateTileEntity implements ISyncedTileEntity {
2728

29+
public static final int SIZE_THRESHOLD = 10;
2830
private final PacketDataList updates = new PacketDataList();
2931

3032
public @Nullable TileEntity getNeighbor(EnumFacing facing) {
@@ -57,7 +59,26 @@ public void addPacketsFrom(SyncedTileEntityBase syncedTileEntityBase) {
5759
private void notifyWorld() {
5860
@SuppressWarnings("deprecation")
5961
IBlockState blockState = getBlockType().getStateFromMeta(getBlockMetadata());
60-
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
62+
if (canNotifyWorld()) {
63+
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
64+
}
65+
}
66+
67+
private boolean canNotifyWorld() {
68+
// short circuit with packet size to avoid too many hash lookups and instanceof casts
69+
if (updates.size() > SIZE_THRESHOLD && getWorld() instanceof WorldServer server) {
70+
int x = getPos().getX() >> 4;
71+
int z = getPos().getZ() >> 4;
72+
if (server.getPlayerChunkMap().contains(x, z)) {
73+
return true;
74+
} else {
75+
// cannot send, so clear
76+
updates.clear();
77+
return false;
78+
}
79+
}
80+
// assume we can send data regardless
81+
return true;
6182
}
6283

6384
@Override

src/main/java/gregtech/api/network/PacketDataList.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.Arrays;
9+
810
/**
911
* An optimised data structure backed by two arrays.
1012
* This is essentially equivalent to <code>List<Pair<Integer, byte[]>></code>, but more efficient.
@@ -84,9 +86,8 @@ public boolean isEmpty() {
8486
* remove all data packets
8587
*/
8688
public void clear() {
87-
for (int i = 0; i < this.size; i++) {
88-
this.data[i] = null;
89-
}
89+
Arrays.fill(this.discriminators, 0);
90+
Arrays.fill(this.data, null);
9091
this.size = 0;
9192
}
9293

src/main/java/gregtech/api/pipenet/block/BlockPipe.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ public BlockFaceShape getBlockFaceShape(@NotNull IBlockAccess worldIn, @NotNull
564564
}
565565

566566
@Override
567-
public boolean recolorBlock(World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
567+
public boolean recolorBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
568568
@NotNull EnumDyeColor color) {
569-
IPipeTile<PipeType, NodeDataType> tileEntityPipe = (IPipeTile<PipeType, NodeDataType>) world.getTileEntity(pos);
569+
IPipeTile<PipeType, NodeDataType> tileEntityPipe = getPipeTileEntity(world, pos);
570570
if (tileEntityPipe != null && tileEntityPipe.getPipeType() != null &&
571571
tileEntityPipe.getPipeType().isPaintable() &&
572572
tileEntityPipe.getPaintingColor() != color.colorValue) {
@@ -588,6 +588,7 @@ public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(IBlockAccess world, B
588588
return getPipeTileEntity(tileEntityAtPos);
589589
}
590590

591+
@Nullable
591592
public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(TileEntity tileEntityAtPos) {
592593
if (tileEntityAtPos instanceof IPipeTile &&
593594
isThisPipeBlock(((IPipeTile<PipeType, NodeDataType>) tileEntityAtPos).getPipeBlock())) {

src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Material getFrameMaterial() {
8181

8282
public void setFrameMaterial(@Nullable Material frameMaterial) {
8383
this.frameMaterial = frameMaterial;
84-
if (world != null && world.isRemote) {
84+
if (world != null && !world.isRemote) {
8585
writeCustomData(UPDATE_FRAME_MATERIAL, buf -> {
8686
buf.writeVarInt(frameMaterial == null ? -1 : frameMaterial.getRegistry().getNetworkId());
8787
buf.writeVarInt(frameMaterial == null ? -1 : frameMaterial.getId());
@@ -278,6 +278,7 @@ public void setFaceBlocked(EnumFacing side, boolean blocked) {
278278

279279
@Override
280280
public boolean isFaceBlocked(EnumFacing side) {
281+
if (side == null) return true; // says hey, you can't insert from nowhere
281282
return isFaceBlocked(blockedConnections, side);
282283
}
283284

src/main/java/gregtech/api/util/world/DummyWorld.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.minecraftforge.fml.common.Optional.Method;
1616
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
1717

18+
import dev.redstudio.alfheim.lighting.LightingEngine;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021

@@ -116,4 +117,9 @@ public int getLightFromNeighborsFor(EnumSkyBlock type, BlockPos pos) {
116117
public int alfheim$getLight(BlockPos pos, boolean checkNeighbors) {
117118
return 15;
118119
}
120+
121+
@Method(modid = Mods.Names.ALFHEIM)
122+
public LightingEngine getAlfheim$lightingEngine() {
123+
return null;
124+
}
119125
}

src/main/java/gregtech/client/model/pipeline/VertexLighterFlatSpecial.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,6 @@ protected void processQuad() {
170170
tint = -1;
171171
}
172172

173-
// This was copied over from VertexLighterFlat because the tint parameter shouldn't be a float
174-
protected static void updateColor(float[] normal, float[] color, float x, float y, float z, int tint,
175-
int multiplier) {
176-
if (tint != -1) {
177-
color[0] *= (float) (multiplier >> 0x10 & 0xFF) / 0xFF;
178-
color[1] *= (float) (multiplier >> 0x8 & 0xFF) / 0xFF;
179-
color[2] *= (float) (multiplier & 0xFF) / 0xFF;
180-
}
181-
}
182-
183173
@Override
184174
public void setQuadTint(int tint) {
185175
this.tint = tint;

src/main/java/gregtech/client/renderer/texture/custom/ClipboardRenderer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.client.renderer.texture.TextureMap;
1313
import net.minecraft.util.EnumFacing;
1414
import net.minecraft.util.ResourceLocation;
15+
import net.minecraft.world.World;
1516
import net.minecraftforge.fml.common.FMLCommonHandler;
1617
import net.minecraftforge.fml.relauncher.Side;
1718
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -74,7 +75,8 @@ public static void renderBoard(CCRenderState renderState, Matrix4 translation, I
7475
translation.translate(0.5, 0.5, 0.5);
7576
translation.rotate(Math.toRadians(90.0 * rotations.indexOf(rotation)), Rotation.axes[1]);
7677
translation.translate(-0.5, -0.5, -0.5);
77-
78+
World world = clipboard.getWorld();
79+
if (world != null) renderState.setBrightness(world, clipboard.getPos());
7880
// Render Clipboard
7981
for (EnumFacing renderSide : EnumFacing.VALUES) {
8082
boxTextureMap.forEach((box, sprite) -> Textures.renderFace(renderState, translation, pipeline, renderSide,
@@ -89,7 +91,17 @@ public static void renderGUI(double x, double y, double z, EnumFacing rotation,
8991
GlStateManager.pushMatrix();
9092
float lastBrightnessX = OpenGlHelper.lastBrightnessX;
9193
float lastBrightnessY = OpenGlHelper.lastBrightnessY;
92-
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
94+
95+
float lx = 240, ly = 240;
96+
World world = clipboard.getWorld();
97+
if (world != null) {
98+
int light = world.getCombinedLight(clipboard.getPos(), 0);
99+
100+
lx = (float) light % 0x10000;
101+
ly = (float) light / 0x10000;
102+
}
103+
104+
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lx, ly);
93105
RenderHelper.disableStandardItemLighting();
94106

95107
// All of these are done in reverse order, by the way, if you're reviewing this :P

0 commit comments

Comments
 (0)