Skip to content

Commit

Permalink
Begin 1.1.0: Gradle 7, Sponge API 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Jan 28, 2022
1 parent f4bc10e commit 3e618f6
Show file tree
Hide file tree
Showing 21 changed files with 414 additions and 281 deletions.
99 changes: 37 additions & 62 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,22 @@
* SOFTWARE.
*/

buildscript {
repositories {
maven {
name = 'forge'
url = 'https://maven.minecraftforge.net'
}
maven {
name = 'sponge'
url = 'https://repo.spongepowered.org/repository/maven-public/'
}
}

dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
}
}

plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'java-library'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'org.spongepowered.gradle.vanilla' version '0.2'
}

apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'org.spongepowered.mixin'
group 'net.smoofyuniverse'

sourceCompatibility = 1.8
targetCompatibility = 1.8

minecraft {
version = '1.12.2-14.23.5.2838'
mappings = 'snapshot_20180808'

runDir = 'run'
makeObfSourceJar = false
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

sourceSets {
main {
ext.refMap = 'mixins.superpiston.refmap.json'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "utf-8"
}

repositories {
Expand All @@ -71,31 +46,37 @@ repositories {
}
}

configurations {
spongevanilla
}

dependencies {
compile 'org.spongepowered:spongecommon:1.12.2-7.3.0:dev'
compile 'net.smoofyuniverse:oreupdater:1.0.1'
compile 'net.smoofyuniverse:worldmap:1.0.0'
implementation 'org.spongepowered:sponge:1.16.5-8.0.0-SNAPSHOT:dev'
implementation 'org.spongepowered:timings:1.0-SNAPSHOT'
implementation 'org.spongepowered:mixin:0.8.4'
implementation 'org.ow2.asm:asm-util:9.2'

implementation 'net.smoofyuniverse:oreupdater:1.1.1'
implementation 'net.smoofyuniverse:worldmap:1.1.0'

spongevanilla 'org.spongepowered:spongevanilla:1.16.5-8.0.0-RC1052:universal'
}

minecraft {
version("1.16.5")
}

jar {
classifier 'base'
manifest {
attributes(
'FMLCorePluginContainsFMLMod': 'true',
'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker',
'MixinConfigs': 'mixins.superpiston.json',
'FMLAT': 'superpiston_at.cfg',
'ForceLoadAsMod' : true
'MixinConfigs': 'mixins.superpiston.json'
)
}
}

reobf.jar.mappingType = 'SEARGE'

shadowJar {
classifier ''
mainSpec.sourcePaths.clear()
dependsOn reobfJar

dependencies {
include dependency('net.smoofyuniverse:oreapi')
Expand All @@ -104,22 +85,16 @@ shadowJar {
}

relocate 'net.smoofyuniverse.ore', 'net.smoofyuniverse.superpiston.ore'
relocate 'net.smoofyuniverse.map', 'net.smoofyuniverse.autopickup.map'

exclude "dummyThing"
afterEvaluate {
from zipTree(reobfJar.jar)
}
relocate 'net.smoofyuniverse.map', 'net.smoofyuniverse.superpiston.map'
}

task updatePlugin <<{
copy {
from 'build/libs/SuperPiston.jar'
into 'run/forge/mods'
}
copy {
from 'build/libs/SuperPiston.jar'
into 'run/vanilla/mods'
task setupVanillaServer(type: Copy) {
into 'run/vanilla'

from configurations.spongevanilla
rename('spongevanilla-(.*).jar', 'spongevanilla.jar')

into('mods') {
from shadowJar
}
}
updatePlugin.dependsOn shadowJar
78 changes: 41 additions & 37 deletions src/main/java/net/smoofyuniverse/superpiston/SuperPiston.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,32 @@
import net.smoofyuniverse.map.WorldMapLoader;
import net.smoofyuniverse.ore.update.UpdateChecker;
import net.smoofyuniverse.superpiston.config.world.WorldConfig;
import net.smoofyuniverse.superpiston.config.world.WorldConfig.Immutable;
import net.smoofyuniverse.superpiston.config.world.WorldConfig.Resolved;
import net.smoofyuniverse.superpiston.event.PistonListener;
import net.smoofyuniverse.superpiston.impl.internal.InternalServer;
import net.smoofyuniverse.superpiston.util.IOUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Server;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.GameReloadEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.world.World;
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
import org.spongepowered.api.event.lifecycle.RefreshGameEvent;
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.configurate.loader.ConfigurationLoader;
import org.spongepowered.plugin.PluginContainer;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

@Plugin(id = "superpiston", name = "SuperPiston", version = "1.0.7", authors = "Yeregorix", description = "Allows to modify vanilla pistons")
public class SuperPiston {
public static final Logger LOGGER = LoggerFactory.getLogger("SuperPiston");
public static final Logger LOGGER = LogManager.getLogger("SuperPiston");
private static SuperPiston instance;

@Inject
Expand All @@ -61,8 +63,10 @@ public class SuperPiston {
@Inject
private PluginContainer container;

private WorldMapLoader<Immutable> configMapLoader;
private WorldMap<Immutable> configMap;
private ConfigurationOptions configOptions;

private WorldMapLoader<Resolved> configMapLoader;
private WorldMap<Resolved> configMap;

public SuperPiston() {
if (instance != null)
Expand All @@ -71,57 +75,57 @@ public SuperPiston() {
}

@Listener
public void onGamePreInit(GamePreInitializationEvent e) {
public void onConstructPlugin(ConstructPluginEvent e) {
this.configOptions = ConfigurationOptions.defaults().serializers(this.game.configManager().serializers());

try {
Files.createDirectories(this.configDir);
} catch (IOException ignored) {
}

this.configMapLoader = new WorldMapLoader<WorldConfig.Immutable>(LOGGER,
IOUtil.createConfigLoader(this.configDir.resolve("map.conf")),
this.configMapLoader = new WorldMapLoader<Resolved>(LOGGER,
createConfigLoader(this.configDir.resolve("map.conf")),
this.configDir.resolve("configs"), WorldConfig.VANILLA) {
@Override
protected WorldConfig.Immutable loadConfig(Path file) throws Exception {
return WorldConfig.load(file).toImmutable();
protected Resolved loadConfig(Path file) throws Exception {
return WorldConfig.load(file).resolve();
}
};
}

public ConfigurationLoader<CommentedConfigurationNode> createConfigLoader(Path file) {
return HoconConfigurationLoader.builder().defaultOptions(this.configOptions).path(file).build();
}

@Listener
public void onGameInit(GameInitializationEvent e) {
public void onServerStarting(StartingEngineEvent<Server> e) {
loadConfigs();

this.game.getEventManager().registerListeners(this, new PistonListener(this));
this.game.eventManager().registerListeners(this.container, new PistonListener(this));

this.game.getEventManager().registerListeners(this, new UpdateChecker(LOGGER, this.container,
IOUtil.createConfigLoader(this.configDir.resolve("update.conf")), "Yeregorix", "SuperPiston"));
this.game.eventManager().registerListeners(this.container, new UpdateChecker(LOGGER, this.container,
createConfigLoader(this.configDir.resolve("update.conf")), "Yeregorix", "SuperPiston"));
}

private void loadConfigs() {
if (Files.exists(this.configDir.resolve("worlds")) && Files.notExists(this.configDir.resolve("map.conf"))) {
LOGGER.info("Updating config directory structure ...");
Path worlds = IOUtil.backup(this.configDir).orElse(this.configDir).resolve("worlds");
this.configMap = this.configMapLoader.importWorlds(worlds);
} else {
this.configMap = this.configMapLoader.load();
}
this.configMap = this.configMapLoader.load();
}

@Listener
public void onGameReload(GameReloadEvent e) {
public void onRefreshGame(RefreshGameEvent e) {
loadConfigs();
}

@Listener
public void onServerStarted(GameStartedServerEvent e) {
if (this.game.getServer() instanceof InternalServer)
LOGGER.info("SuperPiston " + this.container.getVersion().orElse("?") + " was loaded successfully.");
public void onServerStarted(StartedEngineEvent<Server> e) {
if (e.engine() instanceof InternalServer)
LOGGER.info("SuperPiston " + this.container.metadata().version() + " was loaded successfully.");
else
LOGGER.error("!!WARNING!! SuperPiston was not loaded correctly. Be sure that the jar file is at the root of your mods folder!");
}

public WorldConfig.Immutable getConfig(World world) {
return this.configMap.get(world.getProperties());
public Resolved getConfig(ServerWorld world) {
return this.configMap.get(world.properties());
}

public PluginContainer getContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
import co.aikar.timings.Timings;

public class SuperPistonTimings {
public static final Timing CALCULATION = Timings.of(SuperPiston.get(), "Calculation");
public static final Timing CALCULATION = Timings.of(SuperPiston.get().getContainer(), "Calculation");
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,46 @@
import net.smoofyuniverse.superpiston.api.structure.calculator.PistonStructureCalculator;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.world.TargetWorldEvent;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.world.server.ServerWorld;

/**
* Base event for when a piston determines a {@link PistonStructure}.
*/
public interface PistonStructureCalculationEvent extends TargetWorldEvent, Cancellable {
public interface PistonStructureCalculationEvent extends Event, Cancellable {

/**
* Gets the world.
*
* @return The world.
*/
ServerWorld world();

/**
* Gets the block representing the piston.
* In a modded environment this block might not even be a real piston.
* Do not use this block to determine the direction of the piston.
* Use {@link PistonStructureCalculationEvent#getPistonDirection()} instead.
* Use {@link PistonStructureCalculationEvent#pistonDirection()} instead.
*
* @return The block representing the piston.
*/
BlockSnapshot getPiston();
BlockSnapshot piston();

/**
* @return The direction of the piston.
*/
Direction getPistonDirection();
Direction pistonDirection();

/**
* Gets the direction of the movement.
* If it matches {@link PistonStructureCalculationEvent#getPistonDirection()} then the piston is extending.
* If it matches {@link PistonStructureCalculationEvent#pistonDirection()} then the piston is extending.
* If it matches the opposite then the piston is retracting.
* If it matches something else then a mod is doing weird stuff.
*
* @return The direction of the movement.
*/
Direction getPistonMovement();
Direction pistonMovement();

/**
* Called before the {@link PistonStructure} is calculated.
Expand All @@ -68,12 +76,12 @@ public interface Pre extends PistonStructureCalculationEvent {
/**
* @return The original calculator.
*/
PistonStructureCalculator getOriginalCalculator();
PistonStructureCalculator originalCalculator();

/**
* @return The calculator that will be used.
*/
PistonStructureCalculator getCalculator();
PistonStructureCalculator calculator();

/**
* Sets the calculator the will be used.
Expand All @@ -91,11 +99,11 @@ public interface Post extends PistonStructureCalculationEvent {
/**
* @return The calculator that has been used.
*/
PistonStructureCalculator getCalculator();
PistonStructureCalculator calculator();

/**
* @return The calculated structure.
*/
PistonStructure getStructure();
PistonStructure structure();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

package net.smoofyuniverse.superpiston.api.structure;

import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.ImmutableList;
import org.spongepowered.math.vector.Vector3i;

import java.util.Collection;
import java.util.List;
Expand Down
Loading

0 comments on commit 3e618f6

Please sign in to comment.