This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
37 additions
and
67 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
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
55 changes: 4 additions & 51 deletions
55
src/main/java/badasintended/monopoly/mixin/ItemEntityMixin.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,65 +1,18 @@ | ||
package badasintended.monopoly.mixin; | ||
|
||
import badasintended.monopoly.Monopoly; | ||
import badasintended.monopoly.UnifyConfig; | ||
import net.minecraft.entity.ItemEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.tag.Tag; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
@Mixin(ItemEntity.class) | ||
public abstract class ItemEntityMixin extends EntityMixin { | ||
|
||
@Shadow | ||
public abstract UUID getThrower(); | ||
|
||
@Shadow | ||
public abstract ItemStack getStack(); | ||
|
||
@Shadow | ||
public abstract void setStack(ItemStack stack); | ||
|
||
@Unique | ||
private boolean monopoly$already = false; | ||
|
||
@Inject(method = "tick", at = @At("TAIL")) | ||
private void unifyStack(CallbackInfo ci) { | ||
if (!world.isClient && !monopoly$already) { | ||
monopoly$already = true; | ||
ItemStack stack = getStack(); | ||
for (Map.Entry<Identifier, UnifyConfig> entry : Monopoly.getInstance().getConfig().entrySet()) { | ||
Tag<Item> tag = world.getTagManager().getItems().getTag(entry.getKey()); | ||
if (tag == null) continue; | ||
if (tag.contains(stack.getItem())) { | ||
UnifyConfig unifyConfig = entry.getValue(); | ||
if (unifyConfig == null) continue; | ||
|
||
if (!unifyConfig.isThrown() && getThrower() != null) continue; | ||
if (!unifyConfig.isNbt() && stack.getTag() != null) continue; | ||
|
||
Item item = Registry.ITEM.get(unifyConfig.getTarget()); | ||
if (item == Items.AIR) continue; | ||
|
||
ItemStack unified = new ItemStack(item, stack.getCount()); | ||
|
||
unified.setTag(stack.getTag()); | ||
|
||
setStack(unified); | ||
} | ||
} | ||
} | ||
@ModifyVariable(method = "setStack", at = @At("HEAD"), argsOnly = true) | ||
private ItemStack unifyStack(ItemStack from) { | ||
return Monopoly.getInstance().unify(world, from); | ||
} | ||
|
||
} |