Skip to content

Commit

Permalink
Merge pull request #4 from Iteranya/1.20.1
Browse files Browse the repository at this point in the history
1.20.1
  • Loading branch information
Iteranya authored Nov 3, 2024
2 parents e667a12 + 9b870e1 commit cf201fc
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 340 deletions.
61 changes: 6 additions & 55 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}


group = mod_version
version = mod_group_id

Expand All @@ -21,31 +18,13 @@ java {
minecraft {
mappings channel: mapping_channel, version: mapping_version

// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// enableEclipsePrepareRuns = true
// enableIdeaPrepareRuns = true

// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
// It is REQUIRED to be set to true for this template to function.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
copyIdeResources = true

runs {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'


// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

mods {
Expand All @@ -56,7 +35,6 @@ minecraft {
}

client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id
}

Expand All @@ -65,29 +43,19 @@ minecraft {
args '--nogui'
}

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
property 'forge.enabledGameTestNamespaces', mod_id
}

data {
// example of overriding the workingDirectory set in configureEach above
workingDirectory project.file('run-data')

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
}
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
configurations {
shade
implementation.extendsFrom shade
}

repositories {
mavenCentral()
maven {
Expand All @@ -96,28 +64,12 @@ repositories {
maven {
url = 'https://maven.minecraftforge.net/'
}

}

dependencies {

minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
implementation 'com.fasterxml.jackson.core:jackson-core:2.16.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.16.1'

minecraftLibrary 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
minecraftLibrary 'com.fasterxml.jackson.core:jackson-core:2.16.1'
minecraftLibrary 'com.fasterxml.jackson.core:jackson-annotations:2.16.1'


}

// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
Expand All @@ -131,26 +83,25 @@ tasks.named('processResources', ProcessResources).configure {

filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}}
}
}

// Example for how to get properties into the manifest for reading at runtime.
tasks.named('jar', Jar).configure {
manifest {
attributes([
"Specification-Title": mod_id,
"Specification-Vendor": mod_authors,
"Specification-Version": "1", // We are version 1 of ourselves
"Specification-Version": "1",
"Implementation-Title": project.name,
"Implementation-Version": project.jar.archiveVersion,
"Implementation-Vendor": mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}

// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
options.encoding = 'UTF-8'
}
16 changes: 9 additions & 7 deletions src/main/java/org/arsparadox/mobtalkerredux/MobTalkerRedux.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ public void onServerStarting(ServerStartingEvent event) {
@Mod.EventBusSubscriber(modid = "mobtalkerredux", bus = Mod.EventBusSubscriber.Bus.MOD)
public class RegistryEvents {

@SubscribeEvent
public void buildContents(BuildCreativeModeTabContentsEvent event) {
// Add to ingredients tab
if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) {
event.accept(HELLO_WORLD_ITEM);
}
}


public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "mobtalkerredux");
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "mobtalkerredux");
Expand All @@ -102,5 +96,13 @@ public static void initialize() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
register(modEventBus);
}

@SubscribeEvent
public void buildContents(BuildCreativeModeTabContentsEvent event) {
// Add to ingredients tab
if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) {
event.accept(HELLO_WORLD_ITEM);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package org.arsparadox.mobtalkerredux.vn.controller;

import net.minecraft.resources.ResourceLocation;
import org.arsparadox.mobtalkerredux.vn.data.DialogueState;
import org.arsparadox.mobtalkerredux.vn.data.SpriteState;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class VisualNovelEngine {
public boolean shutdown = false;
private List<Map<String, Object>> gameData;
private int currentState=0;
private long currentState=0;
private Map<String, Object> variables;

public DialogueState state;
Expand All @@ -21,32 +18,75 @@ public VisualNovelEngine(List<Map<String, Object>> gameData) {
this.gameData = gameData;
this.currentState = 0;
this.variables = new HashMap<>();
this.state = new DialogueState(null,null,null,null);
this.state = new DialogueState(null,null,null);
}

private Integer findLabelId(String var) {
private Long findLabelId(String var) {
return gameData.stream()
.filter(action -> "label".equals(action.get("type")) && var.equals(action.get("label")))
.map(action -> (int) action.get("id"))
.map(action -> (long) action.get("id"))
.findFirst()
.orElse(null);
}

private Map<String, Object> getDictById(int targetId) {
private Map<String, Object> getDictById(long targetId) {
return gameData.stream()
.filter(action -> targetId == (int) action.get("id"))
.filter(action -> targetId == (long) action.get("id"))
.findFirst()
.orElse(null);
}

private void updateSprite(String spritePath) {
ResourceLocation location = new ResourceLocation(
"mobtalkerredux", "textures/" + spritePath
);
state.setSprite(location);
this.currentState++;
private void removeSprite(String remove){
System.out.println("Try to remove sprite: "+ remove);
removeSpriteByFolder(this.state.getSprites(), remove);
}

private void updateSprite(Map<String, Object> sprite) {
String spritePos;
if(sprite.get("position")==null){
spritePos = "CUSTOM";
}
else{
spritePos = (String) sprite.get("position");
}
SpriteState newSprite;
newSprite = (new SpriteState(
(String) sprite.get("sprite"),
(String) sprite.get("location"),
spritePos
));

if(Objects.equals((String) sprite.get("action"), "show")){
System.out.println("New Sprite: "+newSprite.getSprite());
System.out.println("Old Sprite: "+sprite.get("action"));
if(sprite.get("wRatio")!=null){
newSprite.setPositioning(
((Long) sprite.get("wRatio")).intValue(),
((Long) sprite.get("hRatio")).intValue(),
((Long) sprite.get("wFrameRatio")).intValue(),
((Long) sprite.get("hFrameRatio")).intValue(),
((Long) sprite.get("column")).intValue(),
((Long) sprite.get("row")).intValue()
);
}
for (SpriteState oldSprite: this.state.getSprites()) {
System.out.println("New Sprite: "+oldSprite.getSprite());
System.out.println("Old Sprite: "+newSprite.getSprite());

if(Objects.equals(oldSprite.getSprite(), newSprite.getSprite())){
removeSpriteByFolder(this.state.getSprites(), newSprite.getSprite());
break;
}
}
System.out.println("Adding New Sprite: " + newSprite.getSprite());
this.state.addSprite(newSprite);
}
this.currentState++;
}
public void removeSpriteByFolder(List<SpriteState> sprites, String folderName) {
System.out.println("Remove: "+folderName);
sprites.removeIf(sprite -> sprite.getSprite().equals(folderName));
}
private void updateDialogue(String label, String content) {
state.setLabel(label);
state.setContent(content);
Expand Down Expand Up @@ -93,7 +133,7 @@ private void modifyVariable(String variable, String operation, Object value) {
this.currentState++;
}

private void giveItem(String item, int amount) {
private void giveItem(String item, long amount) {

this.currentState++;
}
Expand All @@ -106,7 +146,7 @@ private void processJump(Map<String, Object> action) {
private void processConditional(Map<String, Object> condition) {
Object var = this.variables.get(condition.get("var"));
Object value = condition.get("value");
int end = (int) condition.get("end");
long end = (long) condition.get("end");

if (value instanceof Map) {
value = processCommand((Map<String, Object>) value);
Expand Down Expand Up @@ -160,8 +200,10 @@ private boolean processAction(Map<String, Object> action) {

switch (actionType) {
case "show_sprite":
updateSprite((String) action.get("location"));
updateSprite(action);
return true;
case "remove_sprite":
removeSprite((String) action.get("sprite"));
case "dialogue":
updateDialogue((String) action.get("label"), (String) action.get("content"));
return true;
Expand All @@ -171,7 +213,7 @@ private boolean processAction(Map<String, Object> action) {
action.get("value"));
break;
case "give_item":
giveItem((String) action.get("item"), (int) action.get("amount"));
giveItem((String) action.get("item"), (long) action.get("amount"));
break;
case "conditional":
processConditional(action);
Expand Down Expand Up @@ -220,7 +262,7 @@ public void runEngine() {
}


public int changeStateByLabel(String label) {
public long changeStateByLabel(String label) {
this.currentState = findLabelId(label);
return this.currentState;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
package org.arsparadox.mobtalkerredux.vn.data;

import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DialogueState {
// This class will represent EVERYTHING visible on screen
// I mean this in the most literal way possible
// Everything on screen will be decided by this class
// Let's *Fucking Do This*
private String label;
private String content;
private ResourceLocation sprite;
private List <SpriteState> sprites = new ArrayList<>();
private List<Map<String, Object>> choices;

public DialogueState(String label, String content, ResourceLocation sprite, List<Map<String, Object>> choices) {
public DialogueState(String label, String content, List<Map<String, Object>> choices) {
this.label = label;
this.content = content;
this.sprite = sprite;
this.choices = choices;

}

// Getters and setters
public String getLabel() { return label; }
public void setLabel(String label) { this.label = label; }
public String getContent() { return content; }
public void setContent(String content) { this.content = content; }
public ResourceLocation getSprite() { return sprite; }
public void setSprite(ResourceLocation sprite) { this.sprite = sprite; }
// public SpriteState getSprite() { return sprite; }
// public void setSprite(SpriteState sprite) { this.sprite = sprite; }

public List<SpriteState> getSprites() { return sprites; }
public void addSprite(SpriteState sprite) { this.sprites.add(sprite); }

public List<Map<String, Object>> getChoices() {
return choices;
Expand Down
Loading

0 comments on commit cf201fc

Please sign in to comment.