Skip to content
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
Expand Up @@ -18,8 +18,6 @@

package com.craftingdead.core;

import java.util.Optional;

import com.craftingdead.core.data.tags.ModBlockTagsProvider;
import org.apache.commons.lang3.mutable.MutableInt;
import org.slf4j.Logger;
Expand Down Expand Up @@ -59,7 +57,6 @@
import com.craftingdead.core.trauma.ProtectionConfig;
import com.craftingdead.core.event.LivingExtensionEvent;
import com.craftingdead.core.world.entity.extension.ClothingProtectionHandler;
import com.craftingdead.core.world.entity.extension.LivingHandlerType;
import com.mojang.logging.LogUtils;
import io.netty.buffer.Unpooled;
import net.minecraft.data.DataGenerator;
Expand Down Expand Up @@ -103,7 +100,6 @@
import net.minecraftforge.server.ServerLifecycleHooks;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.network.PacketDistributor;
import com.craftingdead.core.trauma.TraumaHandler;

@Mod(CraftingDead.ID)
public class CraftingDead {
Expand Down Expand Up @@ -160,7 +156,7 @@ public CraftingDead() {
GunTriggerPredicates.deferredRegister.register(modEventBus);

MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(TraumaHandler.INSTANCE);
// MinecraftForge.EVENT_BUS.register(TraumaHandler.INSTANCE);

ProtectionConfig.load();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ public class AbstractContainerMenuMixin {
private ContainerSynchronizer synchronizer;

@SuppressWarnings("unchecked")
@Redirect(method =
"synchronizeSlotToRemote(ILnet/minecraft/world/item/ItemStack;Ljava/util/function/Supplier;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;matches(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Z"))
@Redirect(at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;matches(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Z"),
method = "synchronizeSlotToRemote")
private boolean matches(ItemStack lastStack, ItemStack currentStack, int slotIndex,
ItemStack __, Supplier<ItemStack> coppiedStack) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,41 @@
package com.craftingdead.core.mixin;

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 com.craftingdead.core.CraftingDead;
// import com.craftingdead.core.world.entity.extension.PlayerExtension;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.craftingdead.core.CraftingDead;
import com.craftingdead.core.world.entity.extension.PlayerExtension;
import net.minecraft.world.entity.player.Inventory;

@Mixin(Inventory.class)
public class InventoryMixin {

// DISABLED: The method 'swapPaint' no longer exists in Minecraft 1.18.2
// The hotbar scrolling behavior in 1.18.2 uses 'swapPaint(double)' which was removed
// This mixin would need to target the new method if this functionality is needed
// Original purpose: Scrolls over empty slots when in combat mode

// @Inject(at = @At("HEAD"), method = "swapPaint", cancellable = true)
// private void swapPaint(double direction, CallbackInfo callbackInfo) {
// if (CraftingDead.getInstance().getClientDist().getPlayerExtension()
// .map(PlayerExtension::isCombatModeEnabled)
// .orElse(false)) {
// callbackInfo.cancel();

// Inventory inventory = (Inventory) (Object) this;

// if (direction > 0.0D) {
// direction = 1.0D;
// }

// if (direction < 0.0D) {
// direction = -1.0D;
// }

// do {
// inventory.selected -= direction;
// if (inventory.selected < 0) {
// inventory.selected = 6;
// } else if (inventory.selected > 6) {
// inventory.selected = 0;
// }
// } while (!inventory.isEmpty() && inventory.getSelected().isEmpty());
// }
// }
@Inject(at = @At("HEAD"), method = "swapPaint", cancellable = true)
private void swapPaint(double direction, CallbackInfo callbackInfo) {
if (CraftingDead.getInstance().getClientDist().getPlayerExtension()
.map(PlayerExtension::isCombatModeEnabled)
.orElse(false)) {
callbackInfo.cancel();

Inventory inventory = (Inventory) (Object) this;

if (direction > 0.0D) {
direction = 1.0D;
}

if (direction < 0.0D) {
direction = -1.0D;
}

do {
inventory.selected -= direction;
if (inventory.selected < 0) {
inventory.selected = 6;
} else if (inventory.selected > 6) {
inventory.selected = 0;
}
} while (!inventory.isEmpty() && inventory.getSelected().isEmpty());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
@Mixin(KeyboardHandler.class)
public class KeyboardHandlerMixin {

@SuppressWarnings("unused")
@Inject(method = "keyPress(JIIII)V", at = @At("HEAD"), cancellable = true)
private void onKeyPress(long ignoredWindowPointer, int key, int ignoredScancode, int action,
int ignoredModifiers,
@Inject(method = "keyPress", at = @At("HEAD"), cancellable = true)
private void onKeyPress(long windowPointer, int key, int scancode, int action, int modifiers,
CallbackInfo ci) {

var minecraft = Minecraft.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {

// TODO: Fix this mixin - isImmobile() method doesn't exist in 1.18.2 LivingEntity
// The refmap has wrong method signature m_6107_()Z
/*
@Inject(at = @At("RETURN"), method = "isImmobile", cancellable = true)
private void isImmobile(CallbackInfoReturnable<Boolean> callbackInfo) {
var self = (LivingEntity) (Object) this;
Expand All @@ -47,11 +44,9 @@ private void isImmobile(CallbackInfoReturnable<Boolean> callbackInfo) {
}
});
}
*/


// TODO - temp until https://github.com/MinecraftForge/MinecraftForge/pull/7630 gets merged
// TODO: Also broken - refmap has wrong method mappings for 1.18.2
/*
@Redirect(at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;matches(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Z"),
method = "collectEquipmentChanges")
Expand All @@ -72,5 +67,4 @@ private boolean matches(ItemStack currentStack, ItemStack lastStack) {
}
return true;
}
*/
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.craftingdead.core.network;

import com.craftingdead.core.CraftingDead;
import com.craftingdead.core.network.message.play.BlockDestroyParticleMessage;
import com.craftingdead.core.network.message.play.BlockDestroyActionMessage;
import com.craftingdead.core.network.message.play.CancelActionMessage;
import com.craftingdead.core.network.message.play.CrouchMessage;
Expand Down Expand Up @@ -199,7 +200,14 @@ public void registerMessages(SimpleChannel simpleChannel) {
.add();

simpleChannel
.messageBuilder(BlockDestroyActionMessage.class, 0x16, NetworkDirection.PLAY_TO_SERVER)
.messageBuilder(BlockDestroyParticleMessage.class, 0x16, NetworkDirection.PLAY_TO_CLIENT)
.encoder(BlockDestroyParticleMessage::encode)
.decoder(BlockDestroyParticleMessage::decode)
.consumer(BlockDestroyParticleMessage::handle)
.add();

simpleChannel
.messageBuilder(BlockDestroyActionMessage.class, 0x17, NetworkDirection.PLAY_TO_SERVER)
.encoder(BlockDestroyActionMessage::encode)
.decoder(BlockDestroyActionMessage::decode)
.consumer(BlockDestroyActionMessage::handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package com.craftingdead.core.network.message.play;

import com.craftingdead.core.network.NetworkChannel;
import java.util.function.Supplier;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;

public record BlockDestroyActionMessage(BlockPos pos) {

Expand All @@ -38,13 +39,14 @@ public static BlockDestroyActionMessage decode(FriendlyByteBuf buf) {
public static void handle(BlockDestroyActionMessage msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
var player = ctx.get().getSender();
if (player == null) {
return;
}
var state = player.getLevel().getBlockState(msg.pos);
if (!state.isAir()) {
player.getLevel().levelEvent(2001, msg.pos, Block.getId(state));
player.getLevel().setBlock(msg.pos, Blocks.AIR.defaultBlockState(), 3);
if (player != null) {
var level = player.getLevel();
var state = level.getBlockState(msg.pos);
if (!state.isAir()) {
NetworkChannel.PLAY.getSimpleChannel().send(PacketDistributor.TRACKING_CHUNK.with(() ->
level.getChunkAt(msg.pos())), new BlockDestroyParticleMessage(msg.pos(), state));
player.getLevel().setBlock(msg.pos, Blocks.AIR.defaultBlockState(), 3);
}
}
});
ctx.get().setPacketHandled(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Crafting Dead
* Copyright (C) 2022 NexusNode LTD
*
* This Non-Commercial Software License Agreement (the "Agreement") is made between
* you (the "Licensee") and NEXUSNODE (BRAD HUNTER). (the "Licensor").
* By installing or otherwise using Crafting Dead (the "Software"), you agree to be
* bound by the terms and conditions of this Agreement as may be revised from time
* to time at Licensor's sole discretion.
*
* If you do not agree to the terms and conditions of this Agreement do not download,
* copy, reproduce or otherwise use any of the source code available online at any time.
*
* https://github.com/nexusnode/crafting-dead/blob/1.18.x/LICENSE.txt
*
* https://craftingdead.net/terms.php
*/

package com.craftingdead.core.network.message.play;

import java.util.function.Supplier;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.network.NetworkEvent;

public record BlockDestroyParticleMessage(BlockPos pos, BlockState state) {

public static void encode(BlockDestroyParticleMessage msg, FriendlyByteBuf buf) {
buf.writeBlockPos(msg.pos());
buf.writeVarInt(Block.getId(msg.state()));
}

public static BlockDestroyParticleMessage decode(FriendlyByteBuf buf) {
return new BlockDestroyParticleMessage(buf.readBlockPos(), Block.stateById(buf.readVarInt()));
}

public static void handle(BlockDestroyParticleMessage msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
var player = Minecraft.getInstance().player;
if (player != null) {
var state = player.getLevel().getBlockState(msg.pos);
player.level.addDestroyBlockEffect(msg.pos, state);
}
});
ctx.get().setPacketHandled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@

import com.craftingdead.core.ModDist;
import net.minecraft.core.RegistryAccess;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.server.ServerLifecycleHooks;

public class ServerDist implements ModDist {

public ServerDist() {
// Auto-updater moved to crafting-dead-updater mod (separate optional mod)
// Server-side updater is now handled by the crafting-dead-updater mod
// This keeps the main Crafting Dead mods CurseForge-compliant
}

@SuppressWarnings("deprecation")
@Override
public RegistryAccess registryAccess() {
Expand Down
Loading