diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..282904d --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,49 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install 7z and extract data + run: | + sudo apt-get install -y p7zip-full + mkdir ~/.gradle + mkdir ~/.gradle/caches + cd ~/.gradle/caches + 7z x /home/runner/work/Traincraft-Community-Pack/Traincraft-Community-Pack/gradle/caches.7z.001 -y + cd /home/runner/work/Traincraft-Community-Pack/Traincraft-Community-Pack + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Retrieve base mod + run: ./gradlew getTrainAPIAutoBuild + + - name: setup with Gradle + run: ./gradlew setupDecompWorkspace --refresh-dependencies idea + + - name: Build with Gradle + run: ./gradlew setupDecompWorkspace --refresh-dependencies build + + - name: Create artifact + uses: actions/upload-artifact@v2 + with: + name: TCCE-Addon-Experimental + path: build/libs/* diff --git a/.gitmodules b/.gitmodules index 063fa78..65336c4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,5 @@ [submodule "submodules/Traincraft"] path = submodules/Traincraft url = https://github.com/TheDoctor1138/Traincraft-5.git - branch = TC4.5-1.7.10 \ No newline at end of file + branch = TC4.5-1.7.10 + update = merge diff --git a/build.gradle b/build.gradle index b93ec0f..b288cfd 100644 --- a/build.gradle +++ b/build.gradle @@ -82,7 +82,7 @@ task buildSubmoduleJar(type: GradleBuild) { task copySubmoduleJar(type: Copy, dependsOn: buildSubmoduleJar) { description = 'Copies the JAR from the submodule to the main repository' - from 'submodules/Traincraft/build/libs' // The directory where the submodule's JAR is located + from 'submodules/Traincraft/build/lib' // The directory where the submodule's JAR is located into 'libs' // The destination directory in the main repository include '*.jar' } @@ -129,7 +129,7 @@ dependencies { implementation "train:Traincraft-4.4.1_020-CE_7.1" // quality of life line to simplify importing jars for experimental testing - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(dir: 'lib', include: ['*.jar']) } idea diff --git a/gradle/caches.7z.001 b/gradle/caches.7z.001 new file mode 100644 index 0000000..44bd3a3 Binary files /dev/null and b/gradle/caches.7z.001 differ diff --git a/gradle/caches.7z.002 b/gradle/caches.7z.002 new file mode 100644 index 0000000..1fc4499 Binary files /dev/null and b/gradle/caches.7z.002 differ diff --git a/gradle/caches.7z.003 b/gradle/caches.7z.003 new file mode 100644 index 0000000..18af36c Binary files /dev/null and b/gradle/caches.7z.003 differ diff --git a/gradle/caches.7z.004 b/gradle/caches.7z.004 new file mode 100644 index 0000000..da70a85 Binary files /dev/null and b/gradle/caches.7z.004 differ diff --git a/gradle/caches.7z.005 b/gradle/caches.7z.005 new file mode 100644 index 0000000..150b029 Binary files /dev/null and b/gradle/caches.7z.005 differ diff --git a/gradle/caches.7z.006 b/gradle/caches.7z.006 new file mode 100644 index 0000000..8a73887 Binary files /dev/null and b/gradle/caches.7z.006 differ diff --git a/gradle/caches.7z.007 b/gradle/caches.7z.007 new file mode 100644 index 0000000..7b8e812 Binary files /dev/null and b/gradle/caches.7z.007 differ diff --git a/src/main/java/tcce/client/core/handlers/RecipeBookHandler.java b/src/main/java/tcce/client/core/handlers/RecipeBookHandler.java new file mode 100644 index 0000000..5a05db7 --- /dev/null +++ b/src/main/java/tcce/client/core/handlers/RecipeBookHandler.java @@ -0,0 +1,73 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package tcce.client.core.handlers; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import net.minecraft.item.Item; +import train.common.core.interfaces.ITCRecipe; +import train.common.core.managers.TierRecipe; +import train.common.recipes.ShapedTrainRecipes; +import train.common.recipes.ShapelessTrainRecipe; + +public class RecipeBookHandler { + public static String[] vanillaWorkTableRecipes = new String[21]; + + public RecipeBookHandler() { + } + + public static List workbenchListCleaner(List recipeList) { + Set outputs = new HashSet(); + ArrayList cleaned = new ArrayList(); + Iterator var3 = recipeList.iterator(); + + while(true) { + Object r; + do { + if (!var3.hasNext()) { + return cleaned; + } + + r = var3.next(); + } while(!(r instanceof ShapedTrainRecipes) && !(r instanceof ShapelessTrainRecipe)); + + ITCRecipe recipe = (ITCRecipe)r; + String output = Item.itemRegistry.getNameForObject(recipe.getRecipeOutput().getItem()); + if (!outputs.contains(output)) { + if (!output.contains("tc:")) { + cleaned.add(recipe); + outputs.add(output); + } + } + } + } + + public static List assemblyListCleaner(List recipeList) { + Set outputs = new HashSet(); + ArrayList cleanedList = new ArrayList(); + Iterator var3 = recipeList.iterator(); + + while(var3.hasNext()) { + Object r = var3.next(); + if (r instanceof TierRecipe) { + TierRecipe recipe = (TierRecipe)r; + String output = Item.itemRegistry.getNameForObject(recipe.getOutput().getItem()); + if (!outputs.contains(output)) { + if (!output.contains("tc:")) { + cleanedList.add(recipe); + outputs.add(output); + } + } + } + } + + return cleanedList; + } +} diff --git a/src/main/java/tcce/client/render/TCCERenderEnum.java b/src/main/java/tcce/client/render/TCCERenderEnum.java new file mode 100644 index 0000000..ab18e98 --- /dev/null +++ b/src/main/java/tcce/client/render/TCCERenderEnum.java @@ -0,0 +1,148 @@ +package tcce.client.render; + + + + + +import fexcraft.tmt.slim.ModelBase; +import tcce.common.library.TCCEInfo; +import train.common.api.EntityRollingStock; +import train.common.api.TrainRenderRecord; +import net.minecraft.util.ResourceLocation; + + +import java.util.ArrayList; + +public enum TCCERenderEnum implements TrainRenderRecord { + + + ; + private Class entityClass; + private final ModelBase model; + private String texture; + private boolean multiTexture; + private float[] trans; + private float[] rotate; + private float[] scale; + private String smokeType; + private ArrayList smokeFX; + private String explosionType; + private ArrayList explosionFX; + private int smokeIterations; + private int explosionFXIterations; + private boolean hasSmokeOnSlopes; + + /** + * Defines the render @param for a RollingStock + * + * @param model ModelBase + * @param texture String + * @param multiTexture boolean + * @param trans float[] + * @param rotate float[] + * @param scale float[] + * @param smokeType String + * @param smokeFX ArrayList + * @param explosionType String + * @param explosionFX ArrayList + */ + TCCERenderEnum(Class entityClass, ModelBase model, String texture, boolean multiTexture, float[] trans, float[] rotate, float[] scale, String smokeType, int smokeIterations, ArrayList smokeFX, String explosionType, ArrayList explosionFX, int explosionFXIterations, boolean hasSmokeOnSlopes) { + this.entityClass = entityClass; + this.model = model; + this.texture = texture; + this.multiTexture = multiTexture; + this.trans = trans; + this.rotate = rotate; + this.scale = scale; + this.smokeType = smokeType; + this.smokeFX = smokeFX; + this.explosionType = explosionType; + this.explosionFX = explosionFX; + this.smokeIterations = smokeIterations; + this.explosionFXIterations = explosionFXIterations; + this.hasSmokeOnSlopes = hasSmokeOnSlopes; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public ModelBase getModel() { + return model; + } + + public boolean getIsMultiTextured() { + return multiTexture; + } + + @Override + public boolean hasSmoke() { + return smokeType.length() > 0; + } + + @Override + public boolean hasSmokeOnSlopes() { + return hasSmokeOnSlopes; + } + + @Override + public String getSmokeType() { + return smokeType; + } + + @Override + public ArrayList getSmokeFX() { + return smokeFX; + } + + @Override + public String getExplosionType() { + return explosionType; + } + + @Override + public boolean hasExplosion() { + return explosionType.length() > 0; + } + + @Override + public ArrayList getExplosionFX() { + return explosionFX; + } + + @Override + public float[] getTrans() { + return trans; + } + + @Override + public float[] getRotate() { + return rotate; + } + + @Override + public float[] getScale() { + return scale; + } + + @Override + public ResourceLocation getTextureFile(String colorString) { + if (multiTexture) { + return new ResourceLocation(TCCEInfo.resourceLocation, TCCEInfo.trainsPrefix + texture + colorString + ".png"); + } else { + return new ResourceLocation(TCCEInfo.resourceLocation, TCCEInfo.trainsPrefix + texture + ".png"); + } + } + + @Override + public int getSmokeIterations() { + return smokeIterations; + } + + @Override + public int getExplosionFXIterations() { + return explosionFXIterations; + } +} diff --git a/src/main/java/tcce/common/TCCE.java b/src/main/java/tcce/common/TCCE.java new file mode 100644 index 0000000..76b928f --- /dev/null +++ b/src/main/java/tcce/common/TCCE.java @@ -0,0 +1,97 @@ +package tcce.common; + +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStoppedEvent; +import cpw.mods.fml.common.network.NetworkRegistry; +import net.minecraft.creativetab.CreativeTabs; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import tcce.common.items.TCCEItems; +import tcce.common.library.TCCEInfo; +import tcce.common.library.TCCERegistry; +import train.common.core.CommonProxy; +import train.common.core.handlers.EntityHandler; + +@Mod(modid = TCCEInfo.modID, name = TCCEInfo.modName, version = TCCEInfo.modVersion) +public class TCCE { + + /* TrainCraft instance */ + @Mod.Instance(TCCEInfo.modID) + public static TCCE instance; + + @SidedProxy(clientSide = "com.thedoctor1138.train.client.core.ClientProxy", serverSide = "com.thedoctor1138.train.common.core.CommonProxy") + public static CommonProxy proxy; + + /* TrainCraft Logger */ + public static Logger tcLog = LogManager.getLogger(TCCEInfo.modName); + +// public static File configDirectory; + + /* Creative tab for Traincraft */ + public static CreativeTabs tcMLPTab; + + private TCCERegistry registry; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) { + tcLog.info("Starting Traincraft MLP Addon " + TCCEInfo.modVersion + "!"); + + /* Config handler */ +// configDirectory= event.getModConfigurationDirectory(); + + /* Register Items, Blocks, ... */ + tcLog.info("Initialize Blocks, Items, ..."); + + tcMLPTab = new TCCECreativeTabTraincraftTrains(CreativeTabs.getNextID(), "TCMLP"); + + + TCCEItems.init(); + EntityHandler.init(); + + /* Other Proxy init */ + tcLog.info("Initialize Renderer and Events"); + + registry = new TCCERegistry(); + registry.init(); + + tcLog.info("Finished PreInitialization"); + } + + + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + } + + @Mod.EventHandler + public void load(FMLInitializationEvent event) { + + + + tcLog.info("Initialize Gui"); + NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); + + + tcLog.info("Initialize Recipes"); + TCCERecipeHandler.initBlockRecipes(); + TCCERecipeHandler.initItemRecipes(); + TCCERecipeHandler.initSmeltingRecipes(); + AssemblyTableRecipes.recipes(); + + proxy.registerBookHandler(); + + + } + + @Mod.EventHandler + public void postInit(FMLPostInitializationEvent evt) { + } + + @Mod.EventHandler + public void serverStop(FMLServerStoppedEvent event) { + } +} } \ No newline at end of file diff --git a/src/main/java/tcce/common/items/TCMLPItems.java b/src/main/java/tcce/common/items/TCMLPItems.java new file mode 100644 index 0000000..3698e96 --- /dev/null +++ b/src/main/java/tcce/common/items/TCMLPItems.java @@ -0,0 +1,44 @@ +/** ***************************************************************************** + * Copyright (c) 2012 Mrbrutal. All rights reserved. + * + * @name TrainCraft + * @author Mrbrutal + ***************************************************************************** + */ +package tcce.common.items; + +import cpw.mods.fml.common.registry.GameRegistry; +import tcce.common.TCCE; +import tcce.common.library.TCCEInfo; +import tcce.common.library.TCCEItemIDs; +import train.common.items.ItemRollingStock; + +public class TCCEItems { + + public static void init() { + loadItems(); + registerItems(); + } + + private static void loadItems() { + for (TCCEItemIDs items : TCCEItemIDs.values()) { + if (items.className != null) { + if (items.className.equals("ItemRollingStock")) { + items.item = new ItemRollingStock(TCCEInfo.modID.toLowerCase() + ":trains/" + items.iconName, TCCE.TCCETab); + } + } + } + + + + } + + private static void registerItems() { + for (TCCEItemIDs itemId : TCCEItemIDs.values()) { + if (itemId.item != null) { + itemId.item.setUnlocalizedName(TCCEInfo.modID + ":" + itemId.name()); + GameRegistry.registerItem(itemId.item, itemId.name()); + } + } + } +} diff --git a/src/main/java/tcce/common/library/GuiIDs.java b/src/main/java/tcce/common/library/GuiIDs.java new file mode 100644 index 0000000..7a87aae --- /dev/null +++ b/src/main/java/tcce/common/library/GuiIDs.java @@ -0,0 +1,10 @@ +package com.thedoctor1138.train.common.library; + +public class GuiIDs { + + public static final int RECIPE_BOOK = 79; + + + public GuiIDs() { + } +} \ No newline at end of file diff --git a/src/main/java/tcce/common/library/TCCEEnumSounds.java b/src/main/java/tcce/common/library/TCCEEnumSounds.java new file mode 100644 index 0000000..0de212d --- /dev/null +++ b/src/main/java/tcce/common/library/TCCEEnumSounds.java @@ -0,0 +1,99 @@ +package tcce.common.library; + +import train.common.api.TrainSoundRecord; + + +public enum TCCEEnumSounds implements TrainSoundRecord { + + ; + + private Class entityClass; + private String horn; + private float hornVolume; + private String run; + private String idle; + private float runVolume; + private float idleVolume; + private int runSoundLenght; + private int idleSoundLenght; + private boolean soundChangeWithSpeed; + + /** + * Defines the sounds for the locomotives Many locomotives have the same sound for run and idle + * + * @param entityClass + * @param horn + * @param hornVolume + * @param run + * @param runVolume + * @param runSoundLenght + * @param idle + * @param idleVolume + * @param idleSoundLenght + * @param soundChangeWithSpeed + */ + private TCCEEnumSounds(Class entityClass, String horn, float hornVolume, String run, float runVolume, int runSoundLenght, String idle, float idleVolume, int idleSoundLenght, boolean soundChangeWithSpeed) { + this.entityClass = entityClass; + this.horn = horn; + this.hornVolume = hornVolume; + this.run = run; + this.idle = idle; + this.runVolume = runVolume; + this.idleVolume = idleVolume; + this.runSoundLenght = runSoundLenght; + this.idleSoundLenght = idleSoundLenght; + this.soundChangeWithSpeed = soundChangeWithSpeed; + } + + @Override + public Class getEntityClass() { + return entityClass; + } + + @Override + public String getHornString() { + if (horn == null || horn.isEmpty() || horn.startsWith(TCCEInfo.resourceLocation + ":")) return horn; + return TCCEInfo.resourceLocation + ":" + horn; + } + + @Override + public String getRunString() { + if (run == null || run.isEmpty() || run.startsWith(TCCEInfo.resourceLocation + ":")) return run; + return TCCEInfo.resourceLocation + ":" + run; + } + + @Override + public String getIdleString() { + if (idle == null || idle.isEmpty() || idle.startsWith(TCCEInfo.resourceLocation + ":")) return idle; + return TCCEInfo.resourceLocation + ":" + idle; + } + + @Override + public Float getHornVolume() { + return hornVolume; + } + + @Override + public Float getRunVolume() { + return runVolume; + } + + @Override + public Float getIdleVolume() { + return idleVolume; + } + + @Override + public int getRunSoundLength() { + return runSoundLenght; + } + + @Override + public int getIdleSoundLength() { + return idleSoundLenght; + } + @Override + public boolean getSoundChangeWithSpeed() { + return soundChangeWithSpeed; + } +} diff --git a/src/main/java/tcce/common/library/TCCEEnumTrains.java b/src/main/java/tcce/common/library/TCCEEnumTrains.java new file mode 100644 index 0000000..d58559f --- /dev/null +++ b/src/main/java/tcce/common/library/TCCEEnumTrains.java @@ -0,0 +1,31 @@ +package tcce.common.library; + +import train.common.api.TrainRecord; + + +public class TCCEEnumTrains { + public static TrainRecord[] trains() { + return new TrainRecord[]{ + + }; + + } +} + /** + * + * @param internalName : Only used by EntityRegistry + * @param entityClass + * @param item + * @param trainType: "steam", "diesel", "freight", "passenger", "special", "flat", "electric" + * @param MHP: power of the locomotive + * @param maxSpeed + * @param mass (will be multiplied by 10 internally. That means putting 0.1 here will create a mass of 1 Ton in game) + * @param fuelConsumption: 1 unit is consumed every x ticks + * @param waterConsumption: 1 unit is consumed every x ticks + * @param heatingTime + * @param accelerationRate: generally around 0.45 + * @param brakeRate: generally around 0.98 + * @param tankCapacity + * @param colors: an array with all possible colors. Index 0 is used as default color when train is first spawned. leave null if no color available + * @param guiRenderScale: scale at which the entity will be rendered inside the GUI (crafting GUI) + */ diff --git a/src/main/java/tcce/common/library/TCCEInfo.java b/src/main/java/tcce/common/library/TCCEInfo.java new file mode 100644 index 0000000..18974d1 --- /dev/null +++ b/src/main/java/tcce/common/library/TCCEInfo.java @@ -0,0 +1,22 @@ +package tcce.common.library; + +public class TCCEInfo { + + /* Mod relevant information */ + public static final String modID = "tc"; + public static final String modName = "Community Edition Addon For Traincraft"; + public static final String modVersion = "0.0"; + public static final String channel = "TCCE"; + public static final String keyChannel = "TCCEKey"; + public static final String rotationChannel = "TCCERotation"; + + /* Localization keys for versioning */ + + /* All the resources for the mod */ + public static final String resourceLocation = "tcce"; + public static final String guiPrefix = "textures/gui/"; + public static final String bookPrefix = "textures/gui/book/"; + + public static final String trainsPrefix = "textures/trains/"; + public static final String modelTexPrefix = "textures/models/"; +} \ No newline at end of file diff --git a/src/main/java/tcce/common/library/TCCEItemIDs.java b/src/main/java/tcce/common/library/TCCEItemIDs.java new file mode 100644 index 0000000..a67fe60 --- /dev/null +++ b/src/main/java/tcce/common/library/TCCEItemIDs.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2012 mrbrutal. All rights reserved. + * + * @name TrainCraft + * @author mrbrutal + ******************************************************************************/ + +package tcce.common.library; + +import net.minecraft.item.Item; + +public enum TCCEItemIDs { + + //Items + + recipeBook("ItemRecipeBook", "item_book_blue", 1), + + //Rollingstock + + + ; + + public Item item; + public String className; + public String iconName; + + /** + * amount for one emerald. For ItemRollingStock, it is the price for one train + */ + public int amountForEmerald; + + /** + * @param classMethodName + * @param iconName + * @param amountForEmerald for one emerald. For ItemRollingStock, it is the price for one train + */ + TCCEItemIDs(String classMethodName, String iconName, int amountForEmerald) { + this.className = classMethodName; + this.iconName = iconName; + this.amountForEmerald = amountForEmerald; + } + +} \ No newline at end of file diff --git a/src/main/java/tcce/common/library/TCMLPRegistry.java b/src/main/java/tcce/common/library/TCMLPRegistry.java new file mode 100644 index 0000000..83b0e96 --- /dev/null +++ b/src/main/java/tcce/common/library/TCMLPRegistry.java @@ -0,0 +1,77 @@ +package tcce.common.library; + + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.item.Item; +import train.common.api.TrainRecord; +import train.common.Traincraft; +import train.common.api.TrainRenderRecord; +import train.common.api.TrainSoundRecord; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TCCERegistry { + + private List trainRecords = new ArrayList<>(); + private Map trainRecordsByItem = new HashMap<>(); + private Map, TrainRenderRecord> trainRenderRecords = new HashMap<>(); + private List trainSoundRecords = new ArrayList<>(); + + public void init() { + for (TrainRecord train : TCCEEnumTrains.trains()) { + Traincraft.instance.traincraftRegistry.registerTrainRecord(train); + } + + Side side = FMLCommonHandler.instance().getEffectiveSide(); + if (side == Side.CLIENT) { + for (TCCERenderEnum render : TCCERenderEnum.values()) { + Traincraft.instance.traincraftRegistry.registerTrainRenderRecord(render); + } + } + + for (TrainSoundRecord sound : TCCEEnumSounds.values()) { + Traincraft.instance.traincraftRegistry.registerTrainSoundRecord(sound); + } + } + + public TrainRecord getTrainRecord(Class entityClass) { + if (entityClass == null) return null; + + for (TrainRecord record : trainRecords) { + if (entityClass.equals(record.getEntityClass())) { + return record; + } + } + return null; + } + + + public void registerTrainRecord(TrainRecord record) { + trainRecords.add(record); + trainRecordsByItem.put(record.getItem(), record); + } + + public void registerTrainRenderRecord(TrainRenderRecord record) { + trainRenderRecords.put(record.getEntityClass(), record); + addLivery(train.common.entity.rollingStock.EntityBoxCartUS.class, "burple"); + } + + public void addLivery(Class entityClass, String name){ + for (TrainRecord record : trainRecords) { + if (entityClass.equals(record.getEntityClass())) { + record.skins.add(name); + } + } + } + + + public void registerTrainSoundRecord(TrainSoundRecord sound) { + trainSoundRecords.add(sound); + } + +} diff --git a/submodules/Traincraft b/submodules/Traincraft index aed47f7..0a18e2b 160000 --- a/submodules/Traincraft +++ b/submodules/Traincraft @@ -1 +1 @@ -Subproject commit aed47f72c7e449ee802cc664dbb0a2ec408c98d7 +Subproject commit 0a18e2ba79880d55c1059f99901a80d8ecf134ad