From 81eeadb8532599d482f2259e58cedeaa602e8628 Mon Sep 17 00:00:00 2001 From: Rabbitminers Date: Mon, 1 May 2023 16:15:28 +0100 Subject: [PATCH] Small cleanup --- .../com/simibubi/create/AllBogeyStyles.java | 9 +++---- .../logistics/trains/AbstractBogeyBlock.java | 2 +- .../logistics/trains/BogeyRenderer.java | 11 -------- .../trains/StandardBogeyRenderer.java | 14 ----------- .../trains/entity/BackupBogeyRenderer.java | 5 ---- .../logistics/trains/entity/BogeyStyle.java | 25 ++++++++++++++----- 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllBogeyStyles.java b/src/main/java/com/simibubi/create/AllBogeyStyles.java index f4eed44df..f15e7bd4d 100644 --- a/src/main/java/com/simibubi/create/AllBogeyStyles.java +++ b/src/main/java/com/simibubi/create/AllBogeyStyles.java @@ -15,7 +15,6 @@ import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import java.util.HashMap; @@ -30,7 +29,7 @@ public class AllBogeyStyles { public static BogeyStyle STANDARD = create("standard") .commonRenderer(CommonStandardBogeyRenderer::new) - .displayName(new TranslatableComponent("create.bogeys.styles.standard")) + .displayName(Lang.translateDirect("create.bogeys.styles.standard")) .size(BogeySizes.SMALL, SmallStandardBogeyRenderer::new, AllBlocks.SMALL_BOGEY) .size(BogeySizes.LARGE, LargeStandardBogeyRenderer::new, AllBlocks.LARGE_BOGEY) .build(); @@ -56,7 +55,7 @@ public class AllBogeyStyles { protected CompoundTag defaultData = new CompoundTag(); protected ParticleOptions contactParticle = ParticleTypes.CRIT; protected ParticleOptions smokeParticle = ParticleTypes.POOF; - protected Optional commonRenderer = Optional.empty(); + protected Optional> commonRenderer = Optional.empty(); public BogeyStyleBuilder(ResourceLocation name) { this.name = name; @@ -85,7 +84,7 @@ public class AllBogeyStyles { public BogeyStyleBuilder size(BogeySizes.BogeySize size, Supplier renderer, ResourceLocation location) { - this.sizes.put(size, new BogeyStyle.SizeData(location, renderer.get())); + this.sizes.put(size, new BogeyStyle.SizeData(location, renderer, renderer.get())); return this; } @@ -100,7 +99,7 @@ public class AllBogeyStyles { } public BogeyStyleBuilder commonRenderer(Supplier commonRenderer) { - this.commonRenderer = Optional.of(commonRenderer.get()); + this.commonRenderer = Optional.of(commonRenderer); return this; } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/AbstractBogeyBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/AbstractBogeyBlock.java index 037382721..040cdd599 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/AbstractBogeyBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/AbstractBogeyBlock.java @@ -111,7 +111,7 @@ public abstract class AbstractBogeyBlock extends Block implements ITE commonRenderer - = style.getNewCommonRenderInstance(); + = style.getInWorldCommonRenderInstance(); final BogeyRenderer renderer = style.getInWorldRenderInstance(this.getSize()); if (state != null) { ms.translate(.5f, .5f, .5f); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/BogeyRenderer.java b/src/main/java/com/simibubi/create/content/logistics/trains/BogeyRenderer.java index 5839646ce..2dbf0450f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/BogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/BogeyRenderer.java @@ -278,21 +278,10 @@ public abstract class BogeyRenderer { return state.toString(); } - /** - * Used for rendering in contraptions allowing for individual instances of models for each component - * - * @return new Instance of renderer - */ - public abstract BogeyRenderer createNewInstance(); - - public static abstract class CommonRenderer extends BogeyRenderer { @Override public BogeySizes.BogeySize getSize() { return null; } - - @Override - public abstract CommonRenderer createNewInstance(); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java b/src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java index 2dddffba2..c3ece1c78 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java @@ -30,11 +30,6 @@ public class StandardBogeyRenderer { .setValue(ShaftBlock.AXIS, Direction.Axis.Z), 2); } - @Override - public CommonStandardBogeyRenderer createNewInstance() { - return new CommonStandardBogeyRenderer(); - } - @Override public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb) { boolean inContraption = vb == null; @@ -58,10 +53,6 @@ public class StandardBogeyRenderer { createModelInstances(materialManager, BOGEY_FRAME); } - @Override - public BogeyRenderer createNewInstance() { - return new SmallStandardBogeyRenderer(); - } @Override public BogeySizes.BogeySize getSize() { @@ -96,11 +87,6 @@ public class StandardBogeyRenderer { .setValue(ShaftBlock.AXIS, Direction.Axis.X), 2); } - @Override - public BogeyRenderer createNewInstance() { - return new LargeStandardBogeyRenderer(); - } - @Override public BogeySizes.BogeySize getSize() { return BogeySizes.LARGE; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BackupBogeyRenderer.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BackupBogeyRenderer.java index a8783ea3a..41dc32e8b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BackupBogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BackupBogeyRenderer.java @@ -19,9 +19,4 @@ public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer { public void initialiseContraptionModelData(MaterialManager materialManager) { } - - @Override - public CommonRenderer createNewInstance() { - return new BackupBogeyRenderer(); - } } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java index a1b48ca99..6d3bdbb12 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java @@ -20,10 +20,13 @@ import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Stream; public class BogeyStyle { + private final Optional> commonRendererFactory; + public final ResourceLocation name; private final Optional commonRenderer; private final Map sizes; @@ -34,7 +37,7 @@ public class BogeyStyle { public final CompoundTag defaultData; public BogeyStyle(ResourceLocation name, Component displayName, ResourceLocation soundType, ParticleOptions contactParticle, ParticleOptions smokeParticle, - CompoundTag defaultData, Map sizes, Optional commonRenderer) { + CompoundTag defaultData, Map sizes, Optional> commonRenderer) { this.name = name; this.displayName = displayName; this.soundType = soundType; @@ -43,9 +46,12 @@ public class BogeyStyle { this.defaultData = defaultData; this.sizes = sizes; - this.commonRenderer = commonRenderer; + + this.commonRendererFactory = commonRenderer; + this.commonRenderer = commonRenderer.map(Supplier::get); } + public Block getNextBlock(BogeySizes.BogeySize currentSize) { return Stream.iterate(currentSize.increment(), BogeySizes.BogeySize::increment) .filter(sizes::containsKey) @@ -70,12 +76,12 @@ public class BogeyStyle { } public BogeyRenderer createRendererInstance(BogeySizes.BogeySize size) { - return this.getInWorldRenderInstance(size).createNewInstance(); + return this.sizes.get(size).createRenderInstance(); } public BogeyRenderer getInWorldRenderInstance(BogeySizes.BogeySize size) { SizeData sizeData = this.sizes.get(size); - return sizeData != null ? sizeData.renderer() : BackupBogeyRenderer.INSTANCE; + return sizeData != null ? sizeData.getInWorldInstance() : BackupBogeyRenderer.INSTANCE; } public Optional getInWorldCommonRenderInstance() { @@ -83,13 +89,20 @@ public class BogeyStyle { } public Optional getNewCommonRenderInstance() { - return this.getInWorldCommonRenderInstance().map(CommonRenderer::createNewInstance); + return this.commonRendererFactory.map(Supplier::get); } public BogeyInstance createInstance(CarriageBogey bogey, BogeySizes.BogeySize size, MaterialManager materialManager) { return new BogeyInstance(bogey, this, size, materialManager); } - public record SizeData(ResourceLocation block, BogeyRenderer renderer) { + public record SizeData(ResourceLocation block, Supplier rendererFactory, BogeyRenderer instance) { + public BogeyRenderer createRenderInstance() { + return rendererFactory.get(); + } + + public BogeyRenderer getInWorldInstance() { + return instance; + } } }