Fixed IMC, Keybinds, other bugs

This commit is contained in:
Tschipp 2023-07-06 17:06:47 +02:00
parent 9ed3268e30
commit 1ca409c43d
8 changed files with 94 additions and 7 deletions

View File

@ -14,7 +14,11 @@ public class CarryOnKeybinds
public static void registerKeybinds(Consumer<KeyMapping> registrar)
{
carryKey = new ConflictFreeKeyMapping("key.carry.desc", Services.PLATFORM.getPlatformName().equals("Forge") ? InputConstants.KEY_LSHIFT : InputConstants.UNKNOWN.getValue(), "key.carry.category");
if(Services.PLATFORM.isModLoaded("amecsapi"))
carryKey = new ConflictFreeKeyMapping("key.carry.desc", InputConstants.KEY_LSHIFT, "key.carry.category");
else
carryKey = new ConflictFreeKeyMapping("key.carry.desc", Services.PLATFORM.getPlatformName().equals("Forge") ? InputConstants.KEY_LSHIFT : InputConstants.UNKNOWN.getValue(), "key.carry.category");
registrar.accept(carryKey);
}

View File

@ -29,7 +29,6 @@ public class ListHandler {
private static List<TagKey<EntityType<?>>> FORBIDDEN_STACKING_TAGS = new ArrayList<>();
private static List<TagKey<EntityType<?>>> ALLOWED_STACKING_TAGS = new ArrayList<>();
private static Set<Class<?>> PROPERTY_EXCEPTION_CLASSES = new HashSet<>();
public static boolean isPermitted(Block block)
@ -140,7 +139,6 @@ public class ListHandler {
}
}
}
}
private static <T> void addTag(String tag, Map<ResourceLocation, TagKey<T>> tagMap, List<TagKey<T>> tags) {

View File

@ -16,16 +16,25 @@ if (System.getenv('BUILD_NUMBER') != null) {
}
repositories {
maven { url 'https://jitpack.io' }
maven {
url "https://maven.siphalor.de/"
name "Siphalor's Maven"
}
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.officialMojangMappings()
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchment_mappings_fabric}@zip")
}
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
implementation project(":Common")
modImplementation "de.siphalor:amecsapi-1.19:1.3.9+mc1.19.4"
include "de.siphalor:amecsapi-1.19:1.3.9+mc1.19.4"
include implementation("com.github.llamalad7.mixinextras:mixinextras-fabric:${mixinextras_version}")
annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${mixinextras_version}")
}

View File

@ -0,0 +1,66 @@
package tschipp.carryon.compat;
import net.fabricmc.fabric.api.event.Event;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import tschipp.carryon.Constants;
import tschipp.carryon.platform.Services;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ArchitecturyCompat {
private static Object INVOKER_INSTANCE;
private static Method PLACE_BLOCK;
private static Method IS_FALSE;
private static void setup( ) {
try {
Class BlockEvent = Class.forName("dev.architectury.event.events.common.BlockEvent");
Field PLACE = BlockEvent.getField("PLACE");
Method invoker = Class.forName("dev.architectury.event.Event").getMethod("invoker");
INVOKER_INSTANCE = invoker.invoke(PLACE.get(BlockEvent));
Class PlaceClass = Class.forName("dev.architectury.event.events.common.BlockEvent$Place");
PLACE_BLOCK = PlaceClass.getMethod("placeBlock", Level.class, BlockPos.class, BlockState.class, Entity.class);
Class EventResult = Class.forName("dev.architectury.event.EventResult");
IS_FALSE = EventResult.getMethod("isFalse");
} catch (Exception e) {
Constants.LOG.warn("Error while initializing Architectury Compat: " + e);
}
}
public static boolean active() {
return Services.PLATFORM.isModLoaded("architectury");
}
public static boolean sendPlaceEvent(Level level, BlockPos pos, BlockState state, Player player) {
if(!active())
return true;
if(INVOKER_INSTANCE == null || PLACE_BLOCK == null)
setup();
if(INVOKER_INSTANCE != null && PLACE_BLOCK != null && IS_FALSE != null) {
try {
Object eventResult = PLACE_BLOCK.invoke(INVOKER_INSTANCE, level, pos, state, player);
boolean canceled = (boolean) IS_FALSE.invoke(eventResult);
return !canceled;
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return true;
}
}

View File

@ -19,6 +19,7 @@ import tschipp.carryon.common.carry.CarryOnDataManager;
import tschipp.carryon.common.carry.PickupHandler;
import tschipp.carryon.common.carry.PlacementHandler;
import tschipp.carryon.common.scripting.ScriptReloadListener;
import tschipp.carryon.compat.ArchitecturyCompat;
import tschipp.carryon.config.ConfigLoader;
import tschipp.carryon.scripting.IdentifiableScriptReloadListener;
@ -42,7 +43,10 @@ public class CommonEvents {
CarryOnData carry = CarryOnDataManager.getCarryData(player);
if(!carry.isCarrying())
{
if (PickupHandler.tryPickUpBlock((ServerPlayer) player, pos, world, null))
if (PickupHandler.tryPickUpBlock((ServerPlayer) player, pos, world, (pState, pPos) -> {
boolean success = PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(world, player, pPos, pState, world.getBlockEntity(pPos));
return success;
}))
return InteractionResult.SUCCESS;
return InteractionResult.PASS;
}
@ -50,7 +54,9 @@ public class CommonEvents {
{
if(carry.isCarrying(CarryOnData.CarryType.BLOCK))
{
if(PlacementHandler.tryPlaceBlock((ServerPlayer) player, pos, facing, null))
if(PlacementHandler.tryPlaceBlock((ServerPlayer) player, pos, facing, (pState, pPos) -> {
return ArchitecturyCompat.sendPlaceEvent(world, pState, pPos, player);
}))
return InteractionResult.SUCCESS;
}
else

View File

@ -1,6 +1,7 @@
package tschipp.carryon;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

View File

@ -6,6 +6,7 @@ import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.InterModComms.IMCMessage;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import tschipp.carryon.Constants;
import tschipp.carryon.client.modeloverride.ModelOverrideHandler;
import tschipp.carryon.common.config.ListHandler;
@ -16,7 +17,7 @@ import java.util.stream.Stream;
public class ModBusEvents {
@SubscribeEvent(priority = EventPriority.LOW)
public static void serverLoad(FMLCommonSetupEvent event)
public static void serverLoad(InterModProcessEvent event)
{
Stream<IMCMessage> messages = InterModComms.getMessages(Constants.MOD_ID);
@ -28,6 +29,7 @@ public class ModBusEvents {
if (!(obj instanceof String str))
return;
switch (method) {
case "blacklistBlock":
ListHandler.addForbiddenTiles(str);

View File

@ -14,6 +14,7 @@ parchment_mappings=2022.11.20-1.19.2
//forge_ats_enabled=true
# Fabric
parchment_mappings_fabric=1.19.2:2022.11.27
fabric_version=0.62.0+1.19.2
fabric_loader_version=0.14.9