Skip to content

Commit 1b2213d

Browse files
committed
- fixed duplication bug while right clicking stacks in the workbench (whooops)
- fixed config option of fully-break-modular tools, now the correct item is set and it can be repaired
1 parent c670bd2 commit 1b2213d

22 files changed

+305
-48
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
- fixed crash with Enchancement Mod
33
- fixed duplicating throwing knifes when multishot
44
- fixed sword sweeping on neoforge
5-
- strongly improved rendering performance
5+
- strongly improved rendering performance
6+
- fixed ht-treechop not working correctly in some module setups
7+
- fixed duplication bug while right clicking stacks in the workbench (whooops)
8+
- fixed config option of fully-break-modular tools, now the correct item is set and it can be repaired

common/libs/armory-local.jar

13.7 KB
Binary file not shown.

common/libs/arsenal-local.jar

77 Bytes
Binary file not shown.

common/src/main/java/smartin/miapi/client/gui/crafting/CraftingScreenHandler.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.resources.ResourceLocation;
77
import net.minecraft.server.level.ServerPlayer;
88
import net.minecraft.world.Container;
9+
import net.minecraft.world.ContainerListener;
910
import net.minecraft.world.SimpleContainer;
1011
import net.minecraft.world.entity.EquipmentSlot;
1112
import net.minecraft.world.entity.player.Inventory;
@@ -214,9 +215,23 @@ public CraftingScreenHandler getScreenHandler() {
214215
@Override
215216
public void setChanged() {
216217
super.setChanged();
217-
CraftingScreenHandler.this.slotsChanged(this);
218218
}
219219
};
220+
((SimpleContainer)inventory).addListener(new ContainerListener() {
221+
@Override
222+
public void containerChanged(Container container) {
223+
CraftingScreenHandler.this.slotsChanged(container);
224+
if(notClient()){
225+
ItemStack block = blockEntity.getItem();
226+
ItemStack inv = inventory.getItem(0);
227+
if (!ItemStack.matches(block, inv)) {
228+
blockEntity.setItem(inventory.getItem(0));
229+
blockEntity.saveAndSync();
230+
updateBE();
231+
}
232+
}
233+
}
234+
});
220235
if (blockEntity != null) {
221236
this.setItem(blockEntity.getItem());
222237
}
@@ -287,13 +302,6 @@ public boolean notClient() {
287302
public void broadcastChanges() {
288303
super.broadcastChanges();
289304
if (notClient()) {
290-
ItemStack block = blockEntity.getItem();
291-
ItemStack inv = inventory.getItem(0);
292-
if (!ItemStack.isSameItem(block, inv)) {
293-
blockEntity.setItem(inventory.getItem(0));
294-
blockEntity.saveAndSync();
295-
updateBE();
296-
}
297305
}
298306
if (blockEntity == null && delegate.get(0) == 1) {
299307
short xsh = (short) delegate.get(1);

common/src/main/java/smartin/miapi/item/modular/items/BrokenModularVisualOnlyItem.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import com.redpxnda.nucleus.util.Color;
44
import net.minecraft.network.chat.Component;
5-
import net.minecraft.world.item.Item;
6-
import net.minecraft.world.item.ItemStack;
7-
import net.minecraft.world.item.TooltipFlag;
5+
import net.minecraft.world.item.*;
86
import org.lwjgl.system.NonnullDefault;
7+
import smartin.miapi.config.MiapiConfig;
98
import smartin.miapi.item.FakeItemManager;
109
import smartin.miapi.item.modular.PlatformModularItemMethods;
1110
import smartin.miapi.item.modular.VisualModularItem;
@@ -16,9 +15,18 @@
1615
import java.util.List;
1716

1817
@NonnullDefault
19-
public class BrokenModularVisualOnlyItem extends Item implements PlatformModularItemMethods, VisualModularItem {
18+
public class BrokenModularVisualOnlyItem extends TieredItem implements PlatformModularItemMethods, VisualModularItem {
2019
public BrokenModularVisualOnlyItem() {
21-
super(new Properties().stacksTo(1).durability(1000));
20+
super(new ModularToolMaterial(), new Properties().stacksTo(1).durability(1000));
21+
}
22+
23+
@Override
24+
public Tier getTier() {
25+
ItemStack itemStack = FakeItemManager.getDefaultInstance(this);
26+
if (MiapiConfig.getServerConfig().other.looseToolMaterial && itemStack != null) {
27+
return ModularToolMaterial.forItemStack(itemStack);
28+
}
29+
return super.getTier();
2230
}
2331

2432
@Override

common/src/main/java/smartin/miapi/mixin/item/MiapiItemStackMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public abstract class MiapiItemStackMixin {
122122
if (damage + current.getDamageValue() >= current.getMaxDamage()) {
123123
for (EquipmentSlot slot : EquipmentSlot.values()) {
124124
if (player.getItemBySlot(slot).equals(current)) {
125-
ItemStack broken = new ItemStack(RegistryInventory.visualOnlymodularItem);
125+
ItemStack broken = new ItemStack(RegistryInventory.brokenModualrItem);
126126
ItemModule.getModules(current).writeToItem(broken);
127127
broken.set(DataComponents.DAMAGE, current.get(DataComponents.DAMAGE));
128128
broken.set(DataComponents.MAX_DAMAGE, current.get(DataComponents.MAX_DAMAGE));
@@ -144,7 +144,7 @@ public abstract class MiapiItemStackMixin {
144144
if (ModularItem.isModularItem(current) && current.isDamageableItem() && !MiapiConfig.getServerConfig().other.fullBreakModularItems) {
145145
if (entity != null && !entity.hasInfiniteMaterials()) {
146146
if (amount + current.getDamageValue() >= current.getMaxDamage()) {
147-
ItemStack broken = new ItemStack(RegistryInventory.visualOnlymodularItem);
147+
ItemStack broken = new ItemStack(RegistryInventory.brokenModualrItem);
148148
ItemModule.getModules(current).writeToItem(broken);
149149
broken.set(DataComponents.DAMAGE, current.get(DataComponents.DAMAGE));
150150
broken.set(DataComponents.MAX_DAMAGE, current.get(DataComponents.MAX_DAMAGE));

common/src/main/java/smartin/miapi/mixin/smithing/AnvilMenuMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public class AnvilMenuMixin {
1818
at = @At("TAIL")
1919
)
2020
public void miapi$preventFullBreak(CallbackInfo ci) {
21-
ItemStack current = (
21+
ItemStack current = (
2222
(ForgingScreenHandlerAccessor) this)
2323
.getResultSlots()
2424
.getItem(0);
25-
if (VisualModularItem.isVisualModularItem(current) && current.isDamageableItem() && !MiapiConfig.getServerConfig().other.fullBreakModularItems) {
25+
if (VisualModularItem.isVisualModularItem(current) && current.isDamageableItem() && !MiapiConfig.getServerConfig().other.fullBreakModularItems && false) {
2626
((ForgingScreenHandlerAccessor) this)
2727
.getResultSlots()
2828
.setItem(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package smartin.miapi.mixin.smithing;
2+
3+
import net.minecraft.world.inventory.ResultContainer;
4+
import net.minecraft.world.item.ItemStack;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
8+
import smartin.miapi.item.modular.VisualModularItem;
9+
import smartin.miapi.modules.properties.ItemIdProperty;
10+
11+
@Mixin(ResultContainer.class)
12+
public class ResultContainerMixin {
13+
14+
@ModifyVariable(
15+
method = "setItem"
16+
, at = @At("HEAD"),
17+
argsOnly = true)
18+
private ItemStack modifyStackBeforeSet(ItemStack current) {
19+
if (VisualModularItem.isVisualModularItem(current) && current.isDamageableItem() && current.getMaxDamage() > current.getDamageValue() + 2)
20+
{
21+
return ItemIdProperty.changeId(current);
22+
}
23+
return current;
24+
}
25+
}

common/src/main/java/smartin/miapi/modules/properties/ItemIdProperty.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import smartin.miapi.Miapi;
99
import smartin.miapi.blocks.ModularWorkBenchEntity;
1010
import smartin.miapi.craft.CraftAction;
11+
import smartin.miapi.datapack.ReloadEvents;
12+
import smartin.miapi.item.modular.VisualModularItem;
1113
import smartin.miapi.modules.ItemModule;
1214
import smartin.miapi.modules.ModuleInstance;
13-
import smartin.miapi.modules.properties.util.CodecProperty;
14-
import smartin.miapi.modules.properties.util.CraftingProperty;
15-
import smartin.miapi.modules.properties.util.EditorError;
16-
import smartin.miapi.modules.properties.util.MergeType;
15+
import smartin.miapi.modules.properties.util.*;
1716
import smartin.miapi.registries.RegistryInventory;
1817

1918
import java.util.List;
@@ -85,4 +84,21 @@ public ItemStack preview(ItemStack old, ItemStack crafting, Player player, Modul
8584
public ResourceLocation merge(ResourceLocation left, ResourceLocation right, MergeType mergeType) {
8685
return right;
8786
}
87+
88+
public Optional<ResourceLocation> getData(ItemStack itemStack) {
89+
if (itemStack == null) {
90+
return Optional.empty();
91+
}
92+
if (!VisualModularItem.isVisualModularItem(itemStack)) {
93+
return Optional.empty();
94+
}
95+
if (ReloadEvents.isInReload()) {
96+
return Optional.empty();
97+
}
98+
ModuleInstance baseModule = ItemModule.getModules(itemStack);
99+
if (baseModule == null || baseModule.module == ItemModule.empty) {
100+
return Optional.empty();
101+
}
102+
return Optional.ofNullable(baseModule.getPropertyItemStack(this));
103+
}
88104
}

common/src/main/java/smartin/miapi/modules/properties/RepairPriority.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import net.minecraft.world.item.ItemStack;
55
import net.minecraft.world.item.crafting.Ingredient;
66
import smartin.miapi.Miapi;
7+
import smartin.miapi.datapack.ReloadEvents;
8+
import smartin.miapi.item.modular.VisualModularItem;
9+
import smartin.miapi.material.MaterialProperty;
710
import smartin.miapi.material.base.IngredientController;
11+
import smartin.miapi.material.base.Material;
812
import smartin.miapi.modules.ItemModule;
913
import smartin.miapi.modules.ModuleInstance;
1014
import smartin.miapi.modules.cache.ModularItemCache;
11-
import smartin.miapi.material.base.Material;
12-
import smartin.miapi.material.MaterialProperty;
15+
import smartin.miapi.modules.properties.util.DoubleOperationResolvable;
1316
import smartin.miapi.modules.properties.util.DoubleProperty;
1417

1518
import java.util.ArrayList;
@@ -80,4 +83,21 @@ private List<Material> getRepairMaterialsPrivate(ItemStack itemStack) {
8083
}
8184
return materials;
8285
}
86+
87+
public Optional<DoubleOperationResolvable> getData(ItemStack itemStack) {
88+
if (itemStack == null) {
89+
return Optional.empty();
90+
}
91+
if (!VisualModularItem.isVisualModularItem(itemStack)) {
92+
return Optional.empty();
93+
}
94+
if (ReloadEvents.isInReload()) {
95+
return Optional.empty();
96+
}
97+
ModuleInstance baseModule = ItemModule.getModules(itemStack);
98+
if (baseModule == null || baseModule.module == ItemModule.empty) {
99+
return Optional.empty();
100+
}
101+
return Optional.ofNullable(baseModule.getPropertyItemStack(this));
102+
}
83103
}

common/src/main/java/smartin/miapi/modules/properties/compat/ht_treechop/TreechopUtil.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ht.treechop.api.TreeChopAPI;
55
import net.minecraft.core.BlockPos;
66
import net.minecraft.world.entity.player.Player;
7+
import net.minecraft.world.item.AxeItem;
78
import net.minecraft.world.item.ItemStack;
89
import net.minecraft.world.level.Level;
910
import net.minecraft.world.level.block.state.BlockState;
@@ -12,30 +13,22 @@
1213
public class TreechopUtil {
1314
public static TreeChopAPI api = null;
1415

15-
public static void setTreechopApi(Object object){
16+
public static void setTreechopApi(Object object) {
1617
api = (TreeChopAPI) object;
17-
api.registerChoppingItemBehavior(RegistryInventory.modularAxe, new IChoppingItem() {
18-
@Override
19-
public boolean canChop(Player playerEntity, ItemStack itemStack, Level world, BlockPos blockPos, BlockState blockState) {
20-
return true;
21-
}
18+
RegistryInventory.MODULAR_ITEMS.addCallback(item -> {
19+
api.registerChoppingItemBehavior(item, new IChoppingItem() {
20+
@Override
21+
public boolean canChop(Player playerEntity, ItemStack itemStack, Level world, BlockPos blockPos, BlockState blockState) {
22+
return item instanceof AxeItem || TreechopProperty.property.getValue(itemStack).orElse(0.0).intValue() > 0;
23+
}
2224

23-
@Override
24-
public int getNumChops(ItemStack itemStack, BlockState blockState) {
25-
return TreechopProperty.property.getValue(itemStack).orElse(0.0).intValue() + 1;
26-
}
27-
});
28-
29-
api.registerChoppingItemBehavior(RegistryInventory.modularMattock, new IChoppingItem() {
30-
@Override
31-
public boolean canChop(Player playerEntity, ItemStack itemStack, Level world, BlockPos blockPos, BlockState blockState) {
32-
return true;
33-
}
25+
@Override
26+
public int getNumChops(ItemStack itemStack, BlockState blockState) {
3427

35-
@Override
36-
public int getNumChops(ItemStack itemStack, BlockState blockState) {
37-
return TreechopProperty.property.getValue(itemStack).orElse(0.0).intValue() + 1;
38-
}
28+
return TreechopProperty.property.getValue(itemStack).orElse(0.0).intValue() +
29+
(item instanceof AxeItem ? 1 : 0);
30+
}
31+
});
3932
});
4033
}
4134
}

common/src/main/java/smartin/miapi/modules/properties/mining/mode/StaggeredMiningMode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public void execute(List<BlockPos> posList, Level world, ServerPlayer player, Bl
5656
int success = 0;
5757
do {
5858
pos = reducedList.remove(0);
59+
if (itemStack.getMaxDamage() - itemStack.getDamageValue() < 2) {
60+
return;
61+
}
5962
if (tryBreakBlock(player, pos)) {
6063
success++;
6164
if (!player.isCreative()) {

0 commit comments

Comments
 (0)