Deleted old code.
This commit is contained in:
@ -1,13 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.events;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import net.minecraftforge.event.TickEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
|
||||||
|
|
||||||
public class ServerTickEventHandler {
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onServerTick(TickEvent.ServerTickEvent event) {
|
|
||||||
TotemOfReviving.players = ServerLifecycleHooks.getCurrentServer().getPlayerList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.items;
|
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.Rarity;
|
|
||||||
|
|
||||||
public class RevivingChargeItem extends Item {
|
|
||||||
public RevivingChargeItem() {
|
|
||||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).rarity(Rarity.RARE));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.items;
|
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.Rarity;
|
|
||||||
|
|
||||||
public class StrawChargeItem extends Item {
|
|
||||||
public StrawChargeItem() {
|
|
||||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).rarity(Rarity.UNCOMMON));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.items;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestTotemCharge;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestTotemTarget;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.client.util.InputMappings;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Rarity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class StrawTotemItem extends Item {
|
|
||||||
public static final String TAG_CHARGE_AMOUNT = "charge";
|
|
||||||
public static final String TAG_TARGET_INDEX = "target_index";
|
|
||||||
public static final String TAG_TARGET_NAME = "target_name";
|
|
||||||
public static final String TAG_FAIL_CHANCE = "fail_chance";
|
|
||||||
public static final int STARTING_FAIL_CHANCE = 45;
|
|
||||||
|
|
||||||
public StrawTotemItem() {
|
|
||||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).stacksTo(1).rarity(Rarity.UNCOMMON));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendHoverText(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
|
||||||
super.appendHoverText(stack, world, tooltip, flag);
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "Charges: " + TextFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT)));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "Target: " + TextFormatting.GRAY + stack.getOrCreateTag().getString(TAG_TARGET_NAME)));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "Fail Chance: " + TextFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_FAIL_CHANCE)));
|
|
||||||
tooltip.add(new StringTextComponent( TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + "\"Feels kinda funky.\""));
|
|
||||||
tooltip.add(new StringTextComponent(""));
|
|
||||||
if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT)) {
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.YELLOW + "R-CLICK"));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "When other hand is empty: attempt to revive target."));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "When other hand has " + TextFormatting.GRAY + "Straw Reviving Charge" + TextFormatting.GOLD + ": charge totem."));
|
|
||||||
tooltip.add(new StringTextComponent(""));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.YELLOW + "SHIFT R-CLICK"));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GOLD + "Cycle through available targets."));
|
|
||||||
} else {
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GRAY + "[" + TextFormatting.WHITE + "LSHIFT" + TextFormatting.GRAY + "] for advanced tooltip."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCraftedBy(ItemStack stack, World world, PlayerEntity player) {
|
|
||||||
super.onCraftedBy(stack, world, player);
|
|
||||||
stack.getOrCreateTag().putInt(TAG_CHARGE_AMOUNT, 0);
|
|
||||||
stack.getOrCreateTag().putInt(TAG_FAIL_CHANCE, STARTING_FAIL_CHANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
|
||||||
if (world.isClientSide) { return super.use(world, player, hand); }
|
|
||||||
if (player.isCrouching()) {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUUID(), hand));
|
|
||||||
} else {
|
|
||||||
Hand item_charge_hand = Hand.MAIN_HAND;
|
|
||||||
if (hand.equals(Hand.MAIN_HAND)) {
|
|
||||||
item_charge_hand = Hand.OFF_HAND;
|
|
||||||
}
|
|
||||||
Item item_charge = player.getItemInHand(item_charge_hand).getItem();
|
|
||||||
|
|
||||||
if (item_charge instanceof StrawChargeItem) {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUUID(), hand, item_charge_hand));
|
|
||||||
} else {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUUID(), hand));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.use(world, player, hand);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.items;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestTotemCharge;
|
|
||||||
import dev.micle.totemofreviving.network.C2SRequestTotemTarget;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
|
||||||
import net.minecraft.client.util.InputMappings;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import net.minecraft.item.Rarity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TotemOfRevivingItem extends Item {
|
|
||||||
public static final String TAG_CHARGE_AMOUNT = "charge";
|
|
||||||
public static final String TAG_TARGET_INDEX = "target_index";
|
|
||||||
public static final String TAG_TARGET_NAME = "target_name";
|
|
||||||
|
|
||||||
public TotemOfRevivingItem() {
|
|
||||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).stacksTo(1).rarity(Rarity.RARE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendHoverText(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
|
||||||
super.appendHoverText(stack, world, tooltip, flag);
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.DARK_AQUA + "Charges: " + TextFormatting.BLUE + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT)));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.DARK_AQUA + "Target: " + TextFormatting.BLUE + stack.getOrCreateTag().getString(TAG_TARGET_NAME)));
|
|
||||||
tooltip.add(new StringTextComponent(""));
|
|
||||||
if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT)) {
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.AQUA + "R-CLICK"));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.DARK_AQUA + "When other hand is empty: attempt to revive target."));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.DARK_AQUA + "When other hand has " + TextFormatting.BLUE + "Reviving Charge" + TextFormatting.DARK_AQUA + ": charge totem."));
|
|
||||||
tooltip.add(new StringTextComponent(""));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.AQUA + "SHIFT R-CLICK"));
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.DARK_AQUA + "Cycle through available targets."));
|
|
||||||
} else {
|
|
||||||
tooltip.add(new StringTextComponent(TextFormatting.GRAY + "[" + TextFormatting.WHITE + "LSHIFT" + TextFormatting.GRAY + "] for advanced tooltip."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCraftedBy(ItemStack stack, World world, PlayerEntity player) {
|
|
||||||
super.onCraftedBy(stack, world, player);
|
|
||||||
stack.getOrCreateTag().putInt(TAG_CHARGE_AMOUNT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
|
||||||
if (world.isClientSide) { return super.use(world, player, hand); }
|
|
||||||
if (player.isCrouching()) {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUUID(), hand));
|
|
||||||
} else {
|
|
||||||
Hand item_charge_hand = Hand.MAIN_HAND;
|
|
||||||
if (hand.equals(Hand.MAIN_HAND)) {
|
|
||||||
item_charge_hand = Hand.OFF_HAND;
|
|
||||||
}
|
|
||||||
Item item_charge = player.getItemInHand(item_charge_hand).getItem();
|
|
||||||
|
|
||||||
if (item_charge instanceof RevivingChargeItem) {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUUID(), hand, item_charge_hand));
|
|
||||||
} else {
|
|
||||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUUID(), hand));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.use(world, player, hand);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.network;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import dev.micle.totemofreviving.items.StrawTotemItem;
|
|
||||||
import dev.micle.totemofreviving.items.TotemOfRevivingItem;
|
|
||||||
import dev.micle.totemofreviving.utils.Utils;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.potion.EffectInstance;
|
|
||||||
import net.minecraft.potion.Effects;
|
|
||||||
import net.minecraft.stats.Stats;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.GameType;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class C2SRequestPlayerRevive {
|
|
||||||
private final UUID player_uuid;
|
|
||||||
private final Hand hand;
|
|
||||||
|
|
||||||
public C2SRequestPlayerRevive(final UUID player_uuid, final Hand hand) {
|
|
||||||
this.player_uuid = player_uuid;
|
|
||||||
this.hand = hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void encode(final C2SRequestPlayerRevive msg, final PacketBuffer packet_buffer) {
|
|
||||||
packet_buffer.writeUUID(msg.player_uuid);
|
|
||||||
packet_buffer.writeEnum(msg.hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static C2SRequestPlayerRevive decode(final PacketBuffer packet_buffer) {
|
|
||||||
return new C2SRequestPlayerRevive(packet_buffer.readUUID(), packet_buffer.readEnum(Hand.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handle(final C2SRequestPlayerRevive msg, final Supplier<NetworkEvent.Context> context_supplier) {
|
|
||||||
final NetworkEvent.Context context = context_supplier.get();
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayer(msg.player_uuid);
|
|
||||||
if (sender == null) { return; }
|
|
||||||
|
|
||||||
ItemStack item = sender.getItemInHand(msg.hand);
|
|
||||||
if (item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_TARGET_INDEX) > TotemOfReviving.players.getPlayerCount()-1 || item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME).equals("")) {
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.RED + "Error getting target! (Try selecting the target again)"), sender.getUUID());
|
|
||||||
} else {
|
|
||||||
ServerPlayerEntity player_to_revive = TotemOfReviving.players.getPlayerByName(item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME));
|
|
||||||
ServerWorld player_to_revive_world = player_to_revive.getLevel();
|
|
||||||
ServerWorld sender_world = sender.getLevel();
|
|
||||||
int required_charge = player_to_revive.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS));
|
|
||||||
if (player_to_revive.isSpectator()) {
|
|
||||||
if (player_to_revive_world.equals(sender_world)) {
|
|
||||||
if (item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_CHARGE_AMOUNT) >= required_charge) {
|
|
||||||
if (item.getOrCreateTag().contains(StrawTotemItem.TAG_FAIL_CHANCE)) {
|
|
||||||
int fail_chance = item.getOrCreateTag().getInt(StrawTotemItem.TAG_FAIL_CHANCE);
|
|
||||||
if (Utils.randomIntRange(0, 100) <= fail_chance) {
|
|
||||||
item.getOrCreateTag().putInt(StrawTotemItem.TAG_CHARGE_AMOUNT, item.getOrCreateTag().getInt(StrawTotemItem.TAG_CHARGE_AMOUNT)-required_charge);
|
|
||||||
item.getOrCreateTag().putInt(StrawTotemItem.TAG_FAIL_CHANCE, fail_chance-(5*required_charge));
|
|
||||||
sender.addEffect(new EffectInstance(Effects.POISON, ((fail_chance*10) / 2), 1));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
item.getOrCreateTag().putInt(StrawTotemItem.TAG_FAIL_CHANCE, fail_chance-(5*required_charge));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player_to_revive.moveTo(sender.getX(), sender.getY(), sender.getZ());
|
|
||||||
player_to_revive.setGameMode(GameType.SURVIVAL);
|
|
||||||
item.getOrCreateTag().putInt(TotemOfRevivingItem.TAG_CHARGE_AMOUNT, item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_CHARGE_AMOUNT) - required_charge);
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Successfully revived " + TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString()), sender.getUUID());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Not enough charge! Required charge is: " + TextFormatting.DARK_GRAY + required_charge), sender.getUUID());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not in this dimension!"), sender.getUUID());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not dead!"), sender.getUUID());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.network;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import dev.micle.totemofreviving.items.StrawTotemItem;
|
|
||||||
import dev.micle.totemofreviving.items.TotemOfRevivingItem;
|
|
||||||
import dev.micle.totemofreviving.utils.Utils;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.potion.EffectInstance;
|
|
||||||
import net.minecraft.potion.Effects;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class C2SRequestTotemCharge {
|
|
||||||
private final UUID player_uuid;
|
|
||||||
private final Hand hand;
|
|
||||||
private final Hand item_charge_hand;
|
|
||||||
|
|
||||||
public C2SRequestTotemCharge(final UUID player_uuid, final Hand hand, final Hand item_charge_hand) {
|
|
||||||
this.player_uuid = player_uuid;
|
|
||||||
this.hand = hand;
|
|
||||||
this.item_charge_hand = item_charge_hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void encode(final C2SRequestTotemCharge msg, final PacketBuffer packet_buffer) {
|
|
||||||
packet_buffer.writeUUID(msg.player_uuid);
|
|
||||||
packet_buffer.writeEnum(msg.hand);
|
|
||||||
packet_buffer.writeEnum(msg.item_charge_hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static C2SRequestTotemCharge decode(final PacketBuffer packet_buffer) {
|
|
||||||
return new C2SRequestTotemCharge(packet_buffer.readUUID(), packet_buffer.readEnum(Hand.class), packet_buffer.readEnum(Hand.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handle(final C2SRequestTotemCharge msg, final Supplier<NetworkEvent.Context> context_supplier) {
|
|
||||||
final NetworkEvent.Context context = context_supplier.get();
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayer(msg.player_uuid);
|
|
||||||
if (sender == null) { return; }
|
|
||||||
|
|
||||||
ItemStack charge_item = sender.getItemInHand(msg.item_charge_hand);
|
|
||||||
ItemStack totem_item = sender.getItemInHand(msg.hand);
|
|
||||||
charge_item.setCount(charge_item.getCount()-1);
|
|
||||||
totem_item.getOrCreateTag().putInt(TotemOfRevivingItem.TAG_CHARGE_AMOUNT, totem_item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_CHARGE_AMOUNT)+1);
|
|
||||||
|
|
||||||
if (totem_item.getOrCreateTag().contains(StrawTotemItem.TAG_FAIL_CHANCE)) {
|
|
||||||
int fail_chance = totem_item.getOrCreateTag().getInt(StrawTotemItem.TAG_FAIL_CHANCE);
|
|
||||||
if (Utils.randomIntRange(0, 100) <= fail_chance) {
|
|
||||||
sender.setItemInHand(msg.hand, new ItemStack(Items.AIR));
|
|
||||||
sender.addEffect(new EffectInstance(Effects.POISON, ((fail_chance*10) / 2), 1));
|
|
||||||
} else {
|
|
||||||
totem_item.getOrCreateTag().putInt(StrawTotemItem.TAG_FAIL_CHANCE, fail_chance+5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.network;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import dev.micle.totemofreviving.items.TotemOfRevivingItem;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class C2SRequestTotemTarget {
|
|
||||||
private final UUID player_uuid;
|
|
||||||
private final Hand hand;
|
|
||||||
|
|
||||||
public C2SRequestTotemTarget(final UUID player_uuid, final Hand hand) {
|
|
||||||
this.player_uuid = player_uuid;
|
|
||||||
this.hand = hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void encode(final C2SRequestTotemTarget msg, final PacketBuffer packet_buffer) {
|
|
||||||
packet_buffer.writeUUID(msg.player_uuid);
|
|
||||||
packet_buffer.writeEnum(msg.hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static C2SRequestTotemTarget decode(final PacketBuffer packet_buffer) {
|
|
||||||
return new C2SRequestTotemTarget(packet_buffer.readUUID(), packet_buffer.readEnum(Hand.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handle(final C2SRequestTotemTarget msg, final Supplier<NetworkEvent.Context> context_supplier) {
|
|
||||||
final NetworkEvent.Context context = context_supplier.get();
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayer(msg.player_uuid);
|
|
||||||
if (sender == null) { return; }
|
|
||||||
|
|
||||||
ItemStack item = sender.getItemInHand(msg.hand);
|
|
||||||
int current_player_index = item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_TARGET_INDEX) + 1;
|
|
||||||
if (current_player_index > TotemOfReviving.players.getPlayerCount()-1) {
|
|
||||||
current_player_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.getOrCreateTag().putInt(TotemOfRevivingItem.TAG_TARGET_INDEX, current_player_index);
|
|
||||||
item.getOrCreateTag().putString(TotemOfRevivingItem.TAG_TARGET_NAME, TotemOfReviving.players.getPlayers().get(current_player_index).getDisplayName().getString());
|
|
||||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Target: " + TextFormatting.DARK_GRAY + item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME)), sender.getUUID());
|
|
||||||
});
|
|
||||||
context.setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.network;
|
|
||||||
|
|
||||||
import dev.micle.totemofreviving.TotemOfReviving;
|
|
||||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
|
||||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public final class Network {
|
|
||||||
public static final String VERSION = TotemOfReviving.MOD_ID + "-net-1";
|
|
||||||
|
|
||||||
public static SimpleChannel channel;
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
channel = NetworkRegistry.ChannelBuilder.named(TotemOfReviving.createResourceLocation("network"))
|
|
||||||
.clientAcceptedVersions(s -> Objects.equals(s, VERSION))
|
|
||||||
.serverAcceptedVersions(s -> Objects.equals(s, VERSION))
|
|
||||||
.networkProtocolVersion(() -> VERSION)
|
|
||||||
.simpleChannel();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package dev.micle.totemofreviving.utils;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
public static float clamp(float val, float min, float max) {
|
|
||||||
return Math.max(min, Math.min(max, val));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int randomIntRange(int min, int max) {
|
|
||||||
return (int) randomDoubleRange(min, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float randomFloatRange(float min, float max) {
|
|
||||||
return (float) randomDoubleRange(min, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double randomDoubleRange(double min, double max) {
|
|
||||||
return ((Math.random() * (max - min)) + min);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user