Skip to content

Commit

Permalink
V 1.6.1 - BETA-1.6.5
Browse files Browse the repository at this point in the history
Working BackPort
  • Loading branch information
mattymatty97 committed Nov 12, 2021
1 parent 1943fa5 commit 0ddd63e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Thu Nov 11 21:11:45 CET 2021
#Fri Nov 12 11:24:53 CET 2021
mod_version=1.6.1
mod_buildnumber=4
mod_buildnumber=5
12 changes: 11 additions & 1 deletion src/main/java/com/carpet_shadow/CarpetShadow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import carpet.CarpetExtension;
import carpet.CarpetServer;
import com.carpet_shadow.utility.RandomString;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.item.ItemStack;
Expand All @@ -12,7 +13,7 @@
import java.lang.ref.WeakReference;
import java.util.HashMap;

public class CarpetShadow implements CarpetExtension, ModInitializer {
public class CarpetShadow implements CarpetExtension, ModInitializer, ClientModInitializer {
public static final HashMap<String, WeakReference<ItemStack>> shadowMap = new HashMap<>();
public static final Logger LOGGER = LogManager.getLogger("carpet-shadow");
public static RandomString shadow_id_generator = new RandomString(CarpetShadowSettings.shadowItemIdSize);
Expand All @@ -32,4 +33,13 @@ public void onInitialize() {
shadowMap.clear();
}));
}

@Override
public void onInitializeClient() {
CarpetServer.manageExtension(new CarpetShadow());
LOGGER.info("Carpet Shadow Loading!");
ServerLifecycleEvents.SERVER_STOPPED.register((server -> {
shadowMap.clear();
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
public abstract class ScreenHandlerMixin {

@Redirect(method = "method_30010",
at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;setStack(Lnet/minecraft/item/ItemStack;)V", ordinal = 0),
at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;setStack(Lnet/minecraft/item/ItemStack;)V",ordinal = 2),
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount(Lnet/minecraft/item/ItemStack;)I", ordinal = 3)),
from = @At(value = "FIELD", target = "Lnet/minecraft/screen/slot/SlotActionType;SWAP:Lnet/minecraft/screen/slot/SlotActionType;")),
require = 0)
private void handle_shadowing(Slot instance, ItemStack stack) {
try {
Expand All @@ -38,11 +38,29 @@ private void handle_shadowing(Slot instance, ItemStack stack) {
CarpetShadow.shadowMap.put(shadow_id, new WeakReference<>(stack));
((ShadowItem) (Object) stack).setShadowId(shadow_id);
}
if (CarpetShadowSettings.shadowItemPersistence) {
throw new ShadowingException();
} else {
throw error;
throw error;
}
}

@Redirect(method = "method_30010",
at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;setStack(Lnet/minecraft/item/ItemStack;)V",ordinal = 4),
slice = @Slice(
from = @At(value = "FIELD", target = "Lnet/minecraft/screen/slot/SlotActionType;SWAP:Lnet/minecraft/screen/slot/SlotActionType;")),
require = 0)
private void handle_shadowing2(Slot instance, ItemStack stack) {
try {
instance.setStack(stack);
} catch (Throwable error) {
CarpetShadow.LOGGER.warn("New Shadow Item Created");
String shadow_id = ((ShadowItem) (Object) stack).getShadowId();
if (shadow_id == null) {
do {
shadow_id = CarpetShadow.shadow_id_generator.nextString();
} while (CarpetShadow.shadowMap.containsKey(shadow_id));
CarpetShadow.shadowMap.put(shadow_id, new WeakReference<>(stack));
((ShadowItem) (Object) stack).setShadowId(shadow_id);
}
throw error;
}
}
//
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
"entrypoints": {
"main": [
"com.carpet_shadow.CarpetShadow"
]
],
"client": [],
"server": []
},
"mixins": [
"carpet-shadow.mixins.json"
],
"depends": {
"fabricloader": ">=0.11.7",
"fabric": ">=0.11.0",
"carpet": ">=1.4.52",
"carpet": ">=1.4.44",
"minecraft": "1.16.5"
},
"suggests": {
Expand Down

0 comments on commit 0ddd63e

Please sign in to comment.