diff --git a/build.gradle b/build.gradle index bdc52ff63..9c5ec083d 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: 'org.spongepowered.mixin' -// apply plugin: 'org.parchmentmc.librarian.forgegradle' +apply plugin: 'org.parchmentmc.librarian.forgegradle' boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false'); // jozu: I use a gradle workspace with both projects. @@ -39,8 +39,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { - // mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}" - mappings channel: 'official', version: "${minecraft_version}" + mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}" accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') runs { diff --git a/gradle.properties b/gradle.properties index b0097b068..dab5c2870 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon = false # mod version info mod_version = 0.4a minecraft_version = 1.18.1 -forge_version = 39.0.5 +forge_version = 39.0.8 # build dependency versions forgegradle_version = 5.1.+ @@ -15,11 +15,11 @@ mixin_version = 0.8.5 librarian_version = 1.+ shadow_version = 7.1.0 cursegradle_version = 1.4.0 -parchment_version = 2021.10.31 +parchment_version = 2021.12.19 # dependency versions registrate_version = MC1.18-1.0.21 -flywheel_version = 1.18-0.4.2-rc.26 +flywheel_version = 1.18-0.5.0.28 jei_minecraft_version = 1.18 jei_version = 9.0.0.40 diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index d69f2d148..44ee6b84e 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -2125,7 +2125,7 @@ d080b1b25e5bc8baf5aee68691b08c7f12ece3b0 assets/create/models/item/windmill_bear a80fb25a0b655e76be986b5b49fcb0f03461a1ab assets/create/models/item/zinc_nugget.json b1689617190c05ef34bd18456b0c7ae09bb3210f assets/create/models/item/zinc_ore.json 5049f72c327a88f175f6f9425909e098fc711100 assets/create/sounds.json -5d0cc4c0255dc241e61c173b31ddca70c88d08e4 data/create/advancements/aesthetics.json +0f1b4b980afba9bf2caf583b88e261bba8b10313 data/create/advancements/aesthetics.json 613e64b44bed959da899fdd54c1cacb227fb33f2 data/create/advancements/andesite_alloy.json 81885c6bfb85792c88aaa7c9b70f58832945d31f data/create/advancements/andesite_casing.json 83c046bd200623933545c9e4326f782fb02c87fa data/create/advancements/arm_blaze_burner.json @@ -5210,7 +5210,7 @@ ff1900963bc4cd8ceffa78d58ef1952ceacb2fb7 data/forge/tags/items/storage_blocks/br 9f7a428085b1aac66da32a43e9d51c7efc1f0d81 data/minecraft/tags/blocks/beacon_base_blocks.json 69f596fcb065e26b02ce246760432b5174191b76 data/minecraft/tags/blocks/impermeable.json 59681910c06f8b7385c6641a409d352056235506 data/minecraft/tags/blocks/mineable/axe.json -7d948c24605906ac26e44258f8eac04aa1ddfac4 data/minecraft/tags/blocks/mineable/pickaxe.json +f8c66b3808efb61d2d928748783bb7eb8a1357f9 data/minecraft/tags/blocks/mineable/pickaxe.json e157c1d3af30e409e34bbefbe15a037e6e1c8daa data/minecraft/tags/blocks/needs_iron_tool.json a08f67865337f62601c5e333b4011382d10020e4 data/minecraft/tags/blocks/needs_stone_tool.json 6bcabbc1c0479caa80a0ebc676bb34ce0052efb0 data/minecraft/tags/blocks/rails.json diff --git a/src/generated/resources/data/create/advancements/aesthetics.json b/src/generated/resources/data/create/advancements/aesthetics.json index 59a86f429..d723cbe38 100644 --- a/src/generated/resources/data/create/advancements/aesthetics.json +++ b/src/generated/resources/data/create/advancements/aesthetics.json @@ -28,8 +28,8 @@ "trigger": "create:bracket_apply", "conditions": { "accepted_entries": [ - "create:large_cogwheel", - "create:cogwheel" + "create:cogwheel", + "create:large_cogwheel" ] } }, diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index bc1ae4df2..25adc0293 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -189,94 +189,262 @@ "create:waxed_weathered_copper_tile_stairs", "create:waxed_oxidized_copper_tile_stairs", "create:cut_granite", + "create:cut_granite_stairs", + "create:cut_granite_slab", + "create:cut_granite_wall", "create:polished_cut_granite", + "create:polished_cut_granite_stairs", + "create:polished_cut_granite_slab", + "create:polished_cut_granite_wall", "create:cut_granite_bricks", + "create:cut_granite_brick_stairs", + "create:cut_granite_brick_slab", + "create:cut_granite_brick_wall", "create:small_granite_bricks", + "create:small_granite_brick_stairs", + "create:small_granite_brick_slab", + "create:small_granite_brick_wall", "create:layered_granite", "create:granite_pillar", "create:cut_diorite", + "create:cut_diorite_stairs", + "create:cut_diorite_slab", + "create:cut_diorite_wall", "create:polished_cut_diorite", + "create:polished_cut_diorite_stairs", + "create:polished_cut_diorite_slab", + "create:polished_cut_diorite_wall", "create:cut_diorite_bricks", + "create:cut_diorite_brick_stairs", + "create:cut_diorite_brick_slab", + "create:cut_diorite_brick_wall", "create:small_diorite_bricks", + "create:small_diorite_brick_stairs", + "create:small_diorite_brick_slab", + "create:small_diorite_brick_wall", "create:layered_diorite", "create:diorite_pillar", "create:cut_andesite", + "create:cut_andesite_stairs", + "create:cut_andesite_slab", + "create:cut_andesite_wall", "create:polished_cut_andesite", + "create:polished_cut_andesite_stairs", + "create:polished_cut_andesite_slab", + "create:polished_cut_andesite_wall", "create:cut_andesite_bricks", + "create:cut_andesite_brick_stairs", + "create:cut_andesite_brick_slab", + "create:cut_andesite_brick_wall", "create:small_andesite_bricks", + "create:small_andesite_brick_stairs", + "create:small_andesite_brick_slab", + "create:small_andesite_brick_wall", "create:layered_andesite", "create:andesite_pillar", "create:cut_calcite", + "create:cut_calcite_stairs", + "create:cut_calcite_slab", + "create:cut_calcite_wall", "create:polished_cut_calcite", + "create:polished_cut_calcite_stairs", + "create:polished_cut_calcite_slab", + "create:polished_cut_calcite_wall", "create:cut_calcite_bricks", + "create:cut_calcite_brick_stairs", + "create:cut_calcite_brick_slab", + "create:cut_calcite_brick_wall", "create:small_calcite_bricks", + "create:small_calcite_brick_stairs", + "create:small_calcite_brick_slab", + "create:small_calcite_brick_wall", "create:layered_calcite", "create:calcite_pillar", "create:cut_dripstone", + "create:cut_dripstone_stairs", + "create:cut_dripstone_slab", + "create:cut_dripstone_wall", "create:polished_cut_dripstone", + "create:polished_cut_dripstone_stairs", + "create:polished_cut_dripstone_slab", + "create:polished_cut_dripstone_wall", "create:cut_dripstone_bricks", + "create:cut_dripstone_brick_stairs", + "create:cut_dripstone_brick_slab", + "create:cut_dripstone_brick_wall", "create:small_dripstone_bricks", + "create:small_dripstone_brick_stairs", + "create:small_dripstone_brick_slab", + "create:small_dripstone_brick_wall", "create:layered_dripstone", "create:dripstone_pillar", "create:cut_deepslate", + "create:cut_deepslate_stairs", + "create:cut_deepslate_slab", + "create:cut_deepslate_wall", "create:polished_cut_deepslate", + "create:polished_cut_deepslate_stairs", + "create:polished_cut_deepslate_slab", + "create:polished_cut_deepslate_wall", "create:cut_deepslate_bricks", + "create:cut_deepslate_brick_stairs", + "create:cut_deepslate_brick_slab", + "create:cut_deepslate_brick_wall", "create:small_deepslate_bricks", + "create:small_deepslate_brick_stairs", + "create:small_deepslate_brick_slab", + "create:small_deepslate_brick_wall", "create:layered_deepslate", "create:deepslate_pillar", "create:cut_tuff", + "create:cut_tuff_stairs", + "create:cut_tuff_slab", + "create:cut_tuff_wall", "create:polished_cut_tuff", + "create:polished_cut_tuff_stairs", + "create:polished_cut_tuff_slab", + "create:polished_cut_tuff_wall", "create:cut_tuff_bricks", + "create:cut_tuff_brick_stairs", + "create:cut_tuff_brick_slab", + "create:cut_tuff_brick_wall", "create:small_tuff_bricks", + "create:small_tuff_brick_stairs", + "create:small_tuff_brick_slab", + "create:small_tuff_brick_wall", "create:layered_tuff", "create:tuff_pillar", "create:asurine", "create:cut_asurine", + "create:cut_asurine_stairs", + "create:cut_asurine_slab", + "create:cut_asurine_wall", "create:polished_cut_asurine", + "create:polished_cut_asurine_stairs", + "create:polished_cut_asurine_slab", + "create:polished_cut_asurine_wall", "create:cut_asurine_bricks", + "create:cut_asurine_brick_stairs", + "create:cut_asurine_brick_slab", + "create:cut_asurine_brick_wall", "create:small_asurine_bricks", + "create:small_asurine_brick_stairs", + "create:small_asurine_brick_slab", + "create:small_asurine_brick_wall", "create:layered_asurine", "create:asurine_pillar", "create:crimsite", "create:cut_crimsite", + "create:cut_crimsite_stairs", + "create:cut_crimsite_slab", + "create:cut_crimsite_wall", "create:polished_cut_crimsite", + "create:polished_cut_crimsite_stairs", + "create:polished_cut_crimsite_slab", + "create:polished_cut_crimsite_wall", "create:cut_crimsite_bricks", + "create:cut_crimsite_brick_stairs", + "create:cut_crimsite_brick_slab", + "create:cut_crimsite_brick_wall", "create:small_crimsite_bricks", + "create:small_crimsite_brick_stairs", + "create:small_crimsite_brick_slab", + "create:small_crimsite_brick_wall", "create:layered_crimsite", "create:crimsite_pillar", "create:limestone", "create:cut_limestone", + "create:cut_limestone_stairs", + "create:cut_limestone_slab", + "create:cut_limestone_wall", "create:polished_cut_limestone", + "create:polished_cut_limestone_stairs", + "create:polished_cut_limestone_slab", + "create:polished_cut_limestone_wall", "create:cut_limestone_bricks", + "create:cut_limestone_brick_stairs", + "create:cut_limestone_brick_slab", + "create:cut_limestone_brick_wall", "create:small_limestone_bricks", + "create:small_limestone_brick_stairs", + "create:small_limestone_brick_slab", + "create:small_limestone_brick_wall", "create:layered_limestone", "create:limestone_pillar", "create:ochrum", "create:cut_ochrum", + "create:cut_ochrum_stairs", + "create:cut_ochrum_slab", + "create:cut_ochrum_wall", "create:polished_cut_ochrum", + "create:polished_cut_ochrum_stairs", + "create:polished_cut_ochrum_slab", + "create:polished_cut_ochrum_wall", "create:cut_ochrum_bricks", + "create:cut_ochrum_brick_stairs", + "create:cut_ochrum_brick_slab", + "create:cut_ochrum_brick_wall", "create:small_ochrum_bricks", + "create:small_ochrum_brick_stairs", + "create:small_ochrum_brick_slab", + "create:small_ochrum_brick_wall", "create:layered_ochrum", "create:ochrum_pillar", "create:scoria", "create:cut_scoria", + "create:cut_scoria_stairs", + "create:cut_scoria_slab", + "create:cut_scoria_wall", "create:polished_cut_scoria", + "create:polished_cut_scoria_stairs", + "create:polished_cut_scoria_slab", + "create:polished_cut_scoria_wall", "create:cut_scoria_bricks", + "create:cut_scoria_brick_stairs", + "create:cut_scoria_brick_slab", + "create:cut_scoria_brick_wall", "create:small_scoria_bricks", + "create:small_scoria_brick_stairs", + "create:small_scoria_brick_slab", + "create:small_scoria_brick_wall", "create:layered_scoria", "create:scoria_pillar", "create:scorchia", "create:cut_scorchia", + "create:cut_scorchia_stairs", + "create:cut_scorchia_slab", + "create:cut_scorchia_wall", "create:polished_cut_scorchia", + "create:polished_cut_scorchia_stairs", + "create:polished_cut_scorchia_slab", + "create:polished_cut_scorchia_wall", "create:cut_scorchia_bricks", + "create:cut_scorchia_brick_stairs", + "create:cut_scorchia_brick_slab", + "create:cut_scorchia_brick_wall", "create:small_scorchia_bricks", + "create:small_scorchia_brick_stairs", + "create:small_scorchia_brick_slab", + "create:small_scorchia_brick_wall", "create:layered_scorchia", "create:scorchia_pillar", "create:veridium", "create:cut_veridium", + "create:cut_veridium_stairs", + "create:cut_veridium_slab", + "create:cut_veridium_wall", "create:polished_cut_veridium", + "create:polished_cut_veridium_stairs", + "create:polished_cut_veridium_slab", + "create:polished_cut_veridium_wall", "create:cut_veridium_bricks", + "create:cut_veridium_brick_stairs", + "create:cut_veridium_brick_slab", + "create:cut_veridium_brick_wall", "create:small_veridium_bricks", + "create:small_veridium_brick_stairs", + "create:small_veridium_brick_slab", + "create:small_veridium_brick_wall", "create:layered_veridium", "create:veridium_pillar" ] diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 5c274fc60..5b78108e3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -185,12 +185,17 @@ public class KineticTileEntity extends SmartTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) { if (hasNetwork()) getOrCreateNetwork().remove(this); detachKinetics(); } - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 425152021..296e434ae 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -42,7 +42,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer, Batched { } @Override - public VertexFormat format() { + public BufferLayout getLayout() { return AllInstanceFormats.BELT; } @Override public StructWriter getWriter(VecBuffer backing) { - return new UnsafeBeltWriter(backing, this); + return new BeltWriterUnsafe(backing, this); } @Override @@ -34,7 +37,26 @@ public class BeltType implements Instanced, Batched { } @Override - public BatchingTransformer getTransformer(Model model) { - return null; + public void transform(BeltData d, ModelTransformer.Params b) { + float spriteHeight = d.maxV - d.minV; + double scroll = d.rotationalSpeed * AnimationTickHolder.getRenderTime() / (31.5 * 16) + d.rotationOffset; + scroll = scroll - Math.floor(scroll); + scroll = scroll * spriteHeight * RenderMath.f(d.scrollMult); + + float finalScroll = (float) scroll; + b.shiftUV((builder, u, v) -> { + float targetU = u - d.sourceU + d.minU; + float targetV = v - d.sourceV + d.minV + + finalScroll; + builder.uv(targetU, targetV); + }); + + b.translate(d.x + 0.5, d.y + 0.5, d.z + 0.5) + .multiply(new Quaternion(d.qX, d.qY, d.qZ, d.qW)) + .unCentre() + .light(d.getPackedLight()); + if (KineticDebugger.isActive()) { + b.color(d.r, d.g, d.b, d.a); + } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeBeltWriter.java b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/BeltWriterUnsafe.java similarity index 52% rename from src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeBeltWriter.java rename to src/main/java/com/simibubi/create/content/contraptions/base/flwdata/BeltWriterUnsafe.java index 1bd4e3ac5..1cf570be5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeBeltWriter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/BeltWriterUnsafe.java @@ -4,27 +4,16 @@ import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; -public class UnsafeBeltWriter extends UnsafeBufferWriter { - public UnsafeBeltWriter(VecBuffer backingBuffer, StructType vertexType) { +public class BeltWriterUnsafe extends KineticWriterUnsafe { + public BeltWriterUnsafe(VecBuffer backingBuffer, StructType vertexType) { super(backingBuffer, vertexType); } @Override - public void write(BeltData d) { + protected void writeInternal(BeltData d) { + super.writeInternal(d); long addr = writePointer; - MemoryUtil.memPutByte(addr, d.blockLight); - MemoryUtil.memPutByte(addr + 1, d.skyLight); - MemoryUtil.memPutByte(addr + 2, d.r); - MemoryUtil.memPutByte(addr + 3, d.g); - MemoryUtil.memPutByte(addr + 4, d.b); - MemoryUtil.memPutByte(addr + 5, d.a); - MemoryUtil.memPutFloat(addr + 6, d.x); - MemoryUtil.memPutFloat(addr + 10, d.y); - MemoryUtil.memPutFloat(addr + 14, d.z); - MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed); - MemoryUtil.memPutFloat(addr + 22, d.rotationOffset); MemoryUtil.memPutFloat(addr + 26, d.qX); MemoryUtil.memPutFloat(addr + 30, d.qY); MemoryUtil.memPutFloat(addr + 34, d.qZ); @@ -36,7 +25,5 @@ public class UnsafeBeltWriter extends UnsafeBufferWriter { MemoryUtil.memPutFloat(addr + 58, d.maxU); MemoryUtil.memPutFloat(addr + 62, d.maxV); MemoryUtil.memPutByte(addr + 66, d.scrollMult); - - advance(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/KineticWriterUnsafe.java b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/KineticWriterUnsafe.java new file mode 100644 index 000000000..d450b1d6a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/KineticWriterUnsafe.java @@ -0,0 +1,24 @@ +package com.simibubi.create.content.contraptions.base.flwdata; + +import org.lwjgl.system.MemoryUtil; + +import com.jozufozu.flywheel.api.struct.StructType; +import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; +import com.jozufozu.flywheel.core.materials.BasicWriterUnsafe; + +public abstract class KineticWriterUnsafe extends BasicWriterUnsafe { + public KineticWriterUnsafe(VecBuffer backingBuffer, StructType vertexType) { + super(backingBuffer, vertexType); + } + + @Override + protected void writeInternal(D d) { + super.writeInternal(d); + long addr = writePointer; + MemoryUtil.memPutFloat(addr + 6, d.x); + MemoryUtil.memPutFloat(addr + 10, d.y); + MemoryUtil.memPutFloat(addr + 14, d.z); + MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed); + MemoryUtil.memPutFloat(addr + 22, d.rotationOffset); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingType.java b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingType.java index 94e05590f..84e8f5d9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingType.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingType.java @@ -1,14 +1,17 @@ package com.simibubi.create.content.contraptions.base.flwdata; import com.jozufozu.flywheel.api.struct.Batched; -import com.jozufozu.flywheel.api.struct.BatchingTransformer; import com.jozufozu.flywheel.api.struct.Instanced; import com.jozufozu.flywheel.api.struct.StructWriter; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.core.layout.BufferLayout; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.core.model.Model; +import com.jozufozu.flywheel.core.model.ModelTransformer; +import com.jozufozu.flywheel.util.RenderMath; +import com.mojang.math.Vector3f; +import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllProgramSpecs; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.resources.ResourceLocation; @@ -19,13 +22,13 @@ public class RotatingType implements Instanced, Batched getWriter(VecBuffer backing) { - return new UnsafeRotatingWriter(backing, this); + return new RotatingWriterUnsafe(backing, this); } @Override @@ -34,7 +37,17 @@ public class RotatingType implements Instanced, Batched getTransformer(Model model) { - return null; + public void transform(RotatingData d, ModelTransformer.Params b) { + float angle = ((AnimationTickHolder.getRenderTime() * d.rotationalSpeed * 3f / 10 + d.rotationOffset) % 360); + + Vector3f axis = new Vector3f(RenderMath.f(d.rotationAxisX), RenderMath.f(d.rotationAxisY), RenderMath.f(d.rotationAxisZ)); + b.light(d.getPackedLight()) + .translate(d.x + 0.5, d.y + 0.5, d.z + 0.5) + .multiply(axis.rotationDegrees(angle)) + .unCentre(); + + if (KineticDebugger.isActive()) { + b.color(d.r, d.g, d.b, d.a); + } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingWriterUnsafe.java b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingWriterUnsafe.java new file mode 100644 index 000000000..b57e21d2a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/RotatingWriterUnsafe.java @@ -0,0 +1,21 @@ +package com.simibubi.create.content.contraptions.base.flwdata; + +import org.lwjgl.system.MemoryUtil; + +import com.jozufozu.flywheel.api.struct.StructType; +import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; + +public class RotatingWriterUnsafe extends KineticWriterUnsafe { + public RotatingWriterUnsafe(VecBuffer backingBuffer, StructType vertexType) { + super(backingBuffer, vertexType); + } + + @Override + protected void writeInternal(RotatingData d) { + super.writeInternal(d); + long addr = writePointer; + MemoryUtil.memPutByte(addr + 26, d.rotationAxisX); + MemoryUtil.memPutByte(addr + 27, d.rotationAxisY); + MemoryUtil.memPutByte(addr + 28, d.rotationAxisZ); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeRotatingWriter.java b/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeRotatingWriter.java deleted file mode 100644 index 8b0f13835..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/base/flwdata/UnsafeRotatingWriter.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.simibubi.create.content.contraptions.base.flwdata; - -import org.lwjgl.system.MemoryUtil; - -import com.jozufozu.flywheel.api.struct.StructType; -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; - -public class UnsafeRotatingWriter extends UnsafeBufferWriter { - public UnsafeRotatingWriter(VecBuffer backingBuffer, StructType vertexType) { - super(backingBuffer, vertexType); - } - - @Override - public void write(RotatingData d) { - long addr = writePointer; - MemoryUtil.memPutByte(addr, d.blockLight); - MemoryUtil.memPutByte(addr + 1, d.skyLight); - MemoryUtil.memPutByte(addr + 2, d.r); - MemoryUtil.memPutByte(addr + 3, d.g); - MemoryUtil.memPutByte(addr + 4, d.b); - MemoryUtil.memPutByte(addr + 5, d.a); - MemoryUtil.memPutFloat(addr + 6, d.x); - MemoryUtil.memPutFloat(addr + 10, d.y); - MemoryUtil.memPutFloat(addr + 14, d.z); - MemoryUtil.memPutFloat(addr + 18, d.rotationalSpeed); - MemoryUtil.memPutFloat(addr + 22, d.rotationOffset); - MemoryUtil.memPutByte(addr + 26, d.rotationAxisX); - MemoryUtil.memPutByte(addr + 27, d.rotationAxisY); - MemoryUtil.memPutByte(addr + 28, d.rotationAxisZ); - - advance(); - } -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 9690f4eba..b623d9200 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -37,7 +37,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { @OnlyIn(value = Dist.CLIENT) public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffer) { - if (!Backend.getInstance().canUseInstancing()) + if (!Backend.isOn()) DrillRenderer.renderInContraption(context, renderWorld, matrices, buffer); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index a2c3716ca..3fcc935bc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -58,8 +58,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { @Override public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffers) { - if (!Backend.getInstance() - .canUseInstancing()) + if (!Backend.isOn()) HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/ActorType.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/ActorType.java index f664a6698..ad55be8cc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/ActorType.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/ActorType.java @@ -1,12 +1,11 @@ package com.simibubi.create.content.contraptions.components.actors.flwdata; import com.jozufozu.flywheel.api.struct.Batched; -import com.jozufozu.flywheel.api.struct.BatchingTransformer; import com.jozufozu.flywheel.api.struct.Instanced; import com.jozufozu.flywheel.api.struct.StructWriter; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.core.layout.BufferLayout; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.core.model.Model; +import com.jozufozu.flywheel.core.model.ModelTransformer; import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllProgramSpecs; @@ -19,7 +18,7 @@ public class ActorType implements Instanced, Batched { } @Override - public VertexFormat format() { + public BufferLayout getLayout() { return AllInstanceFormats.ACTOR; } @@ -34,7 +33,7 @@ public class ActorType implements Instanced, Batched { } @Override - public BatchingTransformer getTransformer(Model model) { - return null; + public void transform(ActorData d, ModelTransformer.Params b) { + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/UnsafeActorWriter.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/UnsafeActorWriter.java index 0a7184910..4479e800d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/UnsafeActorWriter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/flwdata/UnsafeActorWriter.java @@ -12,7 +12,7 @@ public class UnsafeActorWriter extends UnsafeBufferWriter { } @Override - public void write(ActorData d) { + protected void writeInternal(ActorData d) { long addr = writePointer; MemoryUtil.memPutFloat(addr, d.x); MemoryUtil.memPutFloat(addr + 4, d.y); @@ -31,6 +31,5 @@ public class UnsafeActorWriter extends UnsafeBufferWriter { MemoryUtil.memPutByte(addr + 38, d.rotationCenterY); MemoryUtil.memPutByte(addr + 39, d.rotationCenterZ); MemoryUtil.memPutFloat(addr + 40, d.speed); - advance(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index a35f0d13d..72a648e76 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -169,8 +169,7 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer renderItem(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; renderComponents(te, partialTicks, ms, buffer, light, overlay); } @@ -113,7 +113,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { VertexConsumer vb = buffer.getBuffer(RenderType.solid()); - if (!Backend.getInstance().canUseInstancing(te.getLevel())) { + if (!Backend.canUseInstancing(te.getLevel())) { KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); } @@ -193,10 +193,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer IRotate def = (IRotate) context.state.getBlock(); axis = def.getRotationAxis(context.state); } - + float time = AnimationTickHolder.getRenderTime(context.world) / 20; float angle = (time * speed) % 360; - + new MatrixTransformStack(m) .centre() .rotateY(axis == Axis.Z ? 90 : 0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 274f95237..73b918fa7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -28,7 +28,7 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; Direction direction = te.getBlockState() .getValue(FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index a871b4b42..7fd70c96b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -36,7 +36,7 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; BlockState blockState = te.getBlockState(); FlywheelTileEntity wte = (FlywheelTileEntity) te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java index 1c9c904bd..64984443a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java @@ -22,7 +22,7 @@ public class EngineRenderer extends SafeTileEntityRe protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; Block block = te.getBlockState() .getBlock(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index 5934fa714..d96a4827b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -86,10 +86,15 @@ public class EngineTileEntity extends SmartTileEntity implements FlywheelRendere @Override public void setRemoved() { - detachWheel(); super.setRemoved(); } + @Override + protected void setRemovedNotDueToChunkUnload() { + detachWheel(); + super.setRemovedNotDueToChunkUnload(); + } + protected void refreshWheelSpeed() { if (poweredWheel == null) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 83d05442f..ec59b2037 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -31,7 +31,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; BlockState blockState = te.getBlockState(); MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 5523a7b2e..43e315100 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -31,7 +31,7 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; BlockState blockState = te.getBlockState(); float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 149be2e09..5896963ab 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -46,8 +46,7 @@ public class SawRenderer extends SafeTileEntityRenderer { renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance() - .canUseInstancing(te.getLevel())) + if (Backend.canUseInstancing(te.getLevel())) return; renderShaft(te, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index 524d44b9d..e5e405999 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -224,12 +224,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit return; } - for (Iterator> iterator = collidingEntities.entrySet() - .iterator(); iterator.hasNext();) - if (iterator.next() - .getValue() - .incrementAndGet() > 3) - iterator.remove(); + collidingEntities.entrySet().removeIf(e -> e.getValue().incrementAndGet() > 3); xo = getX(); yo = getY(); @@ -642,7 +637,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit public boolean hasExactlyOnePlayerPassenger() { return false; } - + @OnlyIn(Dist.CLIENT) public abstract void doLocalTransforms(float partialTicks, PoseStack[] matrixStacks); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 66ad205e5..312afd33c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -25,8 +25,8 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllInteractionBehaviours; import com.simibubi.create.AllMovementBehaviours; @@ -874,9 +874,9 @@ public abstract class Contraption { } ListTag paletteNBT = new ListTag(); - for(int i = 0; i < palette.getSize(); ++i) + for(int i = 0; i < palette.getSize(); ++i) paletteNBT.add(NbtUtils.writeBlockState(palette.values.byId(i))); - + compound.put("Palette", paletteNBT); compound.put("BlockList", blockList); @@ -891,7 +891,7 @@ public abstract class Contraption { palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> { throw new IllegalStateException("Palette Map index exceeded maximum"); }); - + ListTag list = c.getList("Palette", 10); palette.values.clear(); for (int i = 0; i < list.size(); ++i) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 95ea67501..76ac67287 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.jozufozu.flywheel.light.GPULightVolume; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightUpdater; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 363cd4afa..1e0cd0d8a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.MovingListener; import com.simibubi.create.foundation.config.AllConfigs; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java index 4c9712276..6373f76e1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/OrientedContraptionEntity.java @@ -74,17 +74,12 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { public float prevPitch; public float pitch; - public float targetPitch; - - // When placed using a contraption item - private float initialYawOffset; public OrientedContraptionEntity(EntityType type, Level world) { super(type, world); motionBeforeStall = Vec3.ZERO; attachedExtraInventories = false; isSerializingFurnaceCart = false; - initialYawOffset = -1; } public static OrientedContraptionEntity create(Level world, Contraption contraption, Direction initialOrientation) { @@ -112,11 +107,6 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { return entityData.get(INITIAL_ORIENTATION); } - public void deferOrientation(Direction newInitialAngle) { - entityData.set(INITIAL_ORIENTATION, Direction.UP); - yaw = initialYawOffset = newInitialAngle.toYRot(); - } - @Override public float getYawOffset() { return getInitialYaw(); @@ -398,7 +388,8 @@ public class OrientedContraptionEntity extends AbstractContraptionEntity { prevYaw = yaw; float maxApproachSpeed = (float) (motion.length() * 12f / (Math.max(1, getBoundingBox().getXsize() / 6f))); - float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw); + float yawHint = AngleHelper.getShortestAngleDiff(yaw, yawFromVector(locationDiff)); + float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw, yawHint); approach = Mth.clamp(approach, -maxApproachSpeed, maxApproachSpeed); yaw += approach; if (Math.abs(AngleHelper.getShortestAngleDiff(yaw, targetYaw)) < 1f) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java index 16bd4e82a..1f2a06669 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/AnchoredLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 1bd85cc7f..659152cce 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -27,7 +27,7 @@ public class BearingRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; super.renderSafe(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index 2ff025ffa..633495afc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -362,9 +362,14 @@ public class ClockworkBearingTileEntity extends KineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index efe0f72d9..19d35104a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -59,9 +59,14 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index f00e600f3..91735760f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -34,7 +34,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { @OnlyIn(Dist.CLIENT) public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffer) { - if (Backend.getInstance().canUseInstancing()) return; + if (Backend.isOn()) return; Direction facing = context.state.getValue(BlockStateProperties.FACING); PartialModel top = AllBlockPartials.BEARING_TOP; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java index f4c3c8c27..cfb6a1d0e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java @@ -25,7 +25,7 @@ public class StickerRenderer extends SafeTileEntityRenderer { protected void renderSafe(StickerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; BlockState state = te.getBlockState(); SuperByteBuffer head = CachedBufferer.partial(AllBlockPartials.STICKER_HEAD, state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java index 9e52ea3ea..6e3e6fd44 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java @@ -31,7 +31,7 @@ public class GantryCarriageRenderer extends KineticTileEntityRenderer { int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; BlockState state = te.getBlockState(); Direction facing = state.getValue(GantryCarriageBlock.FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java index bd464c94c..dd7c8c3d1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java @@ -4,34 +4,25 @@ import com.jozufozu.flywheel.api.Instancer; import com.jozufozu.flywheel.api.MaterialGroup; import com.jozufozu.flywheel.api.MaterialManager; import com.jozufozu.flywheel.api.instance.ITickableInstance; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; -import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; -import com.jozufozu.flywheel.core.model.Model; -import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Quaternion; import com.simibubi.create.AllItems; -import com.simibubi.create.AllStitchedTextures; import com.simibubi.create.Create; import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.LightLayer; -import net.minecraft.world.phys.Vec3; public class GlueInstance extends EntityInstance implements ITickableInstance { - private static final boolean USE_ATLAS = false; private static final ResourceLocation TEXTURE = Create.asResource("textures/entity/super_glue/slime.png"); private final Quaternion rotation; @@ -52,9 +43,9 @@ public class GlueInstance extends EntityInstance implements ITi } private Instancer getInstancer(MaterialManager materialManager, SuperGlueEntity entity) { - MaterialGroup group = USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE)); + MaterialGroup group = GlueModel.USE_ATLAS ? materialManager.defaultCutout() : materialManager.cutout(RenderType.entityCutout(TEXTURE)); - return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::new); + return group.material(Materials.ORIENTED).model(entity.getType(), GlueModel::get); } @Override @@ -95,75 +86,4 @@ public class GlueInstance extends EntityInstance implements ITi || AllItems.SUPER_GLUE.isIn(player.getOffhandItem()); } - public static class GlueModel implements Model { - - @Override - public String name() { - return "glue"; - } - - @Override - public void buffer(VertexConsumer buffer) { - Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal()); - Vec3 extension = diff.normalize() - .scale(1 / 32f - 1 / 128f); - - Vec3 plane = VecHelper.axisAlingedPlaneOf(diff); - Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z) - .getAxis(); - - Vec3 start = Vec3.ZERO.subtract(extension); - Vec3 end = Vec3.ZERO.add(extension); - - plane = plane.scale(1 / 2f); - Vec3 a1 = plane.add(start); - Vec3 b1 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a2 = plane.add(start); - Vec3 b2 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a3 = plane.add(start); - Vec3 b3 = plane.add(end); - plane = VecHelper.rotate(plane, -90, axis); - Vec3 a4 = plane.add(start); - Vec3 b4 = plane.add(end); - - float minU; - float maxU; - float minV; - float maxV; - - if (USE_ATLAS) { - TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get(); - minU = sprite.getU0(); - maxU = sprite.getU1(); - minV = sprite.getV0(); - maxV = sprite.getV1(); - } else { - minU = minV = 0; - maxU = maxV = 1; - } - - // inside quad - buffer.vertex(a1.x, a1.y, a1.z).normal(0, 0, -1f).uv(maxU, minV).endVertex(); - buffer.vertex(a2.x, a2.y, a2.z).normal(0, 0, -1f).uv(maxU, maxV).endVertex(); - buffer.vertex(a3.x, a3.y, a3.z).normal(0, 0, -1f).uv(minU, maxV).endVertex(); - buffer.vertex(a4.x, a4.y, a4.z).normal(0, 0, -1f).uv(minU, minV).endVertex(); - // outside quad - buffer.vertex(b4.x, b4.y, b4.z).normal(0, 0, 1f).uv(minU, minV).endVertex(); - buffer.vertex(b3.x, b3.y, b3.z).normal(0, 0, 1f).uv(minU, maxV).endVertex(); - buffer.vertex(b2.x, b2.y, b2.z).normal(0, 0, 1f).uv(maxU, maxV).endVertex(); - buffer.vertex(b1.x, b1.y, b1.z).normal(0, 0, 1f).uv(maxU, minV).endVertex(); - } - - @Override - public int vertexCount() { - return 8; - } - - @Override - public VertexFormat format() { - return Formats.UNLIT_MODEL; - } - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java new file mode 100644 index 000000000..0c8cd46df --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueModel.java @@ -0,0 +1,99 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import com.jozufozu.flywheel.core.Formats; +import com.jozufozu.flywheel.core.model.Model; +import com.jozufozu.flywheel.core.vertex.PosTexNormalWriterUnsafe; +import com.jozufozu.flywheel.api.vertex.VertexList; +import com.mojang.blaze3d.platform.MemoryTracker; +import com.simibubi.create.AllStitchedTextures; +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; + +public class GlueModel implements Model { + + public static final GlueModel INSTANCE = new GlueModel(); + static final boolean USE_ATLAS = false; + + public static GlueModel get() { + return INSTANCE; + } + + private final VertexList reader; + + private GlueModel() { + PosTexNormalWriterUnsafe writer = Formats.POS_TEX_NORMAL.createWriter(MemoryTracker.create(size())); + createGlueModel(writer); + reader = writer.intoReader(); + } + + @Override + public String name() { + return "glue"; + } + + @Override + public int vertexCount() { + return 8; + } + + @Override + public VertexList getReader() { + return reader; + } + + public static void createGlueModel(PosTexNormalWriterUnsafe buffer) { + Vec3 diff = Vec3.atLowerCornerOf(Direction.SOUTH.getNormal()); + Vec3 extension = diff.normalize() + .scale(1 / 32f - 1 / 128f); + + Vec3 plane = VecHelper.axisAlingedPlaneOf(diff); + Direction.Axis axis = Direction.getNearest(diff.x, diff.y, diff.z) + .getAxis(); + + Vec3 start = Vec3.ZERO.subtract(extension); + Vec3 end = Vec3.ZERO.add(extension); + + plane = plane.scale(1 / 2f); + Vec3 a1 = plane.add(start); + Vec3 b1 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a2 = plane.add(start); + Vec3 b2 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a3 = plane.add(start); + Vec3 b3 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vec3 a4 = plane.add(start); + Vec3 b4 = plane.add(end); + + float minU; + float maxU; + float minV; + float maxV; + + if (USE_ATLAS) { + TextureAtlasSprite sprite = AllStitchedTextures.SUPER_GLUE.get(); + minU = sprite.getU0(); + maxU = sprite.getU1(); + minV = sprite.getV0(); + maxV = sprite.getV1(); + } else { + minU = minV = 0; + maxU = maxV = 1; + } + + // inside quad + buffer.putVertex((float) a1.x, (float) a1.y, (float) a1.z, 0, 0, -1, maxU, minV); + buffer.putVertex((float) a2.x, (float) a2.y, (float) a2.z, 0, 0, -1, maxU, maxV); + buffer.putVertex((float) a3.x, (float) a3.y, (float) a3.z, 0, 0, -1, minU, maxV); + buffer.putVertex((float) a4.x, (float) a4.y, (float) a4.z, 0, 0, -1, minU, minV); + // outside quad + buffer.putVertex((float) b4.x, (float) b4.y, (float) b4.z, 0, 0, 1f, minU, minV); + buffer.putVertex((float) b3.x, (float) b3.y, (float) b3.z, 0, 0, 1f, minU, maxV); + buffer.putVertex((float) b2.x, (float) b2.y, (float) b2.z, 0, 0, 1f, maxU, maxV); + buffer.putVertex((float) b1.x, (float) b1.y, (float) b1.z, 0, 0, 1f, maxU, minV); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java index e02fd3faf..cfdd81257 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java @@ -107,7 +107,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity boolean contraptionPresent = movedContraption != null; if (needsContraption && !contraptionPresent) return; - + float movementSpeed = getMovementSpeed(); float newOffset = offset + movementSpeed; if ((int) newOffset != (int) offset) @@ -122,7 +122,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity return; } } - + if (!contraptionPresent || !movedContraption.isStalled()) offset = newOffset; @@ -173,10 +173,15 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity @Override public void setRemoved() { + super.setRemoved(); + } + + @Override + protected void setRemovedNotDueToChunkUnload() { this.remove = true; if (!level.isClientSide) disassemble(); - super.setRemoved(); + super.setRemovedNotDueToChunkUnload(); } @Override @@ -261,13 +266,13 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity movedContraption.setContraptionMotion(Vec3.ZERO); return false; } - + Vec3 motion = getMotionVector(); movedContraption.setContraptionMotion(getMotionVector()); movedContraption.move(motion.x, motion.y, motion.z); return ContraptionCollider.collideBlocks(movedContraption); } - + protected void collided() { if (level.isClientSide) { waitingForSpeedChange = true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java index 2072a657f..5d834de18 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; import net.minecraft.core.Vec3i; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java index 8906a5ab0..f4c600ebf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java @@ -7,8 +7,8 @@ import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.instancing.GroupInstance; import com.jozufozu.flywheel.core.instancing.SelectInstance; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightPacking; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightUpdater; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java index f60c903ab..dfa6dcd0c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java @@ -44,8 +44,7 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance() - .canUseInstancing(te.getLevel())) + if (Backend.canUseInstancing(te.getLevel())) return; super.renderSafe(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java index b959b2ca4..2a1faf43c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java index ead1523c2..c52a7d882 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java @@ -7,9 +7,9 @@ import net.minecraft.client.renderer.RenderType; public class ContraptionGroup

extends InstancedMaterialGroup

{ - private final RenderedContraption contraption; + private final FlwContraption contraption; - public ContraptionGroup(RenderedContraption contraption, InstancingEngine

owner, RenderType type) { + public ContraptionGroup(FlwContraption contraption, InstancingEngine

owner, RenderType type) { super(owner, type); this.contraption = contraption; @@ -20,7 +20,7 @@ public class ContraptionGroup

extends InstancedMat contraption.setup(program); } - public static

InstancingEngine.GroupFactory

forContraption(RenderedContraption c) { + public static

InstancingEngine.GroupFactory

forContraption(FlwContraption c) { return (materialManager, type) -> new ContraptionGroup<>(c, materialManager, type); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java index 94bfa5183..927207f91 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import java.lang.ref.WeakReference; import java.util.ArrayList; import javax.annotation.Nullable; @@ -8,10 +7,12 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.api.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.client.Camera; import net.minecraft.core.BlockPos; @@ -21,11 +22,11 @@ public class ContraptionInstanceManager extends TileInstanceManager { protected ArrayList actors = new ArrayList<>(); - private final WeakReference contraption; + private final PlacementSimulationWorld renderWorld; - ContraptionInstanceManager(RenderedContraption contraption, MaterialManager materialManager) { + ContraptionInstanceManager(MaterialManager materialManager, PlacementSimulationWorld contraption) { super(materialManager); - this.contraption = new WeakReference<>(contraption); + this.renderWorld = contraption; } public void tick() { @@ -33,8 +34,8 @@ public class ContraptionInstanceManager extends TileInstanceManager { } @Override - public void beginFrame(Camera info) { - super.beginFrame(info); + public void beginFrame(TaskEngine taskEngine, Camera info) { + super.beginFrame(taskEngine, info); actors.forEach(ActorInstance::beginFrame); } @@ -52,7 +53,7 @@ public class ContraptionInstanceManager extends TileInstanceManager { MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) { - ActorInstance instance = movementBehaviour.createInstance(materialManager, getContraption().renderWorld, context); + ActorInstance instance = movementBehaviour.createInstance(materialManager, renderWorld, context); actors.add(instance); @@ -61,9 +62,5 @@ public class ContraptionInstanceManager extends TileInstanceManager { return null; } - - public RenderedContraption getContraption() { - return contraption.get(); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 82f43ce96..6997a696a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -43,7 +43,7 @@ import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(Dist.CLIENT) public class ContraptionRenderDispatcher { - private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); + private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); /** * Reset a contraption's renderer. @@ -113,8 +113,7 @@ public class ContraptionRenderDispatcher { // Skip individual lighting updates to prevent lag with large contraptions renderWorld.setBlock(info.pos, info.state, Block.UPDATE_SUPPRESS_LIGHT); - renderWorld.updateLightSources(); - renderWorld.lighter.runUpdates(Integer.MAX_VALUE, false, false); + renderWorld.runLightingEngine(); return renderWorld; } @@ -176,9 +175,9 @@ public class ContraptionRenderDispatcher { } public static void reset() { - WORLDS.empty(ContraptionRenderManager::delete); + WORLDS.empty(ContraptionRenderingWorld::delete); - if (Backend.getInstance().available()) { + if (Backend.isOn()) { WORLDS = new WorldAttached<>(FlwContraptionManager::new); } else { WORLDS = new WorldAttached<>(SBBContraptionManager::new); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index 648311387..13724e05b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java similarity index 95% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java index a5ae70382..072b8842d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java @@ -17,7 +17,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -public abstract class ContraptionRenderManager { +public abstract class ContraptionRenderingWorld { protected final Level world; private int removalTimer; @@ -25,7 +25,7 @@ public abstract class ContraptionRenderManager protected final Int2ObjectMap renderInfos = new Int2ObjectOpenHashMap<>(); protected final List visible = new ObjectArrayList<>(); - public ContraptionRenderManager(LevelAccessor world) { + public ContraptionRenderingWorld(LevelAccessor world) { this.world = (Level) world; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java index da4a5384b..c922a2ccd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/EmptyLighter.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import com.jozufozu.flywheel.light.GridAlignedBB; +import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java similarity index 62% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java index dcf0ba609..9b68b06fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java @@ -7,13 +7,18 @@ import java.util.Map; import java.util.function.Supplier; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.Engine; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; +import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; +import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; import com.jozufozu.flywheel.backend.model.ModelRenderer; import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.core.model.WorldModel; import com.jozufozu.flywheel.event.BeginFrameEvent; +import com.jozufozu.flywheel.event.RenderLayerEvent; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; @@ -30,32 +35,26 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -public class RenderedContraption extends ContraptionRenderInfo { +public class FlwContraption extends ContraptionRenderInfo { private final ContraptionLighter lighter; - public final InstancingEngine engine; - public final ContraptionInstanceManager kinetics; - private final Map renderLayers = new HashMap<>(); private final Matrix4f modelViewPartial = new Matrix4f(); + private final ContraptionInstanceWorld instanceWorld; private boolean modelViewPartialReady; - // floats because we're uploading this to the gpu + // floats because we upload this to the gpu private AABB lightBox; - public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { + public FlwContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); - this.engine = InstancingEngine.builder(CreateContexts.CWORLD) - .setGroupFactory(ContraptionGroup.forContraption(this)) - .setIgnoreOriginCoordinate(true) - .build(); - this.kinetics = new ContraptionInstanceManager(this, engine); - this.engine.addListener(this.kinetics); + + instanceWorld = new ContraptionInstanceWorld(this); buildLayers(); - if (Backend.getInstance().canUseInstancing()) { + if (Backend.isOn()) { buildInstancedTiles(); buildActors(); } @@ -65,7 +64,7 @@ public class RenderedContraption extends ContraptionRenderInfo { return lighter; } - public void doRenderLayer(RenderType layer, ContraptionProgram shader) { + public void renderStructureLayer(RenderType layer, ContraptionProgram shader) { ModelRenderer structure = renderLayers.get(layer); if (structure != null) { setup(shader); @@ -73,6 +72,21 @@ public class RenderedContraption extends ContraptionRenderInfo { } } + public void renderInstanceLayer(RenderLayerEvent event) { + + event.stack.pushPose(); + float partialTicks = AnimationTickHolder.getPartialTicks(); + AbstractContraptionEntity entity = contraption.entity; + double x = Mth.lerp(partialTicks, entity.xOld, entity.getX()); + double y = Mth.lerp(partialTicks, entity.yOld, entity.getY()); + double z = Mth.lerp(partialTicks, entity.zOld, entity.getZ()); + event.stack.translate(x - event.camX, y - event.camY, z - event.camZ); + ContraptionMatrices.transform(event.stack, getMatrices().getModel()); + instanceWorld.engine.render(SerialTaskEngine.INSTANCE, event); + + event.stack.popPose(); + } + public void beginFrame(BeginFrameEvent event) { super.beginFrame(event); @@ -81,7 +95,7 @@ public class RenderedContraption extends ContraptionRenderInfo { if (!isVisible()) return; - kinetics.beginFrame(event.getInfo()); + instanceWorld.tileInstanceManager.beginFrame(SerialTaskEngine.INSTANCE, event.getInfo()); Vec3 cameraPos = event.getCameraPos(); @@ -113,8 +127,7 @@ public class RenderedContraption extends ContraptionRenderInfo { lighter.delete(); - engine.delete(); - kinetics.invalidate(); + instanceWorld.delete(); } private void buildLayers() { @@ -141,7 +154,7 @@ public class RenderedContraption extends ContraptionRenderInfo { .canInstance(te.getType())) { Level world = te.getLevel(); te.setLevel(renderWorld); - kinetics.add(te); + instanceWorld.tileInstanceManager.add(te); te.setLevel(world); } } @@ -149,7 +162,7 @@ public class RenderedContraption extends ContraptionRenderInfo { } private void buildActors() { - contraption.getActors().forEach(kinetics::createActor); + contraption.getActors().forEach(instanceWorld.tileInstanceManager::createActor); } public static void setupModelViewPartial(Matrix4f matrix, Matrix4f modelMatrix, AbstractContraptionEntity entity, double camX, double camY, double camZ, float pt) { @@ -160,4 +173,38 @@ public class RenderedContraption extends ContraptionRenderInfo { matrix.multiply(modelMatrix); } + public void tick() { + instanceWorld.tileInstanceManager.tick(); + } + + public static class ContraptionInstanceWorld { + + private final Engine engine; + private final ContraptionInstanceManager tileInstanceManager; + + public ContraptionInstanceWorld(FlwContraption parent) { + switch (Backend.getInstance().getEngine()) { + case INSTANCING -> { + InstancingEngine engine = InstancingEngine.builder(CreateContexts.CWORLD) + .setGroupFactory(ContraptionGroup.forContraption(parent)) + .setIgnoreOriginCoordinate(true) + .build(); + tileInstanceManager = new ContraptionInstanceManager(engine, parent.renderWorld); + engine.addListener(tileInstanceManager); + + this.engine = engine; + } + case BATCHING -> { + engine = new BatchingEngine(); + tileInstanceManager = new ContraptionInstanceManager(engine, parent.renderWorld); + } + default -> throw new IllegalArgumentException("Unknown engine type"); + } + } + + public void delete() { + engine.delete(); + tileInstanceManager.invalidate(); + } + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index f4794fa75..f7a596670 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.event.RenderLayerEvent; -import com.jozufozu.flywheel.util.TextureBinder; +import com.jozufozu.flywheel.util.Textures; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.render.CreateContexts; @@ -17,7 +17,7 @@ import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationW import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.LevelAccessor; -public class FlwContraptionManager extends ContraptionRenderManager { +public class FlwContraptionManager extends ContraptionRenderingWorld { public FlwContraptionManager(LevelAccessor world) { super(world); @@ -27,8 +27,8 @@ public class FlwContraptionManager extends ContraptionRenderManager { +public class SBBContraptionManager extends ContraptionRenderingWorld { public static final SuperByteBufferCache.Compartment> CONTRAPTION = new SuperByteBufferCache.Compartment<>(); public SBBContraptionManager(LevelAccessor world) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java index a83f0f4ef..2b6404cfe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java @@ -27,7 +27,7 @@ public class FluidValveRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockState blockState = te.getBlockState(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java index 98c6f46ca..a1d77e4e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java @@ -197,12 +197,17 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor @Override public void setRemoved() { - onEmptied(); itemCapability.invalidate(); fluidCapability.invalidate(); super.setRemoved(); } + @Override + protected void setRemovedNotDueToChunkUnload() { + onEmptied(); + super.setRemovedNotDueToChunkUnload(); + } + @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, Direction side) { @@ -288,7 +293,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor tryClearingSpoutputOverflow(); if (!contentsChanged) return; - + contentsChanged = false; getOperator().ifPresent(te -> te.basinChecker.scheduleUpdate()); @@ -312,7 +317,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor Direction direction = blockState.getValue(BasinBlock.FACING); BlockEntity te = level.getBlockEntity(worldPosition.below() .relative(direction)); - + FilteringBehaviour filter = null; InvManipulationBehaviour inserter = null; if (te != null) { @@ -362,7 +367,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor update = true; continue; } - + if (targetTank == null) break; @@ -459,7 +464,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor Direction direction = blockState.getValue(BasinBlock.FACING); if (direction != Direction.DOWN) { - + BlockEntity te = level.getBlockEntity(worldPosition.below() .relative(direction)); @@ -472,7 +477,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()) .orElse(null); boolean externalTankNotPresent = targetTank == null; - + if (!outputItems.isEmpty() && targetInv == null) return false; if (!outputFluids.isEmpty() && externalTankNotPresent) { @@ -484,7 +489,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor if (!acceptFluidOutputsIntoBasin(outputFluids, simulate, targetTank)) return false; } - + if (simulate) return true; for (ItemStack itemStack : outputItems) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index dbae35d20..a7043b05b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -31,7 +31,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { protected void renderSafe(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (!Backend.getInstance().canUseInstancing(te.getLevel())) { + if (!Backend.canUseInstancing(te.getLevel())) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index 33cbbd251..75a669d27 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -13,8 +13,8 @@ import java.util.Optional; import java.util.function.Function; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; -import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.light.ImmutableBox; +import com.jozufozu.flywheel.util.box.GridAlignedBB; +import com.jozufozu.flywheel.util.box.ImmutableBox; import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightProvider; import com.jozufozu.flywheel.light.LightUpdater; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileInstance.java index 7733d54e7..127addf7f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileInstance.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.relays.elementary; import com.jozufozu.flywheel.api.Instancer; import com.jozufozu.flywheel.api.MaterialManager; -import com.jozufozu.flywheel.util.transform.MatrixTransformStack; +import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector3f; import com.simibubi.create.AllBlockPartials; @@ -59,10 +59,11 @@ public class BracketedKineticTileInstance extends SingleRotatingInstance { private PoseStack rotateToAxis(Axis axis) { Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE); PoseStack poseStack = new PoseStack(); - new MatrixTransformStack(poseStack).centre() - .rotateToFace(facing) - .multiply(Vector3f.XN.rotationDegrees(-90)) - .unCentre(); + TransformStack.cast(poseStack) + .centre() + .rotateToFace(facing) + .multiply(Vector3f.XN.rotationDegrees(-90)) + .unCentre(); return poseStack; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileRenderer.java index f8f5754a1..8e0e86660 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticTileRenderer.java @@ -28,8 +28,7 @@ public class BracketedKineticTileRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance() - .canUseInstancing(te.getLevel())) + if (Backend.canUseInstancing(te.getLevel())) return; if (!AllBlocks.LARGE_COGWHEEL.has(te.getBlockState())) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogRenderer.java index 0bb95a167..74445ff1f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedCogRenderer.java @@ -39,8 +39,7 @@ public class EncasedCogRenderer extends KineticTileEntityRenderer { protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); - if (Backend.getInstance() - .canUseInstancing(te.getLevel())) + if (Backend.canUseInstancing(te.getLevel())) return; BlockState blockState = te.getBlockState(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index dd7dce660..ba38d1481 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -28,7 +28,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java index ce495f0bd..a5872e8b3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java @@ -39,7 +39,7 @@ public class GaugeRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; super.renderSafe(te, partialTicks, ms, buffer, light, overlay); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 56194ec81..04671bcad 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -27,7 +27,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; final Axis boxAxis = te.getBlockState().getValue(BlockStateProperties.AXIS); final BlockPos pos = te.getBlockPos(); diff --git a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java index 8477f6578..efc548e31 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java @@ -76,7 +76,7 @@ public class TreeFertilizerItem extends Item { return super.useOn(context); } - private class TreesDreamWorld extends PlacementSimulationServerWorld { + private static class TreesDreamWorld extends PlacementSimulationServerWorld { private final BlockPos saplingPos; private final BlockState soil; diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ItemReturnInvWrapper.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ItemReturnInvWrapper.java index 7110649d7..e70e7a36c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ItemReturnInvWrapper.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ItemReturnInvWrapper.java @@ -1,15 +1,17 @@ package com.simibubi.create.content.curiosities.toolbox; import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.wrapper.InvWrapper; +import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; /** * For inserting items into a players' inventory anywhere except the hotbar */ -public class ItemReturnInvWrapper extends InvWrapper { +public class ItemReturnInvWrapper extends PlayerMainInvWrapper { - public ItemReturnInvWrapper(Container inv) { + public ItemReturnInvWrapper(Inventory inv) { super(inv); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java index 7793550c4..b45ff29da 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java @@ -7,6 +7,8 @@ import java.util.Optional; import javax.annotation.Nullable; +import net.minecraft.nbt.Tag; + import org.apache.commons.lang3.Validate; import com.simibubi.create.AllEntityTypes; @@ -113,9 +115,15 @@ public class BlueprintEntity extends HangingEntity @Override public void readAdditionalSaveData(CompoundTag p_70037_1_) { - this.direction = Direction.from3DDataValue(p_70037_1_.getByte("Facing")); - this.verticalOrientation = Direction.from3DDataValue(p_70037_1_.getByte("Orientation")); - this.size = p_70037_1_.getInt("Size"); + if (p_70037_1_.contains("Facing", Tag.TAG_ANY_NUMERIC)) { + this.direction = Direction.from3DDataValue(p_70037_1_.getByte("Facing")); + this.verticalOrientation = Direction.from3DDataValue(p_70037_1_.getByte("Orientation")); + this.size = p_70037_1_.getInt("Size"); + } else { + this.direction = Direction.SOUTH; + this.verticalOrientation = Direction.DOWN; + this.size = 1; + } super.readAdditionalSaveData(p_70037_1_); this.updateFacingWithBoundingBox(this.direction, this.verticalOrientation); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java index 708853df2..f5f137b2b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java @@ -31,7 +31,7 @@ public class BeltTunnelRenderer extends SmartTileEntityRenderer grabCapability(Direction side) { BlockPos pos = this.worldPosition.relative(side); if (level == null) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteTileEntity.java index 610577a49..a740833cf 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/SmartChuteTileEntity.java @@ -41,6 +41,12 @@ public class SmartChuteTileEntity extends ChuteTileEntity { BlockState blockState = getBlockState(); return blockState.hasProperty(SmartChuteBlock.POWERED) && !blockState.getValue(SmartChuteBlock.POWERED); } + + @Override + protected boolean canOutputItems() { + BlockState blockState = getBlockState(); + return blockState.hasProperty(SmartChuteBlock.POWERED) && !blockState.getValue(SmartChuteBlock.POWERED); + } @Override public void addBehaviours(List behaviours) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java index 868d1c668..9a60342e8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java @@ -47,7 +47,7 @@ public class EjectorRenderer extends KineticTileEntityRenderer { float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks); float angle = lidProgress * 70; - if (!Backend.getInstance().canUseInstancing(te.getLevel())) { + if (!Backend.canUseInstancing(te.getLevel())) { SuperByteBuffer model = CachedBufferer.partial(AllBlockPartials.EJECTOR_TOP, te.getBlockState()); applyLidAngle(te, angle, model); model.light(light) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapData.java b/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapData.java index 2e2ebb44b..591f0160c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapData.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapData.java @@ -4,6 +4,7 @@ import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.core.materials.FlatLit; import com.mojang.math.Vector3f; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.core.BlockPos; public class FlapData extends InstanceData implements FlatLit { @@ -42,18 +43,23 @@ public class FlapData extends InstanceData implements FlatLit { @Override public FlapData setBlockLight(int blockLight) { - this.blockLight = (byte) ((blockLight & 0xF) << 4); + this.blockLight = (byte) (blockLight & 0xF); markDirty(); return this; } @Override public FlapData setSkyLight(int skyLight) { - this.skyLight = (byte) ((skyLight & 0xF) << 4); + this.skyLight = (byte) (skyLight & 0xF); markDirty(); return this; } + @Override + public int getPackedLight() { + return LightTexture.pack(this.blockLight, this.skyLight); + } + public FlapData setSegmentOffset(float x, float y, float z) { this.segmentOffsetX = x; this.segmentOffsetY = y; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapType.java b/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapType.java index 9838d5708..5e1696ad9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapType.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/flap/FlapType.java @@ -1,12 +1,11 @@ package com.simibubi.create.content.logistics.block.flap; import com.jozufozu.flywheel.api.struct.Batched; -import com.jozufozu.flywheel.api.struct.BatchingTransformer; import com.jozufozu.flywheel.api.struct.Instanced; import com.jozufozu.flywheel.api.struct.StructWriter; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.core.layout.BufferLayout; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.core.model.Model; +import com.jozufozu.flywheel.core.model.ModelTransformer; import com.simibubi.create.foundation.render.AllInstanceFormats; import com.simibubi.create.foundation.render.AllProgramSpecs; @@ -19,7 +18,7 @@ public class FlapType implements Instanced, Batched { } @Override - public VertexFormat format() { + public BufferLayout getLayout() { return AllInstanceFormats.FLAP; } @@ -34,7 +33,27 @@ public class FlapType implements Instanced, Batched { } @Override - public BatchingTransformer getTransformer(Model model) { - return null; + public void transform(FlapData d, ModelTransformer.Params b) { + b.translate(d.x, d.y, d.z) + .centre() + .rotateY(-d.horizontalAngle) + .unCentre() + .translate(d.pivotX, d.pivotY, d.pivotZ) + .rotateX(getFlapAngle(d.flapness, d.intensity, d.flapScale)) + .translateBack(d.pivotX, d.pivotY, d.pivotZ) + .translate(d.segmentOffsetX, d.segmentOffsetY, d.segmentOffsetZ) + .light(d.getPackedLight()); + } + + private static float getFlapAngle(float flapness, float intensity, float scale) { + float absFlap = Math.abs(flapness); + + float angle = (float) (Math.sin((1. - absFlap) * Math.PI * intensity) * 30. * flapness * scale); + + if (flapness > 0) { + return angle * 0.5f; + } else { + return angle; + } } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/flap/UnsafeFlapWriter.java b/src/main/java/com/simibubi/create/content/logistics/block/flap/UnsafeFlapWriter.java index f0ace42cc..345fde063 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/flap/UnsafeFlapWriter.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/flap/UnsafeFlapWriter.java @@ -12,13 +12,13 @@ public class UnsafeFlapWriter extends UnsafeBufferWriter { } @Override - public void write(FlapData d) { + protected void writeInternal(FlapData d) { long addr = writePointer; MemoryUtil.memPutFloat(addr, d.x); MemoryUtil.memPutFloat(addr + 4, d.y); MemoryUtil.memPutFloat(addr + 8, d.z); - MemoryUtil.memPutByte(addr + 12, d.blockLight); - MemoryUtil.memPutByte(addr + 13, d.skyLight); + MemoryUtil.memPutByte(addr + 12, (byte) (d.blockLight << 4)); + MemoryUtil.memPutByte(addr + 13, (byte) (d.skyLight << 4)); MemoryUtil.memPutFloat(addr + 14, d.segmentOffsetX); MemoryUtil.memPutFloat(addr + 18, d.segmentOffsetY); MemoryUtil.memPutFloat(addr + 22, d.segmentOffsetZ); @@ -29,7 +29,5 @@ public class UnsafeFlapWriter extends UnsafeBufferWriter { MemoryUtil.memPutFloat(addr + 42, d.intensity); MemoryUtil.memPutFloat(addr + 46, d.flapScale); MemoryUtil.memPutFloat(addr + 50, d.flapness); - - advance(); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java index 867930b9b..3a1d3cd76 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelRenderer.java @@ -30,7 +30,7 @@ public class FunnelRenderer extends SmartTileEntityRenderer { int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); - if (!te.hasFlap() || Backend.getInstance().canUseInstancing(te.getLevel())) + if (!te.hasFlap() || Backend.canUseInstancing(te.getLevel())) return; BlockState blockState = te.getBlockState(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index bf6aa581c..c8212791f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -39,7 +39,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { ArmTileEntity arm = (ArmTileEntity) te; ItemStack item = arm.heldItem; boolean hasItem = !item.isEmpty(); - boolean usingFlywheel = Backend.getInstance().canUseInstancing(te.getLevel()); + boolean usingFlywheel = Backend.canUseInstancing(te.getLevel()); if (usingFlywheel && !hasItem) return; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index 481e3dda7..2d6026c16 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -26,7 +26,7 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer { public static final PaletteBlockPartial STAIR = new Stairs(); @@ -74,7 +76,7 @@ public abstract class PaletteBlockPartial { protected BlockBuilder transformBlock(BlockBuilder builder, String variantName, PaletteBlockPattern pattern) { getBlockTags().forEach(builder::tag); - return builder; + return builder.transform(pickaxeOnly()); } protected ItemBuilder> transformItem( diff --git a/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java b/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java index 80c7bc4d9..9c662be2b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java +++ b/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java @@ -45,7 +45,7 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor protected List renderedTileEntities; protected List entities; protected BoundingBox bounds; - + public BlockPos anchor; public boolean renderMode; @@ -149,12 +149,12 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor public int getBrightness(LightLayer p_226658_1_, BlockPos p_226658_2_) { return 10; } - + @Override public LevelTickAccess getBlockTicks() { return BlackholeTickAccess.emptyLevelList(); } - + @Override public LevelTickAccess getFluidTicks() { return BlackholeTickAccess.emptyLevelList(); @@ -170,7 +170,7 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor Predicate arg2) { return Collections.emptyList(); } - + @Override public List players() { return Collections.emptyList(); diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java index 4650bc294..aacd56fab 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonRenderer.java @@ -38,8 +38,7 @@ public class SchematicannonRenderer extends SafeTileEntityRenderer, Translate, Rotate, TStack { - private final BufferBuilderReader template; + private final VertexList template; // Vertex Position - private PoseStack transforms; + private final PoseStack transforms; // Vertex Coloring private boolean shouldColor; @@ -61,12 +62,9 @@ public class SuperByteBuffer implements Scale, Translate, Translate, Translate, Translate iterator = customRenderTEs.iterator(); while (iterator.hasNext()) { BlockEntity tileEntity = iterator.next(); - if (Backend.getInstance().canUseInstancing(renderWorld) && InstancedRenderRegistry.getInstance() + if (Backend.canUseInstancing(renderWorld) && InstancedRenderRegistry.getInstance() .shouldSkipRender(tileEntity)) continue; BlockEntityRenderer renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(tileEntity); diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java index 5f4d0f718..59ca1d3c1 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -116,6 +116,32 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti read(tag, false); } + /* TODO: Remove this hack once this issue is resolved: https://github.com/MinecraftForge/MinecraftForge/issues/8302 + Once the PR linked in the issue is accepted, we should use the new method for determining whether setRemoved was + called due to a chunk unload or not, and remove this volatile workaround + */ + private boolean unloaded; + + @Override + public void onChunkUnloaded() { + super.onChunkUnloaded(); + unloaded = true; + } + + protected void setRemovedNotDueToChunkUnload() { + + } + + @Override + public void setRemoved() { + forEachBehaviour(TileEntityBehaviour::remove); + super.setRemoved(); + + if (!unloaded) { + setRemovedNotDueToChunkUnload(); + } + } + @Override public final void saveAdditional(CompoundTag tag) { write(tag, false); @@ -158,12 +184,6 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti } } - @Override - public void setRemoved() { - forEachBehaviour(TileEntityBehaviour::remove); - super.setRemoved(); - } - public void setLazyTickRate(int slowTickRate) { this.lazyTickRate = slowTickRate; this.lazyTickCounter = slowTickRate; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java index 310bbeb6e..8ba1894ac 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java @@ -18,7 +18,7 @@ public abstract class ColoredOverlayTileEntityRenderer ex protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { - if (Backend.getInstance().canUseInstancing(te.getLevel())) return; + if (Backend.canUseInstancing(te.getLevel())) return; SuperByteBuffer render = render(getOverlayBuffer(te), getColor(te, partialTicks), light); render.renderInto(ms, buffer.getBuffer(RenderType.solid())); diff --git a/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java b/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java index 9a3e2a393..4c3715fb6 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AngleHelper.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.utility; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; +import net.minecraft.util.Mth; public class AngleHelper { @@ -40,4 +41,12 @@ public class AngleHelper { return (float) (((((target - current) % 360) + 540) % 360) - 180); } + public static float getShortestAngleDiff(double current, double target, float hint) { + float diff = getShortestAngleDiff(current, target); + if (Mth.equal(Math.abs(diff), 180) && Math.signum(diff) != Math.signum(hint)) { + return diff + 360*Math.signum(hint); + } + return diff; + } + } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java index d6dfda197..b54485931 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.utility.worldWrappers; +import javax.annotation.Nullable; + import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkStatus; @@ -10,7 +12,7 @@ public class DummyStatusListener implements ChunkProgressListener { public void updateSpawnPos(ChunkPos pCenter) {} @Override - public void onStatusChange(ChunkPos pChunkPosition, ChunkStatus pNewStatus) {} + public void onStatusChange(ChunkPos pChunkPosition, @Nullable ChunkStatus pNewStatus) {} @Override public void start() {} diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index a3030eaff..8a4674aa7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -7,6 +7,8 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.api.FlywheelWorld; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; @@ -27,12 +29,12 @@ import net.minecraft.world.level.lighting.LevelLightEngine; import javax.annotation.Nonnull; public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { - public Map blocksAdded; - public Map tesAdded; + public Map blocksAdded = new HashMap<>(); + public Map tesAdded = new HashMap<>(); - public Set spannedSections; + public Set spannedSections = new HashSet<>(); public LevelLightEngine lighter; - public WrappedChunkProvider chunkProvider; + public final WrappedChunkProvider chunkSource; private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); private final ContraptionWorld contraptionWorld; @@ -41,22 +43,20 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo this(wrapped, c, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkProvider) { - super(wrapped, chunkProvider); + public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkSource) { + super(wrapped, chunkSource); + // You can't leak this before the super ctor is called. + // You can't create inner classes before super ctor is called. + chunkSource.setPlacementWorld(this); + this.chunkSource = chunkSource; contraptionWorld = c.getContraptionWorld(); - this.chunkProvider = chunkProvider.setPlacementWorld(this); - spannedSections = new HashSet<>(); - lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight - blocksAdded = new HashMap<>(); - tesAdded = new HashMap<>(); + lighter = new LevelLightEngine(chunkSource, true, false); } - @Override - public LevelLightEngine getLightEngine() { - return lighter; - } - - public void updateLightSources() { + /** + * Run this after you're done using setBlock(). + */ + public void runLightingEngine() { for (Map.Entry entry : blocksAdded.entrySet()) { BlockPos pos = entry.getKey(); BlockState state = entry.getValue(); @@ -65,6 +65,13 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo lighter.onBlockEmissionIncrease(pos, light); } } + + lighter.runUpdates(Integer.MAX_VALUE, false, false); + } + + @Override + public LevelLightEngine getLightEngine() { + return lighter; } public void setTileEntities(Collection tileEntities) { @@ -98,6 +105,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo } @Override + @Nullable public BlockEntity getBlockEntity(BlockPos pos) { return tesAdded.get(pos); } @@ -142,10 +150,10 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo // Override Starlight's ExtendedWorld interface methods: public LevelChunk getChunkAtImmediately(final int chunkX, final int chunkZ) { - return chunkProvider.getChunk(chunkX, chunkZ, false); + return chunkSource.getChunk(chunkX, chunkZ, false); } public ChunkAccess getAnyChunkImmediately(final int chunkX, final int chunkZ) { - return chunkProvider.getChunk(chunkX, chunkZ); + return chunkSource.getChunk(chunkX, chunkZ); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java index 20a7a9f5f..cc6d567c0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java @@ -11,8 +11,8 @@ import net.minecraft.world.level.material.FluidState; public class RayTraceWorld implements BlockGetter { - private LevelAccessor template; - private BiFunction stateGetter; + private final LevelAccessor template; + private final BiFunction stateGetter; public RayTraceWorld(LevelAccessor template, BiFunction stateGetter) { this.template = template; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java index 9b82e8c21..8b4b48a6e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java @@ -29,11 +29,11 @@ public class WrappedChunkProvider extends ChunkSource { fallbackWorld = world; return this; } - - public WrappedChunkProvider setPlacementWorld(PlacementSimulationWorld world) { + + // VirtualChunkSource is created before VirtualRenderWorld, so we can't initialize it in the ctor. + public void setPlacementWorld(PlacementSimulationWorld world) { fallbackWorld = this.world = world; this.chunks = new HashMap<>(); - return this; } public Stream getLightSources() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java index 802268f3b..775dc9e11 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java @@ -33,8 +33,6 @@ import net.minecraft.world.level.storage.WritableLevelData; import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.ticks.LevelTickAccess; -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault public class WrappedWorld extends Level { protected Level world; @@ -68,17 +66,18 @@ public class WrappedWorld extends Level { } @Override - public boolean isStateAtPosition(@Nullable BlockPos p_217375_1_, @Nullable Predicate p_217375_2_) { + public boolean isStateAtPosition(BlockPos p_217375_1_, Predicate p_217375_2_) { return world.isStateAtPosition(p_217375_1_, p_217375_2_); } @Override - public BlockEntity getBlockEntity(@Nullable BlockPos pos) { + @Nullable + public BlockEntity getBlockEntity(BlockPos pos) { return world.getBlockEntity(pos); } @Override - public boolean setBlock(@Nullable BlockPos pos, @Nullable BlockState newState, int flags) { + public boolean setBlock(BlockPos pos, BlockState newState, int flags) { return world.setBlock(pos, newState, flags); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java new file mode 100644 index 000000000..87851a339 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.simibubi.create.foundation.utility.worldWrappers; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 1e0a18730..d0c659484 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -32,6 +32,6 @@ Technology that empowers the player.''' [[dependencies.create]] modId="flywheel" mandatory=true - versionRange="[1.18-0.4.0,1.18-0.4.2)" + versionRange="[1.18-0.5.0,1.18-0.5.1)" ordering="AFTER" side="BOTH" diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert index 66db67682..2460a76fc 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert +++ b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert @@ -5,10 +5,10 @@ struct Vertex { vec3 pos; - vec3 normal; - vec2 texCoords; vec4 color; + vec2 texCoords; vec2 modelLight; + vec3 normal; }; #use "flywheel:block.frag" diff --git a/src/main/resources/assets/create/flywheel/shaders/flap.vert b/src/main/resources/assets/create/flywheel/shaders/flap.vert index 721be4ed1..5aefc4131 100644 --- a/src/main/resources/assets/create/flywheel/shaders/flap.vert +++ b/src/main/resources/assets/create/flywheel/shaders/flap.vert @@ -31,8 +31,8 @@ float getFlapAngle(float flapness, float intensity, float scale) { float halfAngle = angle * 0.5; - float which = step(0., flapness);// 0 if negative, 1 if positive - float degrees = which * halfAngle + (1. - which) * angle;// branchless conditional multiply + float which = step(0., flapness); // 0 if negative, 1 if positive + float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply return degrees; } diff --git a/src/main/resources/data/create/recipes/compat/quark/crushing/biotite.json b/src/main/resources/data/create/recipes/compat/quark/crushing/biotite.json deleted file mode 100644 index 4d7c4ba5d..000000000 --- a/src/main/resources/data/create/recipes/compat/quark/crushing/biotite.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "conditions": [ - { - "type": "forge:mod_loaded", - "modid": "quark" - } - ], - "type": "create:crushing", - "ingredients": [ - { - "item": "quark:biotite_ore" - } - ], - "results": [ - { - "item": "quark:biotite", - "count": 2 - }, - { - "item": "quark:biotite", - "count": 4, - "chance": 0.5 - }, - { - "item": "minecraft:end_stone", - "count": 1, - "chance": 0.125 - } - ], - "processingTime": 450 -} \ No newline at end of file diff --git a/src/main/resources/data/create/recipes/compat/quark/crushing/cactus.json b/src/main/resources/data/create/recipes/compat/quark/crushing/moss_block.json similarity index 72% rename from src/main/resources/data/create/recipes/compat/quark/crushing/cactus.json rename to src/main/resources/data/create/recipes/compat/quark/crushing/moss_block.json index 0e007833a..04ed45e63 100644 --- a/src/main/resources/data/create/recipes/compat/quark/crushing/cactus.json +++ b/src/main/resources/data/create/recipes/compat/quark/crushing/moss_block.json @@ -9,19 +9,19 @@ "group": "minecraft:misc", "ingredients": [ { - "item": "minecraft:cactus" + "item": "minecraft:moss_block" } - ], + ], "results": [ { - "item": "quark:cactus_paste", + "item": "quark:moss_paste", "count": 2 }, { - "item": "quark:cactus_paste", + "item": "quark:moss_paste", "count": 1, "chance": 0.1 } ], "processingTime": 50 -} \ No newline at end of file +}