Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Closed
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
10 changes: 10 additions & 0 deletions patchwork-event-dispatcher/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
archivesBaseName = "patchwork-event-dispatcher"
version = getSubprojectVersion(project, "0.1.0")

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-events-world', configuration: 'dev')
compile project(path: ':patchwork-fml', configuration: 'dev')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.client;

import java.util.Set;

import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.util.Identifier;

import net.patchworkmc.impl.event.render.RenderEvents;

public class ForgeHooksClient {
public static void onBlockColorsInit(BlockColors blockColors) {
RenderEvents.onBlockColorsInit(blockColors);
}

public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) {
RenderEvents.onItemColorsInit(itemColors, blockColors);
}

public static void onTextureStitchedPre(SpriteAtlasTexture map, Set<Identifier> resourceLocations) {
RenderEvents.onTextureStitchPre(map, resourceLocations);
}

public static void onTextureStitchedPost(SpriteAtlasTexture map) {
RenderEvents.onTextureStitchPost(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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.common;

import java.util.List;

import javax.annotation.Nullable;

import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Event.Result;

import net.minecraft.entity.EntityCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.level.LevelInfo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;

import net.patchworkmc.impl.event.entity.EntityEvents;
import net.patchworkmc.impl.event.world.WorldEvents;

public class ForgeHooks {
public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason);
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
}

// TODO: onInteractEntityAt

public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) {
return EntityEvents.onInteractEntity(player, entity, hand);
}

public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
return EntityEvents.onLivingDeath(entity, src);
}

public static boolean onLivingUpdate(LivingEntity entity) {
return EntityEvents.onLivingUpdateEvent(entity);
}

// TODO: forge calls the equivilant to this in LivingEntity, but patchwork only calls the equivilant to onPlayerAttack
public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) {
return entity instanceof PlayerEntity || onPlayerAttack(entity, src, amount);
}

public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) {
return !EntityEvents.onLivingAttack(entity, src, amount);
}

// optifine wants this? O.o
public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) {
EntityEvents.onLivingSetAttackTarget(entity, target);
}

public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount) {
return EntityEvents.onLivingHurt(entity, src, amount);
}

@Nullable
public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) {
return EntityEvents.onLivingFall(entity, distance, damageMultiplier);
}

public static float onLivingDamage(LivingEntity entity, DamageSource src, float amount) {
return EntityEvents.onLivingDamage(entity, src, amount);
}

public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) {
return EntityEvents.attackEntity(player, target);
}

public static boolean onCreateWorldSpawn(World world, LevelInfo settings) {
return WorldEvents.onCreateWorldSpawn(world, settings);
}

@Nullable
public static List<Biome.SpawnEntry> getPotentialSpawns(IWorld world, EntityCategory type, BlockPos pos, List<Biome.SpawnEntry> oldList) {
return WorldEvents.getPotentialSpawns(world, type, pos, oldList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.Result;

import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.IWorld;
import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;

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

public class ForgeEventFactory {
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) {
return EntityEvents.canEntitySpawn(entity, world, x, y, z, spawner, spawnReason);
}

public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner) {
return EntityEvents.canEntitySpawnFromSpawner(entity, world, x, y, z, spawner);
}

public static void onPlayerFall(PlayerEntity player, float distance, float multiplier) {
EntityEvents.onFlyablePlayerFall(player, distance, multiplier);
}

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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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.hooks;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

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

public class BasicEventHooks {
// public static void firePlayerChangedDimensionEvent(PlayerEntity player, DimensionType fromDim, DimensionType toDim) {
//
// }

public static void firePlayerLoggedIn(PlayerEntity player) {
EntityEvents.onPlayerLoggedIn(player);
}

// public static void firePlayerLoggedOut(PlayerEntity player) {
//
// }

// public static void firePlayerRespawnEvent(PlayerEntity player, boolean endConquered) {
//
// }

// public static void firePlayerItemPickupEvent(PlayerEntity player, ItemEntity item, ItemStack clone) {
//
// }

// public static void firePlayerCraftingEvent(PlayerEntity player, ItemStack crafted, Inventory craftMatrix) {
//
// }

// public static void firePlayerSmeltedEvent(PlayerEntity player, ItemStack smelted) {
//
// }

// public static void onRenderTickStart(float timer) {
//
// }

// public static void onRenderTickEnd(float timer) {
//
// }

public static void onPlayerPreTick(PlayerEntity player) {
LifecycleEvents.onPlayerPreTick(player);
}

public static void onPlayerPostTick(PlayerEntity player) {
LifecycleEvents.onPlayerPostTick(player);
}

public static void onPreWorldTick(World world) {
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, world);
}

public static void onPostWorldTick(World world) {
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.END, world);
}

// TODO: unlike almost everything else in this class, this doesn't delegate to a module specific method implementation.
public static void onPreClientTick() {
MinecraftForge.EVENT_BUS.post(new TickEvent.ClientTickEvent(TickEvent.Phase.START));
}

// TODO: unlike almost everything else in this class, this doesn't delegate to a module specific method implementation.
public static void onPostClientTick() {
MinecraftForge.EVENT_BUS.post(new TickEvent.ClientTickEvent(TickEvent.Phase.END));
}

// public static void onPreServerTick() {
//
// }

// public static void onPostServerTick() {
//
// }
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions patchwork-event-dispatcher/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"schemaVersion": 1,
"id": "patchwork-event-dispatcher",
"name": "Patchwork Event Dispatcher",
"version": "${version}",
"description": "Implements ForgeHooks, ForgeEventFactory, and more.",
"environment": "*",
"license": "LGPL-2.1-only",
"icon": "assets/patchwork-event-dispatcher/icon.png",
"contact": {
"issues": "https://github.com/PatchworkMC/patchwork-api/issues",
"sources": "https://github.com/PatchworkMC/patchwork-api"
},
"authors": [
"PatchworkMC"
],
"depends": {
"fabricloader": ">=0.8.4",
"patchwork-fml": "*",
"patchwork-events-entity": "*",
"patchwork-events-lifecycle": "*"
},
"custom": {
"modmenu:api": true,
"modmenu:parent": "patchwork"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.IWorld;
Expand Down Expand Up @@ -92,7 +91,7 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ,
}

// PlayerEvents
public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) {
public static void onPlayerLoggedIn(PlayerEntity playerEntity) {
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import net.minecraft.server.MinecraftServer;

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

/**
* This is a stub of the ServerLifecycleHooks class in Forge for mods that use getCurrentServer.
*/
Expand All @@ -30,4 +32,18 @@ public class ServerLifecycleHooks {
public static MinecraftServer getCurrentServer() {
return currentServer;
}

public static boolean handleServerAboutToStart(final MinecraftServer server) {
LifecycleEvents.handleServerAboutToStart(server);
return true; // patchwork does not allow you to cancel server startup.
}

public static boolean handleServerStarting(final MinecraftServer server) {
LifecycleEvents.handleServerStarting(server);
return true; // patchwork does not allow you to cancel server startup.
}

public static void handleServerStarted(final MinecraftServer server) {
LifecycleEvents.handleServerStarted(server);
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include 'patchwork-capabilities'
include 'patchwork-data-generators'
include 'patchwork-dispatcher'
include 'patchwork-enum-hacks'
include 'patchwork-event-dispatcher'
include 'patchwork-events-entity'
include 'patchwork-events-input'
include 'patchwork-events-lifecycle'
Expand Down