Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
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
@@ -0,0 +1,35 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.fml.event.server;

import net.minecraft.server.MinecraftServer;

/**
* Called after {@link FMLServerStoppingEvent} when the server has completely shut down.
* Called immediately before shutting down, on the dedicated server, and before returning
* to the main menu on the client.
*
* @author cpw
*/
public class FMLServerStoppedEvent extends ServerLifecycleEvent {
public FMLServerStoppedEvent(MinecraftServer server) {
super(server);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package net.minecraftforge.fml.server;

import java.util.concurrent.CountDownLatch;

import net.minecraft.server.MinecraftServer;

import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
Expand All @@ -28,6 +30,7 @@
*/
public class ServerLifecycleHooks {
public static MinecraftServer currentServer;
public static volatile CountDownLatch exitLatch = null;

public static MinecraftServer getCurrentServer() {
return currentServer;
Expand All @@ -48,4 +51,8 @@ public static boolean handleServerStarting(final MinecraftServer server) {
public static void handleServerStarted(final MinecraftServer server) {
LifecycleEvents.handleServerStarted(server);
}

public static void handleServerStopped(final MinecraftServer server) {
LifecycleEvents.handleServerStopped(server);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package net.patchworkmc.impl.event.lifecycle;

import java.nio.file.Path;
import java.util.concurrent.CountDownLatch;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
Expand All @@ -30,6 +31,7 @@
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
import net.minecraftforge.fml.loading.FileUtils;
import net.minecraftforge.fml.server.ServerLifecycleHooks;

Expand Down Expand Up @@ -93,6 +95,18 @@ public static void handleLoadComplete() {
loadCompleteCallback.run();
}

public static void handleServerStopped(final MinecraftServer server) {
MinecraftForge.EVENT_BUS.post(new FMLServerStoppedEvent(server));
ServerLifecycleHooks.currentServer = null;
LogicalSidedProvider.setServer(null);
CountDownLatch latch = ServerLifecycleHooks.exitLatch;

if (latch != null) {
latch.countDown();
ServerLifecycleHooks.exitLatch = null;
}
}

@Override
public void onInitialize() {
WorldTickCallback.EVENT.register(world -> fireWorldTickEvent(TickEvent.Phase.END, world));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.event.lifecycle;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.server.MinecraftServer;

import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;

@Mixin(MinecraftServer.class)
public class MixinMinecraftServer {
@Inject(method = "run", at = @At(value = "INVOKE", target = "net/minecraft/server/MinecraftServer.exit ()V"))
private void serverStoppedHook(CallbackInfo ci) {
LifecycleEvents.handleServerStopped((MinecraftServer) (Object) this);
}
}
1 change: 1 addition & 0 deletions patchwork-god-classes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies {
compile project(path: ':patchwork-events-entity', configuration: 'dev')
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
compile project(path: ':patchwork-events-rendering', configuration: 'dev')
compile project(path: ':patchwork-loot', configuration: 'dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import javax.annotation.Nullable;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Event;

Expand All @@ -33,12 +35,16 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;

import net.patchworkmc.impl.event.entity.EntityEvents;
import net.patchworkmc.impl.loot.LootHooks;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
Expand Down Expand Up @@ -98,4 +104,13 @@ public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Co
public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) {
return EntityEvents.attackEntity(player, target);
}

@Nullable
public static LootTable loadLootTable(Gson gson, Identifier name, JsonObject data, boolean custom, LootManager lootTableManager) {
return LootHooks.loadLootTable(gson, name, data, custom, lootTableManager);
}

public static String readPoolName(JsonObject json) {
return LootHooks.readPoolName(json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
import net.minecraft.util.Identifier;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;

import net.patchworkmc.impl.capability.CapabilityEvents;
import net.patchworkmc.impl.event.entity.EntityEvents;
import net.patchworkmc.impl.event.loot.LootEvents;

/*
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
Expand Down Expand Up @@ -65,4 +69,8 @@ public static void onPlayerFall(PlayerEntity player, float distance, float multi
public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner, SpawnType spawnReason) {
return EntityEvents.doSpecialSpawn(entity, world, x, y, z, spawner, spawnReason);
}

public static LootTable loadLootTable(Identifier name, LootTable table, LootManager lootTableManager) {
return LootEvents.loadLootTable(name, table, lootTableManager);
}
}
3 changes: 2 additions & 1 deletion patchwork-god-classes/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"patchwork-fml": "*",
"patchwork-capabilities": "*",
"patchwork-events-lifecycle": "*",
"patchwork-events-rendering": "*"
"patchwork-events-rendering": "*",
"patchwork-loot": "*"
},
"custom": {
"modmenu:api": true,
Expand Down
5 changes: 5 additions & 0 deletions patchwork-loot/build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
archivesBaseName = "patchwork-loot"
version = getSubprojectVersion(project, "0.2.0")

dependencies {
compile project(path: ':patchwork-fml', configuration: 'dev')
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.event;

import net.minecraftforge.eventbus.api.Event;

import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
import net.minecraft.util.Identifier;

/**
* Event fired when a LootTable json is loaded from json.
* This event is fired whenever resources are loaded, or when the server starts.
* This event will NOT be fired for LootTables loaded from the world folder, these are
* considered configurations files and should not be modified by mods.
*
* <p>Canceling the event will make it load a empty loot table.</p>
*/
public class LootTableLoadEvent extends Event {
private final Identifier name;
private LootTable table;
private LootManager lootTableManager;

public LootTableLoadEvent(Identifier name, LootTable table, LootManager lootTableManager) {
this.name = name;
this.table = table;
this.lootTableManager = lootTableManager;
}

public Identifier getName() {
return this.name;
}

public LootTable getTable() {
return this.table;
}

public void setTable(LootTable table) {
this.table = table;
}

public LootManager getLootTableManager() {
return this.lootTableManager;
}

@Override
public boolean isCancelable() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.api.loot;

import net.minecraft.loot.LootPool;
import net.minecraft.loot.LootTableRange;
import net.minecraft.loot.UniformLootTableRange;

/**
* Interface for adding Forge methods added to LootPool and its inner classes.
*/
public interface ForgeLootPool {
// TODO: doesn't include methods having to do with freezing yet

String getName();
LootTableRange getRolls();
LootTableRange getBonusRolls();
void setRolls(UniformLootTableRange v);
void setBonusRolls(UniformLootTableRange v);

public interface Builder {
LootPool.Builder name(String name);
LootPool.Builder bonusRolls(float min, float max);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.api.loot;

import net.minecraft.loot.LootPool;

/**
* Interface for adding Forge methods added to LootTable.
*/
public interface ForgeLootTable {
// TODO: doesn't include methods having to do with freezing yet

LootPool getPool(String name);
LootPool removePool(String name);
void addPool(LootPool pool);
}
Loading