-
-
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
1 parent
36bedd8
commit d340da1
Showing
11 changed files
with
273 additions
and
16 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
...a/me/neovitalism/neomixins/NeoMixins.java → ...eballdatastorage/PokeballDataStorage.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,15 +1,15 @@ | ||
package me.neovitalism.neomixins; | ||
package me.neovitalism.pokeballdatastorage; | ||
|
||
import net.minecraftforge.fml.common.Mod; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@Mod("neomixins") | ||
public class NeoMixins { | ||
@Mod("pokeballdatastorage") | ||
public class PokeballDataStorage { | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
public NeoMixins() { | ||
public PokeballDataStorage() { | ||
LOGGER.log(Level.INFO, "Loaded!"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...116/src/main/java/me/neovitalism/pokeballdatastorage/mixins/EmptyPokeBallEntityMixin.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,71 @@ | ||
package me.neovitalism.pokeballdatastorage.mixins; | ||
|
||
import com.pixelmonmod.pixelmon.api.pokemon.item.pokeball.PokeBall; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.EmptyPokeBallEntity; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.PokeBallEntity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.UUID; | ||
|
||
@SuppressWarnings("UnusedMixin") | ||
@Mixin(value = EmptyPokeBallEntity.class, remap = false) | ||
public abstract class EmptyPokeBallEntityMixin extends PokeBallEntity { | ||
public EmptyPokeBallEntityMixin(EntityType<? extends PokeBallEntity> type, World world) { | ||
super(type, world); | ||
} | ||
|
||
@Redirect(method = "onHit", at = @At(value = "INVOKE", | ||
target = "Lcom/pixelmonmod/pixelmon/api/pokemon/item/pokeball/PokeBall;getBallItem()Lnet/minecraft/item/ItemStack;"), | ||
remap = true) | ||
public ItemStack neoMixins$redirectBallItemOnHit(PokeBall instance) { | ||
ItemStack item = this.getItemFromNBT(); | ||
if(!item.isEmpty()) return item; | ||
return instance.getBallItem(); | ||
} | ||
|
||
@Inject(method = "onHit", at = @At(value = "INVOKE", | ||
target = "Lcom/pixelmonmod/pixelmon/entities/pokeballs/EmptyPokeBallEntity;setPairedEntity(Lnet/minecraft/entity/Entity;)V"), | ||
remap = true) | ||
public void neoMixins$resetDropItem(RayTraceResult movingObjectPosition, CallbackInfo ci) { | ||
if (this.getOwner() instanceof PlayerEntity) { | ||
this.dropItem = !((PlayerEntity)this.getOwner()).isCreative(); | ||
} else this.dropItem = true; | ||
} | ||
|
||
@Redirect(method = "catchPokemon", at = @At(value = "INVOKE", | ||
target = "Lcom/pixelmonmod/pixelmon/api/pokemon/item/pokeball/PokeBall;getBallItem()Lnet/minecraft/item/ItemStack;")) | ||
public ItemStack neoMixins$redirectBallItemOnCatch(PokeBall instance) { | ||
ItemStack item = this.getItemFromNBT(); | ||
if(!item.isEmpty()) return item; | ||
return instance.getBallItem(); | ||
} | ||
|
||
@Override | ||
public ItemStack[] getComponentItems() { | ||
CompoundNBT itemNBT = this.getPersistentData().getCompound("item"); | ||
if (itemNBT.getCompound("tag").getBoolean("Unbreakable")) return new ItemStack[]{ItemStack.of(itemNBT)}; | ||
return super.getComponentItems(); | ||
} | ||
|
||
@Override | ||
public UUID getOwnerId() { | ||
return this.thrower.getUUID(); | ||
} | ||
|
||
@Unique | ||
public ItemStack getItemFromNBT() { | ||
CompoundNBT itemNBT = this.getPersistentData().getCompound("item"); | ||
return ItemStack.of(itemNBT); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
forge116/src/main/java/me/neovitalism/pokeballdatastorage/mixins/PokeBallItemMixin.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,63 @@ | ||
package me.neovitalism.pokeballdatastorage.mixins; | ||
|
||
import com.pixelmonmod.pixelmon.api.events.ThrowPokeballEvent; | ||
import com.pixelmonmod.pixelmon.api.pokemon.item.pokeball.PokeBall; | ||
import com.pixelmonmod.pixelmon.battles.controller.participants.PixelmonWrapper; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.EmptyPokeBallEntity; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.PokeBallEntity; | ||
import com.pixelmonmod.pixelmon.items.PixelmonItem; | ||
import com.pixelmonmod.pixelmon.items.PokeBallItem; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.ActionResultType; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import java.util.Optional; | ||
|
||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "UnusedMixin", "OptionalGetWithoutIsPresent"}) | ||
@Mixin(value = PokeBallItem.class, remap = false) | ||
public abstract class PokeBallItemMixin extends PixelmonItem { | ||
public PokeBallItemMixin(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Inject(method = "use", at = @At(value = "INVOKE", target = | ||
"Lnet/minecraft/world/World;addFreshEntity(Lnet/minecraft/entity/Entity;)Z"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT, remap = true, cancellable = true) | ||
public void neoMixins$use(World world, PlayerEntity entityPlayer, Hand handIn, | ||
CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack itemStack, | ||
Optional<PokeBall> pokeBall) { | ||
EmptyPokeBallEntity entity = new EmptyPokeBallEntity(world, entityPlayer, pokeBall.get(), !entityPlayer.isCreative()); | ||
this.setBallInNBT(entity, itemStack); | ||
world.addFreshEntity(entity); | ||
if (!entityPlayer.isCreative()) { | ||
itemStack.shrink(1); | ||
entityPlayer.inventory.setChanged(); | ||
} | ||
cir.setReturnValue(new ActionResult<>(ActionResultType.SUCCESS, itemStack)); | ||
} | ||
|
||
@Inject(method = "useFromBag", at = @At(value = "INVOKE", target = | ||
"Lnet/minecraft/world/World;addFreshEntity(Lnet/minecraft/entity/Entity;)Z"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT) | ||
public void neoMixins$useFromBag(PixelmonWrapper userWrapper, PixelmonWrapper targetWrapper, ItemStack stack, | ||
CallbackInfoReturnable<Boolean> cir, PlayerEntity thrower, Optional<PokeBall> pokeBall, | ||
ThrowPokeballEvent throwPokeballEvent, World world, PokeBallEntity p) { | ||
this.setBallInNBT((EmptyPokeBallEntity) p, stack); | ||
} | ||
|
||
@Unique | ||
private void setBallInNBT(EmptyPokeBallEntity entity, ItemStack ballItem) { | ||
ItemStack clonedItem = ballItem.copy(); | ||
clonedItem.setCount(1); | ||
entity.getPersistentData().put("item", clonedItem.serializeNBT()); | ||
} | ||
} |
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
8 changes: 4 additions & 4 deletions
8
...a/me/neovitalism/neomixins/NeoMixins.java → ...eballdatastorage/PokeballDataStorage.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,15 +1,15 @@ | ||
package me.neovitalism.neomixins; | ||
package me.neovitalism.pokeballdatastorage; | ||
|
||
import net.minecraftforge.fml.common.Mod; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@Mod("neomixins") | ||
public class NeoMixins { | ||
@Mod("pokeballdatastorage") | ||
public class PokeballDataStorage { | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
public NeoMixins() { | ||
public PokeballDataStorage() { | ||
LOGGER.log(Level.INFO, "Loaded!"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...120/src/main/java/me/neovitalism/pokeballdatastorage/mixins/EmptyPokeBallEntityMixin.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,58 @@ | ||
package me.neovitalism.pokeballdatastorage.mixins; | ||
|
||
import com.pixelmonmod.pixelmon.api.pokemon.item.pokeball.PokeBall; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.EmptyPokeBallEntity; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.PokeBallEntity; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.UUID; | ||
|
||
@SuppressWarnings("UnusedMixin") | ||
@Mixin(value = EmptyPokeBallEntity.class, remap = false) | ||
public abstract class EmptyPokeBallEntityMixin extends PokeBallEntity { | ||
public EmptyPokeBallEntityMixin(EntityType<? extends PokeBallEntity> type, Level world) { | ||
super(type, world); | ||
} | ||
|
||
@Redirect(method = "onHit", at = @At(value = "INVOKE", | ||
target = "Lcom/pixelmonmod/pixelmon/api/pokemon/item/pokeball/PokeBall;getBallItem()Lnet/minecraft/world/item/ItemStack;"), | ||
remap = true) | ||
public ItemStack neoMixins$redirectBallItemOnHit(PokeBall instance) { | ||
ItemStack item = this.getItemFromNBT(); | ||
if(!item.isEmpty()) return item; | ||
return instance.getBallItem(); | ||
} | ||
|
||
@Redirect(method = "catchPokemon", at = @At(value = "INVOKE", | ||
target = "Lcom/pixelmonmod/pixelmon/api/pokemon/item/pokeball/PokeBall;getBallItem()Lnet/minecraft/world/item/ItemStack;")) | ||
public ItemStack neoMixins$redirectBallItemOnCatch(PokeBall instance) { | ||
ItemStack item = this.getItemFromNBT(); | ||
if(!item.isEmpty()) return item; | ||
return instance.getBallItem(); | ||
} | ||
|
||
@Override | ||
public ItemStack[] getComponentItems() { | ||
CompoundTag itemNBT = this.getPersistentData().getCompound("item"); | ||
if (itemNBT.getCompound("tag").getBoolean("Unbreakable")) return new ItemStack[]{ItemStack.of(itemNBT)}; | ||
return super.getComponentItems(); | ||
} | ||
|
||
@Override | ||
public UUID getOwnerId() { | ||
return this.thrower.getUUID(); | ||
} | ||
|
||
@Unique | ||
public ItemStack getItemFromNBT() { | ||
CompoundTag itemNBT = this.getPersistentData().getCompound("item"); | ||
return ItemStack.of(itemNBT); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
forge120/src/main/java/me/neovitalism/pokeballdatastorage/mixins/PokeBallItemMixin.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,63 @@ | ||
package me.neovitalism.pokeballdatastorage.mixins; | ||
|
||
import com.pixelmonmod.pixelmon.api.events.ThrowPokeballEvent; | ||
import com.pixelmonmod.pixelmon.api.pokemon.item.pokeball.PokeBall; | ||
import com.pixelmonmod.pixelmon.battles.controller.participants.PixelmonWrapper; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.EmptyPokeBallEntity; | ||
import com.pixelmonmod.pixelmon.entities.pokeballs.PokeBallEntity; | ||
import com.pixelmonmod.pixelmon.items.PixelmonItem; | ||
import com.pixelmonmod.pixelmon.items.PokeBallItem; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import java.util.Optional; | ||
|
||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "UnusedMixin", "OptionalGetWithoutIsPresent"}) | ||
@Mixin(value = PokeBallItem.class, remap = false) | ||
public abstract class PokeBallItemMixin extends PixelmonItem { | ||
public PokeBallItemMixin(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Inject(method = "use", at = @At(value = "INVOKE", target = | ||
"Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT, remap = true, cancellable = true) | ||
public void neoMixins$use(Level world, Player entityPlayer, InteractionHand handIn, | ||
CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack itemStack, | ||
Optional<PokeBall> pokeBall) { | ||
EmptyPokeBallEntity entity = new EmptyPokeBallEntity(world, entityPlayer, pokeBall.get(), !entityPlayer.isCreative()); | ||
this.setBallInNBT(entity, itemStack); | ||
world.addFreshEntity(entity); | ||
if (!entityPlayer.isCreative()) { | ||
itemStack.shrink(1); | ||
entityPlayer.getInventory().setChanged(); | ||
} | ||
cir.setReturnValue(new InteractionResultHolder<>(InteractionResult.SUCCESS, itemStack)); | ||
} | ||
|
||
@Inject(method = "useFromBag", at = @At(value = "INVOKE", target = | ||
"Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"), | ||
locals = LocalCapture.CAPTURE_FAILSOFT) | ||
public void neoMixins$useFromBag(PixelmonWrapper userWrapper, PixelmonWrapper targetWrapper, ItemStack stack, | ||
CallbackInfoReturnable<Boolean> cir, Player thrower, Optional<PokeBall> pokeBall, | ||
ThrowPokeballEvent throwPokeballEvent, Level world, PokeBallEntity p) { | ||
this.setBallInNBT((EmptyPokeBallEntity) p, stack); | ||
} | ||
|
||
@Unique | ||
private void setBallInNBT(EmptyPokeBallEntity entity, ItemStack ballItem) { | ||
ItemStack clonedItem = ballItem.copy(); | ||
clonedItem.setCount(1); | ||
entity.getPersistentData().put("item", clonedItem.serializeNBT()); | ||
} | ||
} |
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,5 +1,5 @@ | ||
mod_version = 1.0.0 | ||
mod_id = neomixins | ||
mod_name = NeoMixins | ||
mod_description = Mixins for use with Pixelmon | ||
github_page = https://github.com/Neovitalism/NeoMixins | ||
mod_id = pokeballdatastorage | ||
mod_name = PokeballDataStorage | ||
mod_description = Caches the pokeball thrown onto the EmptyPokeballEntity. | ||
github_page = https://github.com/Neovitalism/NeoMixins/tree/pokeball-data-storage |
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,4 +1,4 @@ | ||
rootProject.name = 'NeoMixins' | ||
rootProject.name = 'PokeballDataStorage' | ||
include 'forge116' | ||
include 'forge120' | ||
|