generated from JamCoreModding/multi-loader-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7944b58
commit a09a4cc
Showing
20 changed files
with
395 additions
and
291 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
- Fix a dupe exploit (#44) | ||
This release brings about a significant internal rework with should make Utility Belt significantly | ||
less buggy. I have conducted a long play testing session before this release to try to verify | ||
everything works as intended. | ||
|
||
## Closed Issues | ||
|
||
- #47: fishing rod flickering | ||
- #46: dupe bug | ||
- #45: dupe bug | ||
|
||
Alongside the issues that were reported, many others have been fixed. |
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
99 changes: 68 additions & 31 deletions
99
common/src/main/java/io/github/jamalam360/utility_belt/UtilityBeltInventory.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 |
---|---|---|
@@ -1,73 +1,110 @@ | ||
package io.github.jamalam360.utility_belt; | ||
|
||
import com.mojang.serialization.Codec; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.core.component.DataComponents; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.world.SimpleContainer; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class UtilityBeltInventory extends SimpleContainer { | ||
public record UtilityBeltInventory(List<ItemStack> items) { | ||
|
||
public static final UtilityBeltInventory EMPTY = new UtilityBeltInventory(NonNullList.withSize(4, ItemStack.EMPTY)); | ||
public static final Codec<UtilityBeltInventory> CODEC = Codec | ||
.list(ItemStack.CODEC) | ||
.xmap(UtilityBeltInventory::new, UtilityBeltInventory::getItems); | ||
.list(ItemStack.OPTIONAL_CODEC) | ||
.xmap(UtilityBeltInventory::new, UtilityBeltInventory::items); | ||
|
||
public static final StreamCodec<RegistryFriendlyByteBuf, UtilityBeltInventory> STREAM_CODEC = StreamCodec | ||
.composite( | ||
ItemStack.STREAM_CODEC.apply(ByteBufCodecs.list(4)), | ||
UtilityBeltInventory::getItems, | ||
ItemStack.OPTIONAL_STREAM_CODEC.apply(ByteBufCodecs.list(4)), | ||
UtilityBeltInventory::items, | ||
UtilityBeltInventory::new | ||
); | ||
|
||
public UtilityBeltInventory { | ||
if (items.size() != 4) { | ||
throw new IllegalArgumentException("Utility belt inventory must have exactly 4 items"); | ||
} | ||
} | ||
|
||
public UtilityBeltInventory() { | ||
super(4); | ||
public ItemStack getItem(int index) { | ||
return items.get(index); | ||
} | ||
|
||
private UtilityBeltInventory(List<ItemStack> stacks) { | ||
super(4); | ||
public int getContainerSize() { | ||
return 4; | ||
} | ||
|
||
for (int i = 0; i < stacks.size(); i++) { | ||
this.setItem(i, stacks.get(i)); | ||
} | ||
public UtilityBeltInventory clone() { | ||
return new UtilityBeltInventory(new ArrayList<>(items)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof UtilityBeltInventory other) { | ||
if (other.getContainerSize() == this.getContainerSize()) { | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
if (!ItemStack.matches(this.getItem(i), other.getItem(i))) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
return ItemStack.listMatches(items, other.items); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public int hashCode() { | ||
int hash = 0; | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
hash += this.getItem(i).hashCode(); | ||
return ItemStack.hashStackList(items); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return invToString("UtilityBeltInventory[", items); | ||
} | ||
|
||
public static class Mutable extends SimpleContainer { | ||
|
||
public Mutable(UtilityBeltInventory inv) { | ||
super(4); | ||
|
||
for (int i = 0; i < inv.getContainerSize(); i++) { | ||
this.setItem(i, inv.getItem(i)); | ||
} | ||
} | ||
|
||
public UtilityBeltInventory toImmutable() { | ||
return new UtilityBeltInventory(new ArrayList<>(this.getItems())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof UtilityBeltInventory other) { | ||
return ItemStack.listMatches(this.getItems(), other.items); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return hash; | ||
@Override | ||
public String toString() { | ||
return invToString("UtilityBeltInventory$Mutable[", this.getItems()); | ||
} | ||
} | ||
|
||
@Override | ||
public UtilityBeltInventory clone() { | ||
UtilityBeltInventory inv = new UtilityBeltInventory(); | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
inv.setItem(i, this.getItem(i).copy()); | ||
private static String invToString(String prefix, List<ItemStack> items) { | ||
StringBuilder string = new StringBuilder(prefix); | ||
|
||
for (int i = 0; i < items.size(); i++) { | ||
string.append(items.get(i)); | ||
string.append(" {"); | ||
string.append(items.get(i).getComponents().get(DataComponents.DAMAGE)); | ||
string.append("}"); | ||
if (i < items.size() - 1) { | ||
string.append(", "); | ||
} | ||
} | ||
|
||
return inv; | ||
return string.toString(); | ||
} | ||
} |
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
Oops, something went wrong.