Skip to content

Commit

Permalink
Bugs fixed in some lines powers, ettmetal y spikes
Browse files Browse the repository at this point in the history
  • Loading branch information
rudahee committed Apr 12, 2023
1 parent da6a5ca commit 732b120
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public int getEnchantmentValue() {
}

@Override
public @NotNull Ingredient getRepairIngredient() {
return Ingredient.of(Blocks.AIR);
public Ingredient getRepairIngredient() {
return Ingredient.of(Blocks.CRYING_OBSIDIAN);
}
};

Expand Down Expand Up @@ -183,16 +183,16 @@ public CompoundTag generateTags(ItemStack stack) {
* @return boolean
*/
@Override
public boolean hurtEnemy(ItemStack stack, @NotNull LivingEntity target, @NotNull LivingEntity source) {
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity source) {

if (stack.hasTag()){
if (!stack.getTag().contains("metal_spike") || !stack.getTag().contains("feruchemic_power") || !stack.getTag().contains("allomantic_power")) {
stack.setTag(generateTags(stack));
}
if (!stack.getTag().contains("metal_spike")||!stack.getTag().contains("feruchemic_power") || !stack.getTag().contains("allomantic_power")) {
stack.setTag(generateTags(stack));
}


if ((target instanceof Player) && (source instanceof Player)){


target.getCapability(ModBlocksRegister.InvestedCapabilityRegister.PLAYER_CAP).ifPresent(targetData -> {

boolean hasAllomanticPower = targetData.hasAllomanticPower(MetalTagEnum.getMetal(stack.getTag().getInt("metal_spike")));
Expand All @@ -208,91 +208,79 @@ public boolean hurtEnemy(ItemStack stack, @NotNull LivingEntity target, @NotNull
Level world = target.level;
BlockPos pos = new BlockPos(target.position());

if (stack.getTag().getBoolean("allomantic_power")) {
//DAR PODER
if (stack.getTag().getBoolean("allomantic_power")){
if (!targetData.hasAllomanticPower(localMetal)){
targetData.addAllomanticPower(localMetal);
doEffects(world, pos);
source.setItemInHand(source.getUsedItemHand(), ItemStack.EMPTY);
}
} else if (stack.getTag().getBoolean("feruchemic_power")) {
} else if (stack.getTag().getBoolean("feruchemic_power")){
if (!targetData.hasFeruchemicPower(localMetal)){
targetData.addFeruchemicPower(localMetal);
doEffects(world, pos);
source.setItemInHand(source.getUsedItemHand(), ItemStack.EMPTY);
}

//SI EL CLAVO NO TIENE PODERES -> intenta robar
} else if (hasPlayerBothPowers(localMetal, targetData)) {
//SI EL OBJETIVO TIENE AMBOS PODERES
if (isAllomantic) {
if (couldStealPower){
if (couldRemovePower){
if (Math.random()>0.50){
if (Math.random()<0.75){
targetData.removeAllomanticPower(localMetal);

target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, true, true, false));

target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, true, true, false));

}
stack.getTag().putBoolean("allomantic_power",true);
addItemToPlayer((Player) source, stack);
}
} else {
if (couldStealPower) {
if (couldRemovePower) {
if (Math.random()>0.50){
if (Math.random()<0.75){
targetData.removeFeruchemicPower(localMetal);

target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, true, true, false));

target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, true, true, false));

}
stack.getTag().putBoolean("feruchemic_power",true);
addItemToPlayer((Player) source, stack);
}
}
} else if (hasAllomanticPower) {
if (couldStealPower){
if (couldRemovePower){
} else if (hasAllomanticPower){
if (Math.random()>0.50){
if (Math.random()<0.75){
targetData.removeAllomanticPower(localMetal);

target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, true, true, false));

target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, true, true, false));

}
stack.getTag().putBoolean("allomantic_power",true);
addItemToPlayer((Player) source, stack);
}
} else if (hasFeruchemicPower){
if (couldStealPower){
if (couldRemovePower) {
if (Math.random()>0.50){
if (Math.random()<0.75) {


targetData.removeFeruchemicPower(localMetal);
target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, false, false));
target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, false, false));

target.addEffect(new MobEffectInstance(MobEffects.GLOWING, 40, 1, true, true, false));

target.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1, true, true, false));

}
stack.getTag().putBoolean("feruchemic_power",true);
addItemToPlayer((Player) source, stack);
}
}
ModNetwork.syncInvestedDataPacket(targetData,(Player) target);
ModNetwork.sync(targetData,(Player) target);
});



} else if ((target instanceof Witch) && (source instanceof Player)) {
if (!stack.getTag().getBoolean("allomantic_power") && !stack.getTag().getBoolean("feruchemic_power")) {
if (Math.random()<0.1){
stack.getTag().putBoolean("allomantic_power",true);
addItemToPlayer((Player) source, stack);
target.kill();
}
}
} else if ((target instanceof Evoker) && (source instanceof Player)) {
if (!stack.getTag().getBoolean("allomantic_power") && !stack.getTag().getBoolean("feruchemic_power")) {
if (Math.random()<0.1){
target.kill();
stack.getTag().putBoolean("feruchemic_power",true);
addItemToPlayer((Player) source, stack);
}
}
}
return super.hurtEnemy(stack, target, source);
}
Expand All @@ -312,64 +300,6 @@ private void doEffects(Level level, BlockPos pos) {
level.addFreshEntity(lightning);
}

/**
* This method define the behaviour when spike is used.
*
* @param level of the player when use it.
* @param player that use the spike.
* @param hand that have the spike.
*
* @return InteractionResultHolder<ItemStack>
*/
@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
if (!itemStack.getTag().contains("metal_spike") || !itemStack.getTag().contains("feruchemic_power") || !itemStack.getTag().contains("allomantic_power")) {
return new InteractionResultHolder<>(InteractionResult.FAIL, itemStack);
} else if (itemStack.getTag().getBoolean("allomantic_power") || itemStack.getTag().getBoolean("feruchemic_power")) {
player.startUsingItem(hand);
try {
IInvestedPlayerData capabilities = CapabilityUtils.getCapability(player);
if (itemStack.getTag().getBoolean("allomantic_power")) {
capabilities.addAllomanticPower(this.metalSpike);
} else if (!itemStack.getTag().getBoolean("feruchemic_power")) {
capabilities.addFeruchemicPower(this.metalSpike);
}
} catch (PlayerException ex) {
ex.printResumeLog();
}
doEffects(level, player.getOnPos());
player.getInventory().removeItem(itemStack);
return new InteractionResultHolder<>(InteractionResult.CONSUME, itemStack);
}
return new InteractionResultHolder<>(InteractionResult.FAIL, itemStack);
}

/**
* This method define the behaviour when using is finished. but we don't do anything special, only call super().
*
* @param stack specific item.
* @param level of the player.
* @param livingEntity tht use the spike.
* @param status of the using.
*/
@Override
public void releaseUsing(@NotNull ItemStack stack, @NotNull Level level, @NotNull LivingEntity livingEntity, int status) {
super.releaseUsing(stack, level, livingEntity, status);
}

/**
* This method define the animation when the player use the spike. Always be BOW animation.
*
* @param stack of the animation.
*
* @return UseAnim
*/
@Override
public @NotNull UseAnim getUseAnimation(@NotNull ItemStack stack) {
return UseAnim.BOW;
}

/**
* Add an item to the player if the power is given.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.rudahee.metallics_arts.modules.logic.server.powers.feruchemy.god_metals;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Explosion;
import net.rudahee.metallics_arts.data.enums.implementations.MetalTagEnum;
import net.rudahee.metallics_arts.data.player.IInvestedPlayerData;
import net.rudahee.metallics_arts.modules.logic.server.powers.feruchemy.AbstractFechuchemicHelper;
import net.rudahee.metallics_arts.modules.effects.ModEffects;

Expand All @@ -23,7 +26,6 @@ public class EttmetalFecuchemicHelper extends AbstractFechuchemicHelper {
*/
@Override
public void tapPower(Player player) {
ModEffects.giveFeruchemicalTapEffect(player, MetalTagEnum.ETTMETAL);
}

/**
Expand All @@ -34,7 +36,6 @@ public void tapPower(Player player) {
*/
@Override
public void storagePower(Player player) {
ModEffects.giveFeruchemicalStorageEffect(player,MetalTagEnum.ETTMETAL);
}

/**
Expand All @@ -51,13 +52,13 @@ public void storagePower(Player player) {
*
* @see AbstractFechuchemicHelper#tapPower(Player)
*/
/*@Override
@Override
public CompoundTag calculateDischarge(CompoundTag compoundTag, Player player, IInvestedPlayerData playerCapability, int metalReserve, String metalKey, boolean nicConsume) {
player.level.explode(player,player.position().x,player.position().y,player.position().z,(float) compoundTag.getInt(metalKey)/683, Explosion.BlockInteraction.NONE);
player.setHealth((player.getHealth() - ((float) compoundTag.getInt(metalKey)/205)));
compoundTag.putInt(metalKey,0);
return compoundTag;
}*/
}

/**
* Implementation of the abstract method of the AbstractFechuchemicHelper class.
Expand All @@ -73,15 +74,15 @@ public CompoundTag calculateDischarge(CompoundTag compoundTag, Player player, II
*
* @see AbstractFechuchemicHelper#storagePower(Player)
*/
/*@Override
@Override
public CompoundTag calculateCharge(CompoundTag compoundTag, Player player, IInvestedPlayerData playerCapability, int metalReserve, String metalKey, boolean nicConsume) {
if (player.getLastDamageSource() != null){
if ((player.getLastDamageSource().isExplosion())){
compoundTag.putInt(metalKey, metalReserve + 1);
}
}
return compoundTag;
}*/
}

/**
* Returns an instance of EttmetalFecuchemicHelper using a factory method pattern.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.rudahee.metallics_arts.modules.logic.server.server_events.on_world_tick;

import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level;
import net.rudahee.metallics_arts.data.enums.implementations.MetalTagEnum;
import net.rudahee.metallics_arts.data.player.IInvestedPlayerData;
import net.rudahee.metallics_arts.modules.logic.server.powers.allomancy.god_metals.EttmetalAllomanticHelper;
Expand All @@ -21,8 +25,6 @@
import net.rudahee.metallics_arts.modules.effects.ModEffects;
import net.rudahee.metallics_arts.setup.network.ModNetwork;

import java.util.logging.Level;

/**
* Handles the effects and abilities related to Allomantic metals for players.
*
Expand Down Expand Up @@ -53,9 +55,10 @@ public static void each3Ticks(IInvestedPlayerData playerCapability, ServerPlayer
temporalMetals(playerCapability, player, level);
}
if (MalatiumAllomanticHelper.isPosRegistered() && !playerCapability.isBurning(MetalTagEnum.MALATIUM)) {
MalatiumAllomanticHelper.setPos(null, null);
MalatiumAllomanticHelper.setPosRegistered(false);
ModNetwork.syncAnotherPlayerDeathPos(null, player);
MalatiumAllomanticHelper.setPos(null, null);
GlobalPos gPos = GlobalPos.of(Level.OVERWORLD, new BlockPos(level.getLevelData().getXSpawn(), level.getLevelData().getYSpawn(), level.getLevelData().getZSpawn()));
ModNetwork.syncAnotherPlayerDeathPos(gPos, player);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package net.rudahee.metallics_arts.setup.network.packets;

import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkEvent;
import net.rudahee.metallics_arts.modules.logic.client.client_events.OnRenderLevelStage;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.awt.*;
import java.util.UUID;
import java.util.function.Supplier;

public class AnotherPlayerDeathPosPacket {

private final UUID uuid;
private final GlobalPos pos;
private GlobalPos pos;

/**
* Default constructor that receive all mandatory data.
*
* @param player to synchronize pos.
* @param pos to synchronize.
*/
public AnotherPlayerDeathPosPacket(Player player, GlobalPos pos) {
public AnotherPlayerDeathPosPacket(Player player, @NonNull GlobalPos pos) {
this.uuid = player.getUUID();
this.pos = pos;
}
Expand All @@ -32,7 +36,7 @@ public AnotherPlayerDeathPosPacket(Player player, GlobalPos pos) {
* @param uuid of the player to synchronize pos.
* @param pos to synchronize.
*/
private AnotherPlayerDeathPosPacket(UUID uuid, GlobalPos pos) {
private AnotherPlayerDeathPosPacket(UUID uuid, @NonNull GlobalPos pos) {
this.uuid = uuid;
this.pos = pos;
}
Expand All @@ -45,7 +49,12 @@ private AnotherPlayerDeathPosPacket(UUID uuid, GlobalPos pos) {
* @return RespawnPositionPacket
*/
public static AnotherPlayerDeathPosPacket decode(FriendlyByteBuf buf) {
return new AnotherPlayerDeathPosPacket(buf.readUUID(), buf.readGlobalPos());
UUID uuidLocal = buf.readUUID();
GlobalPos posLocal = buf.readGlobalPos();
if (posLocal == null) {
posLocal = GlobalPos.of(Level.OVERWORLD, new BlockPos(Minecraft.getInstance().level.getLevelData().getXSpawn(), Minecraft.getInstance().level.getLevelData().getYSpawn(), Minecraft.getInstance().level.getLevelData().getZSpawn()));
}
return new AnotherPlayerDeathPosPacket(uuidLocal, posLocal);
}

/**
Expand All @@ -65,7 +74,7 @@ public void encode(FriendlyByteBuf buf) {
*/
public void handle(Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
OnRenderLevelStage.setAnotherPlayerDeathPos(pos);
OnRenderLevelStage.setAnotherPlayerDeathPos(this.pos);
});
ctx.get().setPacketHandled(true);
}
Expand Down

0 comments on commit 732b120

Please sign in to comment.