Skip to content

Commit

Permalink
Merge pull request #42 from stlngds/master
Browse files Browse the repository at this point in the history
2021-2022 Merge
  • Loading branch information
stlngds authored May 3, 2022
2 parents 1afa45b + c6c0846 commit 5335e6c
Show file tree
Hide file tree
Showing 99 changed files with 1,849 additions and 124 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Electric Blocks

Electric Blocks is a minecraft mod that simulates realistic power transmission.
Electric Blocks is a Minecraft mod that simulates realistic power transmission.

[![Build][build-shield]][build-url]
[![Contributors][contributors-shield]][contributors-url]
Expand All @@ -23,7 +23,9 @@ Electric Blocks is a minecraft mod that simulates realistic power transmission.

## About The Project

Electric Blocks is different from other Minecraft mods. Rather than using our own power flow implementation, this mod uses the heavily tested and validated PandaPower API. This means that the results of power flows are very accurate and can be used for real world modeling and testing of power flow. This tool can be used for educational or engineering purposes.
For all installation and usage information and other documentation, visit our [website](https://electricblocks.github.io).

The Electric Blocks mod brings accurate power flow simulation to Minecraft! Rather than using our own power flow implementation, Electric Blocks uses the heavily tested and validated PandaPower API. This means that the results of power flows are very accurate and can be used for real world modeling and testing of power flow.

### Built With

Expand All @@ -32,15 +34,15 @@ Electric Blocks is different from other Minecraft mods. Rather than using our ow

## Installation

To use this mod, you must have Forge version 1.15.2 installed. For single player, [EBPP](https://github.com/ElectricBlocks/ebpp) must be installed and running on your computer. For multiplayer, only the computer running the Forge server needs to have [EBPP](https://github.com/ElectricBlocks/ebpp) installed.
To use this mod, you **must** have Forge version 1.15.2 **and** the [HWYLA](https://www.curseforge.com/minecraft/mc-mods/hwyla/files/2880069) mod installed. For single player, the power flow simulation server [EBPP](https://github.com/ElectricBlocks/ebpp) must be installed and running on your computer. For multiplayer, only the computer running the Forge server needs to have [EBPP](https://github.com/ElectricBlocks/ebpp) installed.

### Prebuilt JAR

First make sure you have MC Forge installed. If you want to play single player or host a multiplayer server then you will need to have EBPP installed and running as well. Then go to our releases page and download the latest release: https://github.com/ElectricBlocks/electricblocks/releases/

Move the JAR file into your mods folder and start up MC Forge.

### Manual Install
### Building from Source

To build from sources, you will need:
* Java 8 JDK
Expand All @@ -54,13 +56,15 @@ gradlew jar
```
We recommend using the included gradle wrapper. We are using version 4.10.3. Newer versions of gradle may cause this build to fail.

This may take a while. Once built, the JAR should be located in `./build/reobfJar/output.jar`
This may take a while. Once built, the JAR should be located in `./build/reobfJar/output.jar`.

Copy this JAR file into your mods folder and start MC Forge.

If compiling with an IDE, we recommend IntelliJ. If you encounter errors during compilation, you may need to add the HWYLA sources jar as a library.

## Usage

TODO: Create useage info
For usage info,

## Contributing

Expand All @@ -72,10 +76,13 @@ Distributed under the GNU Affero General Public License. See [LICENSE.md](LICENS

## Acknowledgements

This software is developed by students at the University of Idaho for the Capstone Design class:
This software has been developed by the following students at the University of Idaho for the 2020-21 and 2021-22 Senior Capstone Design courses:

* Zachary Sugano - Project Lead - [zachoooo](https://github.com/zachoooo)
* Christian Whitfield - Team Member/Communications Lead - [oceanwhit](https://github.com/oceanwhit)
* 21-22: Ryan Buckel - [gellyboi](https://github.com/gellyboi)
* 21-22: Samuel Frederickson - [SamFrederickson](https://github.com/SamFrederickson)
* 21-22: Greyson Biggs - [stlngds](https://github.com/stlngds)
* 20-21: Zachary Sugano - Project Lead - [zachoooo](https://github.com/zachoooo)
* 20-21: Christian Whitfield - Team Member/Communications Lead - [oceanwhit](https://github.com/oceanwhit)

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.0.0'
version = '2.0.0'
group = 'edu.uidaho.electricblocks' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'electricblocks'

Expand Down Expand Up @@ -85,6 +85,13 @@ minecraft {
}
}

repositories {
maven {
name = "TehNut's Maven (HWYLA)"
url "https://maven.tehnut.info/"
}
}

dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
Expand All @@ -109,6 +116,7 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

compile fg.deobf("mcp.mobius.waila:Hwyla:${hwyla_version}")
}

// Example for how to get properties into the manifest for reading by the runtime..
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.daemon=false

minecraft_version=1.15.2
forge_version=1.15.2-31.1.60
mcp_version=20200514-1.15.1
hwyla_version=1.10.8-B72_1.15.2
Binary file added saves/Electric Blocks.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/edu/uidaho/electricblocks/EBHWYLAPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package edu.uidaho.electricblocks;

import mcp.mobius.waila.api.IRegistrar;
import mcp.mobius.waila.api.IWailaPlugin;
import mcp.mobius.waila.api.WailaPlugin;

@WailaPlugin
public class EBHWYLAPlugin implements IWailaPlugin {
@Override
public void register (IRegistrar hwyla) {
//Each HWYLA feature (in the plugins folder) must be "declared"/referenced in ElectricBlocksMod.java
ElectricBlocksMod.getFeatures().forEach(f -> f.initialize(hwyla));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ElectricBlocksConfig {
}

private static String hostURL;
private static String proxyURL;
private static boolean updateOnBlockBreak;
private static boolean logJSONRequests;

Expand Down Expand Up @@ -57,6 +58,7 @@ public static boolean getLogJSONRequests() {

public static void bakeConfig() {
hostURL = SERVER.hostURL.get();
proxyURL = SERVER.proxyURL.get();
updateOnBlockBreak = SERVER.updateOnBlockBreak.get();
logJSONRequests = SERVER.logJSONRequests.get();
}
Expand All @@ -71,6 +73,7 @@ public static void onModConfigEvent(final ModConfig.ModConfigEvent configEvent)
public static class ServerConfig {

public final ConfigValue<String> hostURL;
public final ConfigValue<String> proxyURL;
public final BooleanValue updateOnBlockBreak;
public final BooleanValue logJSONRequests;

Expand All @@ -79,6 +82,10 @@ public ServerConfig(ForgeConfigSpec.Builder builder) {
.comment("Host of EBPP Simulation Server including port and endpoint")
.translation("config.electricblocks.hostURL")
.define("hostURL", "http://127.0.0.1:1127/api");
proxyURL = builder
.comment("Proxy of EBPP Simulation Server including port and address")
.translation("config.electricblocks.proxyURL")
.define("proxyURL", "http://127.0.0.1:1126");
updateOnBlockBreak = builder
.comment("Whether or not the simulation should be updated when an electric block is broken")
.translation("config.electricblocks.update_on_block_break")
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/edu/uidaho/electricblocks/ElectricBlocksMod.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package edu.uidaho.electricblocks;

import edu.uidaho.electricblocks.lib.Feature;
import edu.uidaho.electricblocks.network.ElectricBlocksPacketHandler;
import edu.uidaho.electricblocks.utils.ClientUtils;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -21,6 +23,13 @@
import edu.uidaho.electricblocks.eventhandlers.BlockEventHandler;
import edu.uidaho.electricblocks.simulation.SimulationHandler;

import edu.uidaho.electricblocks.plugins.FeatureEBInService;
import edu.uidaho.electricblocks.plugins.FeatureEBInputs;
import edu.uidaho.electricblocks.plugins.FeatureEBOutputs;

import java.text.DecimalFormat;
import java.util.List;

/**
* ElectricBlocks main class. This is what gets everything started.
*/
Expand All @@ -31,6 +40,9 @@ public class ElectricBlocksMod {

public static final Logger LOGGER = LogManager.getLogger(); // Reference to L4J Logger

public static final DecimalFormat FORMAT = new DecimalFormat("#.##");
private static final List<Feature> features = NonNullList.create();

// Creates a new tab group in the creative menu for all the blocks and items in
// this mod
public static final ItemGroup TAB = new ItemGroup("ebtab") {
Expand All @@ -57,8 +69,16 @@ public ElectricBlocksMod() {
ElectricBlocksPacketHandler.registerPackets();

RegistryHandler.init();

features.add(new FeatureEBInService()); //HWYLA plugins from /plugins
features.add(new FeatureEBInputs());
features.add(new FeatureEBOutputs());
}

public static List<Feature> getFeatures() {
return features;
} //HWYLA

private void setup(final FMLCommonSetupEvent event)
{
LOGGER.info("HELLO FROM PREINIT");
Expand All @@ -74,7 +94,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
try {
keepAliveSuccessful = SimulationHandler.instance().sendKeepAlive();
} catch (Exception e) {
keepAliveSuccessful = true; // Set this to prevent double message from appearing
keepAliveSuccessful = true; // Set this to prevent double message from appearing //doesn't work??
LOGGER.fatal("Unable to contact simulation server! ElectricBlocksMod will be unable to function.");
LOGGER.fatal("Ensure that EBPP is online and accessible. Also validate your configuration file.");
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/edu/uidaho/electricblocks/RegistryHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package edu.uidaho.electricblocks;

import edu.uidaho.electricblocks.blocks.*;
import edu.uidaho.electricblocks.containers.ElecFurnaceContainer;
import edu.uidaho.electricblocks.items.*;
import edu.uidaho.electricblocks.tileentities.*;

import net.minecraft.block.Block;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item;
import net.minecraft.tileentity.AbstractFurnaceTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistryEntry;

import static edu.uidaho.electricblocks.init.RecipeSerializerInit.RECIPE_SERIALIZERS;

/**
* This is a static class that cannot be instantiated and is just used to register all of the blocks, items and tile
Expand All @@ -23,29 +31,41 @@ private RegistryHandler() {} // Class cannot be instantiated
public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, ElectricBlocksMod.MOD_ID);
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, ElectricBlocksMod.MOD_ID);
public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, ElectricBlocksMod.MOD_ID);
public static final DeferredRegister<ContainerType<?>> CONTAINER_TYPES = new DeferredRegister<>(
ForgeRegistries.CONTAINERS, ElectricBlocksMod.MOD_ID);



// Blocks
public static final RegistryObject<Block> LAMP_BLOCK = BLOCKS.register("lamp_block", LampBlock::new);
public static final RegistryObject<Block> BATTERY_BLOCK = BLOCKS.register("battery_block", BatteryBlock::new);
public static final RegistryObject<Block> EXTERNAL_GRID_BLOCK = BLOCKS.register("externalgrid_block", ExternalGridBlock::new);
public static final RegistryObject<Block> WIRE_BLOCK = BLOCKS.register("wire_block", WireBlock::new);
public static final RegistryObject<Block> BUS_BLOCK = BLOCKS.register("bus_block", BusBlock::new);
public static final RegistryObject<Block> GENERATOR_BLOCK = BLOCKS.register("generator_block", GeneratorBlock::new);
public static final RegistryObject<Block> LOAD_BLOCK = BLOCKS.register("load_block", LoadBlock::new);
public static final RegistryObject<Block> TRANSFORMER_BLOCK = BLOCKS.register("transformer_block", TransformerBlock::new);
public static final RegistryObject<Block> ELEC_FURNACE_BLOCK = BLOCKS.register("elec_furnace_block", ElecFurnaceBlock::new);

// Items
public static final RegistryObject<Item> LAMP_ITEM = ITEMS.register("lamp_item", LampItem::new);
public static final RegistryObject<Item> BATTERY_ITEM = ITEMS.register("battery_item", BatteryItem::new);
public static final RegistryObject<Item> MULTIMETER_ITEM = ITEMS.register("multimeter_item", MultimeterItem::new);
public static final RegistryObject<Item> MULTIMETER_ITEM2 = ITEMS.register("multimeter_item2", MultimeterItem2::new);
public static final RegistryObject<Item> MULTIMETER_ITEM3 = ITEMS.register("multimeter_item3", MultimeterItem3::new);
public static final RegistryObject<Item> EXTERNAL_GRID_ITEM = ITEMS.register("externalgrid_item", ExternalGridItem::new);
public static final RegistryObject<Item> WIRE_ITEM = ITEMS.register("wire_item", WireItem::new);
public static final RegistryObject<Item> BUS_ITEM = ITEMS.register("bus_item", BusItem::new);
public static final RegistryObject<Item> GENERATOR_ITEM = ITEMS.register("generator_item", GeneratorItem::new);
public static final RegistryObject<Item> LOAD_ITEM = ITEMS.register("load_item", LoadItem::new);
public static final RegistryObject<Item> TRANSFORMER_ITEM = ITEMS.register("transformer_item", TransformerItem::new);
public static final RegistryObject<Item> ELEC_FURNACE_ITEM = ITEMS.register("elec_furnace_item", ElecFurnaceItem::new);

// Tile Entities
public static final RegistryObject<TileEntityType<LampTileEntity>> LAMP_TILE_ENTITY =
TILE_ENTITIES.register("lamp_tileentity", () -> TileEntityType.Builder.create(LampTileEntity::new).build(null));
public static final RegistryObject<TileEntityType<BatteryTileEntity>> BATTERY_TILE_ENTITY =
TILE_ENTITIES.register("battery_tileentity", () -> TileEntityType.Builder.create(BatteryTileEntity::new).build(null));
public static final RegistryObject<TileEntityType<ExternalGridTileEntity>> EXTERNAL_GRID_TILE_ENTITY =
TILE_ENTITIES.register("externalgrid_tileentity", () -> TileEntityType.Builder.create(ExternalGridTileEntity::new).build(null));
public static final RegistryObject<TileEntityType<BusTileEntity>> BUS_TILE_ENTITY =
Expand All @@ -56,6 +76,12 @@ private RegistryHandler() {} // Class cannot be instantiated
TILE_ENTITIES.register("load_tileentity", () -> TileEntityType.Builder.create(LoadTileEntity::new).build(null));
public static final RegistryObject<TileEntityType<TransformerTileEntity>> TRANSFORMER_TILE_ENTITY =
TILE_ENTITIES.register("transformer_tileentity", () -> TileEntityType.Builder.create(TransformerTileEntity::new).build(null));
public static final RegistryObject<TileEntityType<ElecFurnaceTileEntity>> ELEC_FURNACE_TILE_ENTITY =
TILE_ENTITIES.register("elec_furnace_tileentity", () -> TileEntityType.Builder.create(ElecFurnaceTileEntity::new).build(null));

//Containers
public static final RegistryObject<ContainerType<ElecFurnaceContainer>> ELEC_FURNACE_CONTAINER = CONTAINER_TYPES
.register("electric_furnace", () -> IForgeContainerType.create(ElecFurnaceContainer::new));

/**
* Initializes all of the registers with the event mod bus so that blocks, items, and tile entities will be
Expand All @@ -65,6 +91,8 @@ public static void init() {
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
TILE_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
CONTAINER_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
RECIPE_SERIALIZERS.register(FMLJavaModLoadingContext.get().getModEventBus());
}

}
34 changes: 34 additions & 0 deletions src/main/java/edu/uidaho/electricblocks/blocks/BatteryBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.uidaho.electricblocks.blocks;

import edu.uidaho.electricblocks.tileentities.BatteryTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader;

import javax.annotation.Nullable;

public class BatteryBlock extends Block {

public BatteryBlock() {
super(Properties.create(Material.EARTH)
.hardnessAndResistance(0f)
.sound(SoundType.WOOD)
.slipperiness(0.6f)
.harvestLevel(2)
);
}

@Override
public boolean hasTileEntity(BlockState state) {
return true;
}

@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BatteryTileEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BusBlock extends Block {
public BusBlock() {
super(Properties.create(Material.EARTH)
.hardnessAndResistance(0f)
.sound(SoundType.ANVIL)
.sound(SoundType.STONE)
.slipperiness(0.6f)
.harvestLevel(2)
);
Expand Down
Loading

0 comments on commit 5335e6c

Please sign in to comment.