Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern emmisive #102

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
Expand All @@ -13,14 +14,11 @@
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;
import whocraft.tardis_refined.common.util.Platform;

import java.io.IOException;
import java.util.*;

public class ConsolePatterns extends SimpleJsonResourceReloadListener {


public static final ResourceLocation CRYSTAL_CORRUPTED = new ResourceLocation(TardisRefined.MODID, "crystal/corrupted");
private static final Map<ConsoleTheme, List<Pattern>> PATTERNS = new HashMap<>();

private static Map<ConsoleTheme, List<Pattern>> PATTERNS = new HashMap<>();
public ConsolePatterns() {
super(TardisRefined.GSON, "patterns/console");
}
Expand All @@ -35,19 +33,18 @@ public static Pattern next(ConsoleTheme consoleTheme, Pattern pattern) {
}

public static Pattern addPattern(ConsoleTheme theme, Pattern pattern) {
TardisRefined.LOGGER.debug("Adding Console Pattern {} for {}", pattern.identifier, pattern.theme);
TardisRefined.LOGGER.info("Adding Console Pattern {} for {}", pattern.identifier, pattern.theme);
if (PATTERNS.containsKey(theme)) {
List<Pattern> patternLiat = new ArrayList<>(PATTERNS.get(theme));
PATTERNS.replace(theme, patternLiat);
if(Platform.getServer() != null) {
new SyncConsolePatternsMessage(PATTERNS).sendToAll();
}
return pattern;
List<Pattern> patternList = new ArrayList<>(PATTERNS.get(theme));
patternList.add(pattern);
PATTERNS.replace(theme, patternList);
} else {
PATTERNS.put(theme, new ArrayList<>(List.of(pattern)));
}
PATTERNS.put(theme, List.of(pattern));
return pattern;
}


public static List<Pattern> getPatternsForTheme(ConsoleTheme consoleTheme) {
return PATTERNS.get(consoleTheme);
}
Expand Down Expand Up @@ -76,29 +73,36 @@ public static Pattern getPatternFromString(ConsoleTheme consoleTheme, ResourceLo
return patterns.get(0);
}

public static void clearPatterns() {
PATTERNS.clear();
}

@Override
protected void apply(Map<ResourceLocation, JsonElement> object, ResourceManager resourceManager, ProfilerFiller profilerFiller) {

ConsolePatterns.PATTERNS.clear();
object.forEach((resourceLocation, jsonElement) -> {

JsonArray patternsArray = jsonElement.getAsJsonArray();
for (JsonElement patternElement : patternsArray) {
JsonObject patternObject = patternElement.getAsJsonObject();
ConsoleTheme theme = ConsoleTheme.valueOf(findConsoleTheme(resourceLocation));
String id = patternObject.get("id").getAsString();
String texture = patternObject.get("texture").getAsString();

ResourceLocation textureLocation = new ResourceLocation(texture);
Pattern pattern = new Pattern(theme, new ResourceLocation(id), textureLocation);
pattern.setName(patternObject.get("name_component").getAsString());
addPattern(theme, pattern);
try {
JsonArray patternsArray = jsonElement.getAsJsonArray();
for (JsonElement patternElement : patternsArray) {
JsonObject patternObject = patternElement.getAsJsonObject();
ConsoleTheme theme = ConsoleTheme.valueOf(findConsoleTheme(resourceLocation));
String id = patternObject.get("id").getAsString();
String texture = patternObject.get("texture").getAsString();

boolean emissive = patternObject.get("emissive").getAsBoolean();

ResourceLocation textureLocation = new ResourceLocation(texture);
Pattern pattern = new Pattern(theme, new ResourceLocation(id), textureLocation);
pattern.setName(patternObject.get("name_component").getAsString());
pattern.setEmissive(emissive);
addPattern(theme, pattern);
}
} catch (JsonParseException jsonParseException){
TardisRefined.LOGGER.debug("Issue parsing {}! Error: {}", resourceLocation, jsonParseException.getMessage());
}
});

if(Platform.getServer() != null) {
new SyncConsolePatternsMessage(PATTERNS).sendToAll();
}
}

@NotNull
Expand All @@ -116,9 +120,10 @@ private String findConsoleTheme(ResourceLocation resourceLocation) {

public static class Pattern {

private final ResourceLocation textureLocation;
private final ResourceLocation textureLocation, emissiveTexture;
private final ResourceLocation identifier;
private String name;
private boolean hasEmissiveTexture = false;

public ConsoleTheme theme() {
return theme;
Expand All @@ -129,13 +134,15 @@ public ConsoleTheme theme() {
public Pattern(ConsoleTheme consoleTheme, ResourceLocation identifier, ResourceLocation texture) {
this.identifier = identifier;
this.textureLocation = texture;
this.emissiveTexture = new ResourceLocation(texture.getNamespace(), texture.getPath().replace(".png", "_emissive.png"));
this.theme = consoleTheme;
this.name = identifier.getPath().substring(0, 1).toUpperCase() + identifier.getPath().substring(1).replace("_", "");
}

public Pattern(ConsoleTheme consoleTheme, ResourceLocation identifier, String texture) {
this.identifier = new ResourceLocation(identifier.getNamespace(), consoleTheme.getSerializedName() + "/" + identifier.getPath());
this.textureLocation = new ResourceLocation(TardisRefined.MODID, "textures/blockentity/console/" + texture + ".png");
this.emissiveTexture = new ResourceLocation(TardisRefined.MODID, "textures/blockentity/console/" + texture + "_emissive.png");
this.theme = consoleTheme;
this.name = identifier.getPath().substring(0, 1).toUpperCase() + identifier.getPath().substring(1).replace("_", "");
}
Expand All @@ -144,12 +151,25 @@ public String name() {
return name;
}

public boolean emissive() {
return hasEmissiveTexture;
}

public Pattern setEmissive(boolean hasEmissiveTexture) {
this.hasEmissiveTexture = hasEmissiveTexture;
return this;
}

public Pattern setName(String name) {
this.name = name;
return this;
}

public ResourceLocation textureLocation() {
public ResourceLocation emissiveTexture() {
return emissiveTexture;
}

public ResourceLocation texture() {
return textureLocation;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
package whocraft.tardis_refined.client.model.blockentity.console;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import whocraft.tardis_refined.common.block.console.GlobalConsoleBlock;
import whocraft.tardis_refined.common.blockentity.console.GlobalConsoleBlockEntity;
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;

public interface ConsoleUnit {
void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha);
void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha);

default ResourceLocation getTexture(GlobalConsoleBlockEntity entity) {

if (entity == null) return getDefaultTexture();
default ResourceLocation getTexture(GlobalConsoleBlockEntity entity, boolean emissiveTexture) {
if (entity == null || entity.pattern() == null) return getDefaultTexture();
return emissiveTexture ? entity.pattern().emissiveTexture() : entity.pattern().texture();
}

ConsoleTheme console = entity.getBlockState().getValue(GlobalConsoleBlock.CONSOLE);
return entity.pattern().textureLocation();
default ResourceLocation getTexture(GlobalConsoleBlockEntity entity) {
return getTexture(entity, false);
}

default ModelPart findPart(HierarchicalModel hierarchicalModel, String string) {
return hierarchicalModel.root().getAllParts().filter((modelPart) -> {
return modelPart.hasChild(string);
}).findFirst().map((modelPart) -> {
return modelPart.getChild(string);
}).get();
return hierarchicalModel.root().getAllParts().filter((modelPart) -> modelPart.hasChild(string)).findFirst().map((modelPart) -> modelPart.getChild(string)).get();
}

ResourceLocation getDefaultTexture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -2250,7 +2248,7 @@ public void setupAnim(Entity entity, float f, float g, float h, float i, float j
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
this.modelRoot.getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());

Expand All @@ -2261,7 +2259,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);

this.throttle.zRot = (reactions.isThrottleDown()) ? -1f : 1f;
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));
modelRoot.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,7 @@ public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, i
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);

TardisClientData reactions = TardisClientData.getInstance(level.dimension());
Expand All @@ -3539,8 +3539,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev

this.throttle.xRot = (reactions.isThrottleDown()) ? 2f : 0f;

VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));

base_console.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
anim_parts.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3779,7 +3779,7 @@ public ModelPart root() {


@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());

Expand All @@ -3791,7 +3791,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev

this.throttle.xRot = (reactions.isThrottleDown()) ? -25f : -32f;

VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));
base_control.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
rotor.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
rotor_purple.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, i


@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);
Expand All @@ -2261,7 +2261,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
}

this.throttleLever.xRot = (reactions.isThrottleDown()) ? -155: -125;
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));
console_factory.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,7 @@ public void setupAnim(Entity entity, float f, float g, float h, float i, float j
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);
Expand All @@ -3251,7 +3251,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
}

throttle.xRot = (reactions.isThrottleDown()) ? 1f : -1f;
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityCutout(getTexture(globalConsoleBlock)));
root.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package whocraft.tardis_refined.client.model.blockentity.console;// Made with Blockbench 4.5.2
// Exported for Minecraft version 1.17 - 1.18 with Mojang mappings
// Paste this class into your mod and generate all required imports

package whocraft.tardis_refined.client.model.blockentity.console;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down Expand Up @@ -599,13 +596,12 @@ public void setupAnim(Entity entity, float f, float g, float h, float i, float j
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
this.animate(reactions.ROTOR_ANIMATION, MODEL_ROTOR_LOOP, Minecraft.getInstance().player.tickCount);

throttle_control.xRot = (reactions.isThrottleDown()) ? 1f : -1f;
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));

this.root.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public void setupAnim(Entity entity, float f, float g, float h, float i, float j
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);
panels.getAllParts().forEach(ModelPart::resetPose);
console.getAllParts().forEach(ModelPart::resetPose);
Expand All @@ -506,9 +506,6 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev

throttle.xRot = (reactions.isThrottleDown()) ? 1f : -1f;

VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));


rotor_zminus3_yplus5_rotateY.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
panels.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
console.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ public void setupAnim(Entity entity, float f, float g, float h, float i, float j
}

@Override
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level level, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root().getAllParts().forEach(ModelPart::resetPose);

TardisClientData reactions = TardisClientData.getInstance(level.dimension());
Expand All @@ -1494,11 +1494,7 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
}

this.animate(reactions.ROTOR_ANIMATION, FLIGHT, Minecraft.getInstance().player.tickCount);

this.throttle.xRot = (reactions.isThrottleDown()) ? -1f : 1f;

VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityTranslucent(getTexture(globalConsoleBlock)));

this.root().render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}

Expand Down
Loading