-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed QUICK_MOVE ( shift clicking ) fragility. had to use a compromise: now shadow stacks will behave like unstackables on QUICK_MOVE
- Loading branch information
1 parent
aaa1246
commit 6cc4258
Showing
7 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#Tue Nov 09 14:01:36 CET 2021 | ||
mod_version=1.4.1 | ||
mod_buildnumber=17 | ||
#Tue Nov 09 21:09:38 CET 2021 | ||
mod_version=1.5 | ||
mod_buildnumber=7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/com/carpet_shadow/mixins/fragility/ScreenHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.carpet_shadow.mixins.fragility; | ||
|
||
import com.carpet_shadow.CarpetShadowSettings; | ||
import com.carpet_shadow.Globals; | ||
import com.carpet_shadow.interfaces.ShadowItem; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.screen.slot.SlotActionType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
@Mixin(ScreenHandler.class) | ||
public abstract class ScreenHandlerMixin { | ||
|
||
|
||
@Shadow protected abstract boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast); | ||
|
||
@Shadow protected abstract void internalOnSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player); | ||
|
||
String shadowId1 = null; | ||
@Redirect(method = "internalOnSlotClick", slice = @Slice( | ||
from=@At(value = "INVOKE",target = "Lnet/minecraft/screen/slot/Slot;canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z",ordinal = 1)), | ||
at=@At(value = "INVOKE",target = "Lnet/minecraft/screen/slot/Slot;setStack(Lnet/minecraft/item/ItemStack;)V",ordinal = 0) | ||
) | ||
public void remove_shadow_stack(Slot instance, ItemStack stack){ | ||
shadowId1 = ((ShadowItem)(Object)stack).getShadowId(); | ||
instance.setStack(stack); | ||
} | ||
|
||
@Redirect(method = "internalOnSlotClick", slice = @Slice( | ||
from=@At(value = "INVOKE",target = "Lnet/minecraft/screen/slot/Slot;canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z",ordinal = 1)), | ||
at=@At(value = "INVOKE",target = "Lnet/minecraft/screen/ScreenHandler;setCursorStack(Lnet/minecraft/item/ItemStack;)V", ordinal = 1) | ||
) | ||
public void remove_shadow_stack(ScreenHandler instance, ItemStack stack){ | ||
String shadowId2 = ((ShadowItem)(Object)stack).getShadowId(); | ||
if(CarpetShadowSettings.shadowItemFragilityFixes && shadowId1 != null && shadowId1.equals(shadowId2)){ | ||
instance.setCursorStack(ItemStack.EMPTY); | ||
}else{ | ||
instance.setCursorStack(stack); | ||
} | ||
shadowId1 = null; | ||
} | ||
|
||
@Redirect(method = "internalOnSlotClick", slice=@Slice( | ||
from = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z") | ||
), | ||
at=@At(value = "INVOKE",target = "Lnet/minecraft/screen/ScreenHandler;transferSlot(Lnet/minecraft/entity/player/PlayerEntity;I)Lnet/minecraft/item/ItemStack;")) | ||
public ItemStack fix_shift(ScreenHandler instance, PlayerEntity player, int index){ | ||
if(CarpetShadowSettings.shadowItemFragilityFixes){ | ||
Slot og = instance.slots.get(index); | ||
ItemStack og_item = og.getStack(); | ||
if(((ShadowItem)(Object)og_item).getShadowId() != null){ | ||
ItemStack mirror = og_item.copy(); | ||
((ShadowItem)(Object)mirror).setShadowId(((ShadowItem)(Object)og_item).getShadowId()); | ||
og.setStack(mirror); | ||
ItemStack ret = instance.transferSlot(player,index); | ||
if(ret == ItemStack.EMPTY){ | ||
og_item = Globals.getByIdOrAdd(((ShadowItem)(Object)og_item).getShadowId(), og_item); | ||
og.setStack(og_item); | ||
og_item.setCount(mirror.getCount()); | ||
} | ||
return ret; | ||
} | ||
} | ||
return instance.transferSlot(player,index); | ||
} | ||
|
||
@Redirect(method = "insertItem", slice=@Slice( | ||
from = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;",ordinal = 1) | ||
), | ||
at=@At(value = "INVOKE",target = "Lnet/minecraft/item/ItemStack;split(I)Lnet/minecraft/item/ItemStack;",ordinal = 1)) | ||
public ItemStack fix_shift(ItemStack instance, int amount){ | ||
if(CarpetShadowSettings.shadowItemFragilityFixes && ((ShadowItem)(Object)instance).getShadowId() != null){ | ||
String shadow_id = ((ShadowItem)(Object)instance).getShadowId(); | ||
ItemStack og_item = Globals.getByIdOrNull(shadow_id); | ||
if(og_item != null){ | ||
og_item.setCount(instance.getCount()); | ||
instance.setCount(0); | ||
return og_item; | ||
} | ||
} | ||
return instance.split(amount); | ||
} | ||
|
||
@Redirect(method = "insertItem", | ||
at=@At(value = "INVOKE",target = "Lnet/minecraft/item/ItemStack;isStackable()Z",ordinal = 0)) | ||
public boolean fix_shift2(ItemStack instance){ | ||
if(CarpetShadowSettings.shadowItemFragilityFixes && ((ShadowItem)(Object)instance).getShadowId() != null){ | ||
return false; | ||
} | ||
return instance.isStackable(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters