Skip to content

Commit

Permalink
Fixes some usable effects not working
Browse files Browse the repository at this point in the history
# Fixes:

-  nature items should work now
-  z-moves should have crit chance 0 now
-  gigant shard works
  • Loading branch information
Thutmose committed Jul 1, 2020
1 parent d54ebf1 commit 3e438b4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 42 deletions.
19 changes: 10 additions & 9 deletions src/main/java/pokecube/legends/PokecubeLegends.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import pokecube.legends.init.Config;
import pokecube.legends.init.ItemInit;
import pokecube.legends.init.PokecubeDim;
import pokecube.legends.init.function.UsableItemGigantShard;
import pokecube.legends.init.function.UsableItemNatureEffects;
import pokecube.legends.init.function.UsableItemZMoveEffects;
import pokecube.legends.proxy.ClientProxy;
Expand Down Expand Up @@ -82,13 +83,6 @@ public static void registerTiles(final RegistryEvent.Register<TileEntityType<?>>
event.getRegistry().register(RaidSpawn.TYPE.setRegistryName(BlockInit.RAID_SPAWN.get().getRegistryName()));
}

@SubscribeEvent
public static void onItemCapabilityAttach(final AttachCapabilitiesEvent<ItemStack> event)
{
UsableItemNatureEffects.registerCapabilities(event);
UsableItemZMoveEffects.registerCapabilities(event);
}

@SubscribeEvent
public static void registerFeatures(final RegistryEvent.Register<Feature<?>> event)
{
Expand Down Expand Up @@ -138,8 +132,7 @@ public static void registerModDimensions(final RegistryEvent.Register<ModDimensi
}
}

public static CommonProxy proxy = DistExecutor.safeRunForDist(
() -> ClientProxy::new, () -> CommonProxy::new);
public static CommonProxy proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);

public static final Config config = new Config();

Expand Down Expand Up @@ -170,6 +163,14 @@ public PokecubeLegends()
ItemInit.init();
}

@SubscribeEvent
public void onItemCapabilityAttach(final AttachCapabilitiesEvent<ItemStack> event)
{
UsableItemNatureEffects.registerCapabilities(event);
UsableItemZMoveEffects.registerCapabilities(event);
UsableItemGigantShard.registerCapabilities(event);
}

@SubscribeEvent
public void registerDatabases(final InitDatabase.Pre evt)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package pokecube.legends.init.function;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import pokecube.core.database.Database;
import pokecube.core.database.PokedexEntry;
import pokecube.core.interfaces.IPokemob;
import pokecube.core.interfaces.pokemob.ai.CombatStates;
import pokecube.core.items.UsableItemEffects.BaseUseable;
import pokecube.legends.Reference;
import pokecube.legends.init.ItemInit;

public class UsableItemGigantShard
{
public static class GigantShardUsable extends BaseUseable
{
/**
* Called when this item is "used". Normally this means via right
* clicking the pokemob with the itemstack. It can also be called via
* onTick or onMoveTick, in which case user will be pokemob.getEntity()
*
* @param user
* @param pokemob
* @param stack
* @return something happened
*/
@Override
public ActionResult<ItemStack> onUse(final IPokemob pokemob, final ItemStack stack, final LivingEntity user)
{
System.out.println(user + " " + pokemob.getOwner());
if (user != pokemob.getOwner()) return new ActionResult<>(ActionResultType.FAIL, stack);
boolean gigant = pokemob.getCombatState(CombatStates.GIGANTAMAX);
// Already able to gigantamax, no effect.
if (gigant) return super.onUse(pokemob, stack, user);
final PokedexEntry entry = pokemob.getPokedexEntry();
gigant = Database.getEntry(entry.getTrimmedName() + "_gigantamax") != null;
// No gigantamax form for this pokemob, no effect.
if (!gigant) return super.onUse(pokemob, stack, user);
pokemob.setCombatState(CombatStates.GIGANTAMAX, true);
stack.split(1);
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
}

public static final ResourceLocation USABLE = new ResourceLocation(Reference.ID, "usables");

public static void registerCapabilities(final AttachCapabilitiesEvent<ItemStack> event)
{
if (event.getCapabilities().containsKey(UsableItemGigantShard.USABLE)) return;
final Item item = event.getObject().getItem();
if (item == ItemInit.GIGANTIC_SHARD.get()) event.addCapability(UsableItemGigantShard.USABLE,
new GigantShardUsable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public ActionResult<ItemStack> onUse(final IPokemob pokemob, final ItemStack sta

public static final ResourceLocation USABLE = new ResourceLocation(Reference.ID, "usables");

/** 1.12 this needs to be ItemStack instead of item. */
public static void registerCapabilities(final AttachCapabilitiesEvent<ItemStack> event)
{
if (event.getCapabilities().containsKey(UsableItemNatureEffects.USABLE)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package pokecube.legends.init.function;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import pokecube.core.PokecubeItems;
import pokecube.core.interfaces.IPokemob;
import pokecube.core.interfaces.pokemob.moves.MovePacket;
import pokecube.core.items.UsableItemEffects.BaseUseable;
Expand All @@ -18,38 +15,17 @@ public class UsableItemZMoveEffects
{
public static class ZMoveUsable extends BaseUseable
{
/**
* Called when this item is "used". Normally this means via right
* clicking the pokemob with the itemstack. It can also be called via
* onTick or onMoveTick, in which case user will be pokemob.getEntity()
*
* @param user
* @param pokemob
* @param stack
* @return something happened
*/

@SuppressWarnings("null")
@Override
public ActionResult<ItemStack> onUse(final IPokemob pokemob, final ItemStack stack, final LivingEntity user)
public ActionResult<ItemStack> onMoveTick(final IPokemob attacker, final ItemStack stack,
final MovePacket moveuse)
{
if (user != pokemob.getEntity() && user != pokemob.getOwner()) return new ActionResult<>(
ActionResultType.FAIL, stack);
final MovePacket moveUse = null;
final boolean used = true;
if (used)
{
moveUse.didCrit = true;
PokecubeItems.deValidate(stack);
}
stack.setTag(null);
return new ActionResult<>(used ? ActionResultType.SUCCESS : ActionResultType.FAIL, stack);
if (moveuse.pre && stack == attacker.getHeldItem()) moveuse.criticalLevel = 0;
return super.onMoveTick(attacker, stack, moveuse);
}
}

public static final ResourceLocation USABLE = new ResourceLocation(Reference.ID, "usables");

/** 1.12 this needs to be ItemStack instead of item. */
public static void registerCapabilities(final AttachCapabilitiesEvent<ItemStack> event)
{
if (event.getCapabilities().containsKey(UsableItemZMoveEffects.USABLE)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ItemNature extends Item
{
public static boolean isNature(final ItemStack stackIn)
{
return stackIn != null && stackIn.getItem() instanceof ItemNature;
return stackIn.getItem() instanceof ItemNature;
}

public final Nature type;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/pokecube_legends/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"": "/Tools",
"item.pokecube_legends.rainbow_sword": "Rainbow Sword",
"item.pokecube_legends.wishing_piece": "Wishing Piece",
"item.pokecube_legends.gigantic_shard": "Gigant Shard (WIP)",
"item.pokecube_legends.gigantic_shard": "Gigant Shard",

"": "/Blocks",
"block.pokecube_legends.regirock_spawn": "Regirock Core",
Expand Down Expand Up @@ -217,6 +217,6 @@
"legends.zygardecube.tooltip": "Use this item in 'Zygarde' to change it.",
"legends.gigantic_shard.tooltip": "Use to make your pokemon use Gigantamax!",
"legends.wishing_piece.tooltip": "Use this item on an inactive raid spot to activate it!",
"legends.pdark.tooltip": "Use this item to evolve Kubfu into Single Strike Style",
"legends.pwater.tooltip": "Use this item to evolve Kubfu into Rapid Strike Style"
"legends.pdark.tooltip": "Use this item to evolve Kubfu into Single Strike Style",
"legends.pwater.tooltip": "Use this item to evolve Kubfu into Rapid Strike Style"
}

0 comments on commit 3e438b4

Please sign in to comment.