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
629cbf8
commit 3c484ef
Showing
19 changed files
with
344 additions
and
256 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
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
118 changes: 66 additions & 52 deletions
118
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,59 +1,73 @@ | ||
package io.github.jamalam360.utility_belt; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import com.mojang.serialization.Codec; | ||
import java.util.List; | ||
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 UtilityBeltInventory() { | ||
super(4); | ||
} | ||
|
||
@Override | ||
public void fromTag(ListTag listTag) { | ||
this.clearContent(); | ||
|
||
for (int i = 0; i < listTag.size(); ++i) { | ||
this.setItem(i, ItemStack.of(listTag.getCompound(i))); | ||
} | ||
} | ||
|
||
@Override | ||
public ListTag createTag() { | ||
ListTag listTag = new ListTag(); | ||
|
||
for (int i = 0; i < this.getContainerSize(); ++i) { | ||
listTag.add(this.getItem(i).save(new CompoundTag())); | ||
} | ||
|
||
return listTag; | ||
} | ||
|
||
@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 false; | ||
} | ||
|
||
@Override | ||
public UtilityBeltInventory clone() { | ||
UtilityBeltInventory inv = new UtilityBeltInventory(); | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
inv.setItem(i, this.getItem(i).copy()); | ||
} | ||
|
||
return inv; | ||
} | ||
|
||
public static final Codec<UtilityBeltInventory> CODEC = Codec | ||
.list(ItemStack.CODEC) | ||
.xmap(UtilityBeltInventory::new, UtilityBeltInventory::getItems); | ||
|
||
public static final StreamCodec<RegistryFriendlyByteBuf, UtilityBeltInventory> STREAM_CODEC = StreamCodec | ||
.composite( | ||
ItemStack.STREAM_CODEC.apply(ByteBufCodecs.list(4)), | ||
UtilityBeltInventory::getItems, | ||
UtilityBeltInventory::new | ||
); | ||
|
||
|
||
public UtilityBeltInventory() { | ||
super(4); | ||
} | ||
|
||
private UtilityBeltInventory(List<ItemStack> stacks) { | ||
super(4); | ||
|
||
for (int i = 0; i < stacks.size(); i++) { | ||
this.setItem(i, stacks.get(i)); | ||
} | ||
} | ||
|
||
@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 false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 0; | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
hash += this.getItem(i).hashCode(); | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
@Override | ||
public UtilityBeltInventory clone() { | ||
UtilityBeltInventory inv = new UtilityBeltInventory(); | ||
for (int i = 0; i < this.getContainerSize(); i++) { | ||
inv.setItem(i, this.getItem(i).copy()); | ||
} | ||
|
||
return inv; | ||
} | ||
} |
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.