Merge remote-tracking branch 'origin/1.18/api' into 1.18/api

# Conflicts:
#	src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java
This commit is contained in:
techno-sam 2023-05-08 20:16:32 -07:00
commit 662da6bab1
8 changed files with 30 additions and 47 deletions

View File

@ -172,7 +172,7 @@ dependencies {
// runtimeOnly fg.deobf("slimeknights.mantle:Mantle:1.16.5-1.6.115") // runtimeOnly fg.deobf("slimeknights.mantle:Mantle:1.16.5-1.6.115")
// runtimeOnly fg.deobf("slimeknights.tconstruct:TConstruct:1.16.5-3.1.1.252") // runtimeOnly fg.deobf("slimeknights.tconstruct:TConstruct:1.16.5-3.1.1.252")
// runtimeOnly fg.deobf("maven.modrinth:rubidium:0.5.3") // runtimeOnly fg.deobf("maven.modrinth:rubidium:0.5.3")
implementation fg.deobf("com.railwayteam.railways:railways-1.18.2-1.1.1:all") { transitive = false } // implementation fg.deobf("com.railwayteam.railways:railways-1.18.2-1.1.1:all") { transitive = false }
// https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497 // https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings // Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings

View File

@ -28,21 +28,23 @@ import static com.simibubi.create.Create.LOGGER;
public class AllBogeyStyles { public class AllBogeyStyles {
public static final Map<ResourceLocation, BogeyStyle> BOGEY_STYLES = new HashMap<>(); public static final Map<ResourceLocation, BogeyStyle> BOGEY_STYLES = new HashMap<>();
public static final Map<ResourceLocation, Map<ResourceLocation, BogeyStyle>> STYLE_GROUPS = new HashMap<>(); // each set of styles that should be cycled through public static final Map<ResourceLocation, Map<ResourceLocation, BogeyStyle>> CYCLE_GROUPS = new HashMap<>(); // each set of styles that should be cycled through
private static final Map<ResourceLocation, BogeyStyle> EMPTY_GROUP = ImmutableMap.of(); private static final Map<ResourceLocation, BogeyStyle> EMPTY_GROUP = ImmutableMap.of();
public static Map<ResourceLocation, BogeyStyle> getCycleGroup(ResourceLocation cycleGroup) { public static Map<ResourceLocation, BogeyStyle> getCycleGroup(ResourceLocation cycleGroup) {
return STYLE_GROUPS.getOrDefault(cycleGroup, EMPTY_GROUP); return CYCLE_GROUPS.getOrDefault(cycleGroup, EMPTY_GROUP);
} }
public static BogeyStyle STANDARD = create("standard", "standard") public static final String STANDARD_CYCLE_GROUP = "standard";
public static BogeyStyle STANDARD = create("standard", STANDARD_CYCLE_GROUP)
.commonRenderer(CommonStandardBogeyRenderer::new) .commonRenderer(CommonStandardBogeyRenderer::new)
.displayName(Components.translatable("create.bogey.style.standard")) .displayName(Components.translatable("create.bogey.style.standard"))
.size(BogeySizes.SMALL, SmallStandardBogeyRenderer::new, AllBlocks.SMALL_BOGEY) .size(BogeySizes.SMALL, SmallStandardBogeyRenderer::new, AllBlocks.SMALL_BOGEY)
.size(BogeySizes.LARGE, LargeStandardBogeyRenderer::new, AllBlocks.LARGE_BOGEY) .size(BogeySizes.LARGE, LargeStandardBogeyRenderer::new, AllBlocks.LARGE_BOGEY)
.build(); .build();
public static BogeyStyleBuilder create(String name, String cycleGroup) { private static BogeyStyleBuilder create(String name, String cycleGroup) {
return create(Create.asResource(name), Create.asResource(cycleGroup)); return create(Create.asResource(name), Create.asResource(cycleGroup));
} }
@ -64,7 +66,7 @@ public class AllBogeyStyles {
protected CompoundTag defaultData = new CompoundTag(); protected CompoundTag defaultData = new CompoundTag();
protected ParticleOptions contactParticle = ParticleTypes.CRIT; protected ParticleOptions contactParticle = ParticleTypes.CRIT;
protected ParticleOptions smokeParticle = ParticleTypes.POOF; protected ParticleOptions smokeParticle = ParticleTypes.POOF;
protected Optional<CommonRenderer> commonRenderer = Optional.empty(); protected Optional<Supplier<? extends CommonRenderer>> commonRenderer = Optional.empty();
public BogeyStyleBuilder(ResourceLocation name, ResourceLocation cycleGroup) { public BogeyStyleBuilder(ResourceLocation name, ResourceLocation cycleGroup) {
this.name = name; this.name = name;
@ -94,7 +96,7 @@ public class AllBogeyStyles {
public BogeyStyleBuilder size(BogeySizes.BogeySize size, Supplier<? extends BogeyRenderer> renderer, public BogeyStyleBuilder size(BogeySizes.BogeySize size, Supplier<? extends BogeyRenderer> renderer,
ResourceLocation location) { 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; return this;
} }
@ -109,7 +111,7 @@ public class AllBogeyStyles {
} }
public BogeyStyleBuilder commonRenderer(Supplier<? extends CommonRenderer> commonRenderer) { public BogeyStyleBuilder commonRenderer(Supplier<? extends CommonRenderer> commonRenderer) {
this.commonRenderer = Optional.of(commonRenderer.get()); this.commonRenderer = Optional.of(commonRenderer);
return this; return this;
} }
@ -117,7 +119,7 @@ public class AllBogeyStyles {
BogeyStyle entry = BogeyStyle entry =
new BogeyStyle(name, cycleGroup, displayName, soundType, contactParticle, smokeParticle, defaultData, sizes, commonRenderer); new BogeyStyle(name, cycleGroup, displayName, soundType, contactParticle, smokeParticle, defaultData, sizes, commonRenderer);
BOGEY_STYLES.put(name, entry); BOGEY_STYLES.put(name, entry);
STYLE_GROUPS.computeIfAbsent(cycleGroup, l -> new HashMap<>()).put(name, entry); CYCLE_GROUPS.computeIfAbsent(cycleGroup, l -> new HashMap<>()).put(name, entry);
return entry; return entry;
} }
} }

View File

@ -151,7 +151,7 @@ public abstract class AbstractBogeyBlock<T extends AbstractBogeyTileEntity> exte
style = getDefaultStyle(); style = getDefaultStyle();
final Optional<BogeyRenderer.CommonRenderer> commonRenderer final Optional<BogeyRenderer.CommonRenderer> commonRenderer
= style.getNewCommonRenderInstance(); = style.getInWorldCommonRenderInstance();
final BogeyRenderer renderer = style.getInWorldRenderInstance(this.getSize()); final BogeyRenderer renderer = style.getInWorldRenderInstance(this.getSize());
if (state != null) { if (state != null) {
ms.translate(.5f, .5f, .5f); ms.translate(.5f, .5f, .5f);

View File

@ -278,21 +278,10 @@ public abstract class BogeyRenderer {
return state.toString(); 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 { public static abstract class CommonRenderer extends BogeyRenderer {
@Override @Override
public BogeySizes.BogeySize getSize() { public BogeySizes.BogeySize getSize() {
return null; return null;
} }
@Override
public abstract CommonRenderer createNewInstance();
} }
} }

View File

@ -30,11 +30,6 @@ public class StandardBogeyRenderer {
.setValue(ShaftBlock.AXIS, Direction.Axis.Z), 2); .setValue(ShaftBlock.AXIS, Direction.Axis.Z), 2);
} }
@Override
public CommonStandardBogeyRenderer createNewInstance() {
return new CommonStandardBogeyRenderer();
}
@Override @Override
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) { public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
boolean inInstancedContraption = vb == null; boolean inInstancedContraption = vb == null;
@ -58,10 +53,6 @@ public class StandardBogeyRenderer {
createModelInstances(materialManager, BOGEY_FRAME); createModelInstances(materialManager, BOGEY_FRAME);
} }
@Override
public BogeyRenderer createNewInstance() {
return new SmallStandardBogeyRenderer();
}
@Override @Override
public BogeySizes.BogeySize getSize() { public BogeySizes.BogeySize getSize() {
@ -96,11 +87,6 @@ public class StandardBogeyRenderer {
.setValue(ShaftBlock.AXIS, Direction.Axis.X), 2); .setValue(ShaftBlock.AXIS, Direction.Axis.X), 2);
} }
@Override
public BogeyRenderer createNewInstance() {
return new LargeStandardBogeyRenderer();
}
@Override @Override
public BogeySizes.BogeySize getSize() { public BogeySizes.BogeySize getSize() {
return BogeySizes.LARGE; return BogeySizes.LARGE;

View File

@ -19,9 +19,4 @@ public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer {
public void initialiseContraptionModelData(MaterialManager materialManager) { public void initialiseContraptionModelData(MaterialManager materialManager) {
} }
@Override
public CommonRenderer createNewInstance() {
return new BackupBogeyRenderer();
}
} }

View File

@ -21,10 +21,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
public class BogeyStyle { public class BogeyStyle {
private final Optional<Supplier<? extends CommonRenderer>> commonRendererFactory;
public final ResourceLocation name; public final ResourceLocation name;
public final ResourceLocation cycleGroup; public final ResourceLocation cycleGroup;
private final Optional<CommonRenderer> commonRenderer; private final Optional<CommonRenderer> commonRenderer;
@ -36,7 +39,7 @@ public class BogeyStyle {
public final CompoundTag defaultData; public final CompoundTag defaultData;
public BogeyStyle(ResourceLocation name, ResourceLocation cycleGroup, Component displayName, ResourceLocation soundType, ParticleOptions contactParticle, ParticleOptions smokeParticle, public BogeyStyle(ResourceLocation name, ResourceLocation cycleGroup, Component displayName, ResourceLocation soundType, ParticleOptions contactParticle, ParticleOptions smokeParticle,
CompoundTag defaultData, Map<BogeySizes.BogeySize, SizeData> sizes, Optional<CommonRenderer> commonRenderer) { CompoundTag defaultData, Map<BogeySizes.BogeySize, SizeData> sizes, Optional<Supplier<? extends CommonRenderer>> commonRenderer) {
this.name = name; this.name = name;
this.cycleGroup = cycleGroup; this.cycleGroup = cycleGroup;
this.displayName = displayName; this.displayName = displayName;
@ -46,7 +49,9 @@ public class BogeyStyle {
this.defaultData = defaultData; this.defaultData = defaultData;
this.sizes = sizes; this.sizes = sizes;
this.commonRenderer = commonRenderer;
this.commonRendererFactory = commonRenderer;
this.commonRenderer = commonRenderer.map(Supplier::get);
} }
public Map<ResourceLocation, BogeyStyle> getCycleGroup() { public Map<ResourceLocation, BogeyStyle> getCycleGroup() {
@ -77,12 +82,12 @@ public class BogeyStyle {
} }
public BogeyRenderer createRendererInstance(BogeySizes.BogeySize size) { public BogeyRenderer createRendererInstance(BogeySizes.BogeySize size) {
return this.getInWorldRenderInstance(size).createNewInstance(); return this.sizes.get(size).createRenderInstance();
} }
public BogeyRenderer getInWorldRenderInstance(BogeySizes.BogeySize size) { public BogeyRenderer getInWorldRenderInstance(BogeySizes.BogeySize size) {
SizeData sizeData = this.sizes.get(size); SizeData sizeData = this.sizes.get(size);
return sizeData != null ? sizeData.renderer() : BackupBogeyRenderer.INSTANCE; return sizeData != null ? sizeData.getInWorldInstance() : BackupBogeyRenderer.INSTANCE;
} }
public Optional<CommonRenderer> getInWorldCommonRenderInstance() { public Optional<CommonRenderer> getInWorldCommonRenderInstance() {
@ -90,13 +95,20 @@ public class BogeyStyle {
} }
public Optional<CommonRenderer> getNewCommonRenderInstance() { public Optional<CommonRenderer> getNewCommonRenderInstance() {
return this.getInWorldCommonRenderInstance().map(CommonRenderer::createNewInstance); return this.commonRendererFactory.map(Supplier::get);
} }
public BogeyInstance createInstance(CarriageBogey bogey, BogeySizes.BogeySize size, MaterialManager materialManager) { public BogeyInstance createInstance(CarriageBogey bogey, BogeySizes.BogeySize size, MaterialManager materialManager) {
return new BogeyInstance(bogey, this, size, materialManager); return new BogeyInstance(bogey, this, size, materialManager);
} }
public record SizeData(ResourceLocation block, BogeyRenderer renderer) { public record SizeData(ResourceLocation block, Supplier<? extends BogeyRenderer> rendererFactory, BogeyRenderer instance) {
public BogeyRenderer createRenderInstance() {
return rendererFactory.get();
}
public BogeyRenderer getInWorldInstance() {
return instance;
}
} }
} }

View File

@ -14,7 +14,6 @@ import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.railwayteam.railways.Railways;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
import org.apache.commons.lang3.mutable.MutableDouble; import org.apache.commons.lang3.mutable.MutableDouble;