Changed groupId to dev.micle from com.micle. Updated code to match new MCP mappings.
This commit is contained in:
@ -1,53 +0,0 @@
|
||||
package com.micle.totemofreviving.data;
|
||||
|
||||
import com.micle.totemofreviving.setup.ModItems;
|
||||
import net.minecraft.data.*;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ModRecipeProvider extends RecipeProvider {
|
||||
public ModRecipeProvider(DataGenerator generator_in) {
|
||||
super(generator_in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
ShapedRecipeBuilder.shaped(ModItems.TOTEM_OF_REVIVING.get())
|
||||
.define('#', Items.TOTEM_OF_UNDYING)
|
||||
.define('@', Items.DIAMOND)
|
||||
.pattern("@@@")
|
||||
.pattern("@#@")
|
||||
.pattern("@@@")
|
||||
.unlockedBy("has_item", has(Items.TOTEM_OF_UNDYING))
|
||||
.save(consumer);
|
||||
ShapedRecipeBuilder.shaped(ModItems.REVIVING_CHARGE.get())
|
||||
.define('#', Items.TOTEM_OF_UNDYING)
|
||||
.define('@', Items.DIAMOND_BLOCK)
|
||||
.define('E', Items.ENDER_PEARL)
|
||||
.pattern("@E@")
|
||||
.pattern("E#E")
|
||||
.pattern("@E@")
|
||||
.unlockedBy("has_item", has(ModItems.TOTEM_OF_REVIVING.get()))
|
||||
.save(consumer);
|
||||
ShapedRecipeBuilder.shaped(ModItems.STRAW_TOTEM.get())
|
||||
.define('W', Items.WHEAT)
|
||||
.define('/', Items.STICK)
|
||||
.define('S', Items.STRING)
|
||||
.define('N', Items.IRON_NUGGET)
|
||||
.pattern("NSN")
|
||||
.pattern("NWN")
|
||||
.pattern("N/N")
|
||||
.unlockedBy("has_item", has(Items.WHEAT))
|
||||
.save(consumer);
|
||||
ShapedRecipeBuilder.shaped(ModItems.STRAW_CHARGE.get())
|
||||
.define('W', Items.WHEAT)
|
||||
.define('E', Items.EMERALD)
|
||||
.define('I', Items.IRON_INGOT)
|
||||
.pattern("IWI")
|
||||
.pattern("WEW")
|
||||
.pattern("IWI")
|
||||
.unlockedBy("has_item", has(Items.EMERALD))
|
||||
.save(consumer);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.micle.totemofreviving;
|
||||
package dev.micle.totemofreviving;
|
||||
|
||||
import com.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemCharge;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemTarget;
|
||||
import com.micle.totemofreviving.setup.Registration;
|
||||
import dev.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
||||
import dev.micle.totemofreviving.network.C2SRequestTotemCharge;
|
||||
import dev.micle.totemofreviving.network.C2SRequestTotemTarget;
|
||||
import dev.micle.totemofreviving.setup.Registration;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
@ -1,7 +1,7 @@
|
||||
package com.micle.totemofreviving.data;
|
||||
package dev.micle.totemofreviving.data;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.data.client.ModItemModelProvider;
|
||||
import dev.micle.totemofreviving.TotemOfReviving;
|
||||
import dev.micle.totemofreviving.data.client.ModItemModelProvider;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
53
src/main/java/dev/micle/totemofreviving/data/ModRecipeProvider.java
Executable file
53
src/main/java/dev/micle/totemofreviving/data/ModRecipeProvider.java
Executable file
@ -0,0 +1,53 @@
|
||||
package dev.micle.totemofreviving.data;
|
||||
|
||||
import dev.micle.totemofreviving.setup.ModItems;
|
||||
import net.minecraft.data.*;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ModRecipeProvider extends RecipeProvider {
|
||||
public ModRecipeProvider(DataGenerator generator_in) {
|
||||
super(generator_in);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
ShapedRecipeBuilder.shapedRecipe(ModItems.TOTEM_OF_REVIVING.get())
|
||||
.key('#', Items.TOTEM_OF_UNDYING)
|
||||
.key('@', Items.DIAMOND)
|
||||
.patternLine("@@@")
|
||||
.patternLine("@#@")
|
||||
.patternLine("@@@")
|
||||
.addCriterion("has_item", hasItem(Items.TOTEM_OF_UNDYING))
|
||||
.build(consumer);
|
||||
ShapedRecipeBuilder.shapedRecipe(ModItems.REVIVING_CHARGE.get())
|
||||
.key('#', Items.TOTEM_OF_UNDYING)
|
||||
.key('@', Items.DIAMOND_BLOCK)
|
||||
.key('E', Items.ENDER_PEARL)
|
||||
.patternLine("@E@")
|
||||
.patternLine("E#E")
|
||||
.patternLine("@E@")
|
||||
.addCriterion("has_item", hasItem(ModItems.TOTEM_OF_REVIVING.get()))
|
||||
.build(consumer);
|
||||
ShapedRecipeBuilder.shapedRecipe(ModItems.STRAW_TOTEM.get())
|
||||
.key('W', Items.WHEAT)
|
||||
.key('/', Items.STICK)
|
||||
.key('S', Items.STRING)
|
||||
.key('N', Items.IRON_NUGGET)
|
||||
.patternLine("NSN")
|
||||
.patternLine("NWN")
|
||||
.patternLine("N/N")
|
||||
.addCriterion("has_item", hasItem(Items.WHEAT))
|
||||
.build(consumer);
|
||||
ShapedRecipeBuilder.shapedRecipe(ModItems.STRAW_CHARGE.get())
|
||||
.key('W', Items.WHEAT)
|
||||
.key('E', Items.EMERALD)
|
||||
.key('I', Items.IRON_INGOT)
|
||||
.patternLine("IWI")
|
||||
.patternLine("WEW")
|
||||
.patternLine("IWI")
|
||||
.addCriterion("has_item", hasItem(Items.EMERALD))
|
||||
.build(consumer);
|
||||
}
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
package com.micle.totemofreviving.data.client;
|
||||
package dev.micle.totemofreviving.data.client;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import dev.micle.totemofreviving.TotemOfReviving;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.ItemModelBuilder;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ModItemModelProvider extends ItemModelProvider {
|
||||
public ModItemModelProvider(DataGenerator generator, ExistingFileHelper existing_file_helper) {
|
||||
super(generator, TotemOfReviving.MOD_ID, existing_file_helper);
|
@ -1,6 +1,6 @@
|
||||
package com.micle.totemofreviving.events;
|
||||
package dev.micle.totemofreviving.events;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import dev.micle.totemofreviving.TotemOfReviving;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
@ -1,4 +1,4 @@
|
||||
package com.micle.totemofreviving.items;
|
||||
package dev.micle.totemofreviving.items;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
@ -6,6 +6,6 @@ import net.minecraft.item.Rarity;
|
||||
|
||||
public class RevivingChargeItem extends Item {
|
||||
public RevivingChargeItem() {
|
||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).rarity(Rarity.RARE));
|
||||
super(new Item.Properties().group(ItemGroup.MISC).rarity(Rarity.RARE));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.micle.totemofreviving.items;
|
||||
package dev.micle.totemofreviving.items;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
@ -6,6 +6,6 @@ import net.minecraft.item.Rarity;
|
||||
|
||||
public class StrawChargeItem extends Item {
|
||||
public StrawChargeItem() {
|
||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).rarity(Rarity.UNCOMMON));
|
||||
super(new Item.Properties().group(ItemGroup.MISC).rarity(Rarity.UNCOMMON));
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.micle.totemofreviving.items;
|
||||
package dev.micle.totemofreviving.items;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemCharge;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemTarget;
|
||||
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;
|
||||
@ -32,18 +32,18 @@ public class StrawTotemItem extends Item {
|
||||
public static final int STARTING_FAIL_CHANCE = 45;
|
||||
|
||||
public StrawTotemItem() {
|
||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).stacksTo(1).rarity(Rarity.UNCOMMON));
|
||||
super(new Item.Properties().group(ItemGroup.MISC).maxStackSize(1).rarity(Rarity.UNCOMMON));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
||||
super.addInformation(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)) {
|
||||
if (InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), 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."));
|
||||
@ -56,31 +56,31 @@ public class StrawTotemItem extends Item {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedBy(ItemStack stack, World world, PlayerEntity player) {
|
||||
super.onCraftedBy(stack, world, player);
|
||||
public void onCreated(ItemStack stack, World world, PlayerEntity player) {
|
||||
super.onCreated(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); }
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
||||
if (world.isRemote) { return super.onItemRightClick(world, player, hand); }
|
||||
if (player.isCrouching()) {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUUID(), hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUniqueID(), 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();
|
||||
Item item_charge = player.getHeldItem(item_charge_hand).getItem();
|
||||
|
||||
if (item_charge instanceof StrawChargeItem) {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUUID(), hand, item_charge_hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUniqueID(), hand, item_charge_hand));
|
||||
} else {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUUID(), hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUniqueID(), hand));
|
||||
}
|
||||
}
|
||||
return super.use(world, player, hand);
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.micle.totemofreviving.items;
|
||||
package dev.micle.totemofreviving.items;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.network.C2SRequestPlayerRevive;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemCharge;
|
||||
import com.micle.totemofreviving.network.C2SRequestTotemTarget;
|
||||
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;
|
||||
@ -31,16 +31,16 @@ public class TotemOfRevivingItem extends Item {
|
||||
public static final String TAG_TARGET_NAME = "target_name";
|
||||
|
||||
public TotemOfRevivingItem() {
|
||||
super(new Item.Properties().tab(ItemGroup.TAB_MISC).stacksTo(1).rarity(Rarity.RARE));
|
||||
super(new Item.Properties().group(ItemGroup.MISC).maxStackSize(1).rarity(Rarity.RARE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
||||
super.appendHoverText(stack, world, tooltip, flag);
|
||||
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
|
||||
super.addInformation(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)) {
|
||||
if (InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), 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."));
|
||||
@ -53,30 +53,30 @@ public class TotemOfRevivingItem extends Item {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedBy(ItemStack stack, World world, PlayerEntity player) {
|
||||
super.onCraftedBy(stack, world, player);
|
||||
public void onCreated(ItemStack stack, World world, PlayerEntity player) {
|
||||
super.onCreated(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); }
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
||||
if (world.isRemote) { return super.onItemRightClick(world, player, hand); }
|
||||
if (player.isCrouching()) {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUUID(), hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemTarget(player.getUniqueID(), 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();
|
||||
Item item_charge = player.getHeldItem(item_charge_hand).getItem();
|
||||
|
||||
if (item_charge instanceof RevivingChargeItem) {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUUID(), hand, item_charge_hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestTotemCharge(player.getUniqueID(), hand, item_charge_hand));
|
||||
} else {
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUUID(), hand));
|
||||
TotemOfReviving.INSTANCE.sendToServer(new C2SRequestPlayerRevive(player.getUniqueID(), hand));
|
||||
}
|
||||
}
|
||||
return super.use(world, player, hand);
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
@ -1,20 +1,16 @@
|
||||
package com.micle.totemofreviving.network;
|
||||
package dev.micle.totemofreviving.network;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.items.StrawTotemItem;
|
||||
import com.micle.totemofreviving.items.TotemOfRevivingItem;
|
||||
import com.micle.totemofreviving.utils.Utils;
|
||||
import net.minecraft.client.audio.Sound;
|
||||
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.stats.Stats;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.GameType;
|
||||
@ -34,27 +30,27 @@ public class C2SRequestPlayerRevive {
|
||||
}
|
||||
|
||||
public static void encode(final C2SRequestPlayerRevive msg, final PacketBuffer packet_buffer) {
|
||||
packet_buffer.writeUUID(msg.player_uuid);
|
||||
packet_buffer.writeEnum(msg.hand);
|
||||
packet_buffer.writeUniqueId(msg.player_uuid);
|
||||
packet_buffer.writeEnumValue(msg.hand);
|
||||
}
|
||||
|
||||
public static C2SRequestPlayerRevive decode(final PacketBuffer packet_buffer) {
|
||||
return new C2SRequestPlayerRevive(packet_buffer.readUUID(), packet_buffer.readEnum(Hand.class));
|
||||
return new C2SRequestPlayerRevive(packet_buffer.readUniqueId(), packet_buffer.readEnumValue(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);
|
||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayerByUUID(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());
|
||||
ItemStack item = sender.getHeldItem(msg.hand);
|
||||
if (item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_TARGET_INDEX) > TotemOfReviving.players.getCurrentPlayerCount()-1 || item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME).equals("")) {
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.RED + "Error getting target! (Try selecting the target again)"), sender.getUniqueID());
|
||||
} 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();
|
||||
ServerPlayerEntity player_to_revive = TotemOfReviving.players.getPlayerByUsername(item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME));
|
||||
ServerWorld player_to_revive_world = player_to_revive.getServerWorld();
|
||||
ServerWorld sender_world = sender.getServerWorld();
|
||||
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)) {
|
||||
@ -64,24 +60,24 @@ public class C2SRequestPlayerRevive {
|
||||
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));
|
||||
sender.addPotionEffect(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.teleportTo(sender.getX(), sender.getY(), sender.getZ());
|
||||
player_to_revive.setGameMode(GameType.SURVIVAL);
|
||||
player_to_revive.moveForced(sender.getPosX(), sender.getPosY(), sender.getPosZ());
|
||||
player_to_revive.setGameType(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());
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Successfully revived " + TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString()), sender.getUniqueID());
|
||||
} else {
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Not enough charge! Required charge is: " + TextFormatting.DARK_GRAY + required_charge), sender.getUUID());
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Not enough charge! Required charge is: " + TextFormatting.DARK_GRAY + required_charge), sender.getUniqueID());
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not in this dimension!"), sender.getUUID());
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not in this dimension!"), sender.getUniqueID());
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not dead!"), sender.getUUID());
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.DARK_GRAY + player_to_revive.getDisplayName().getString() + TextFormatting.GRAY + " is not dead!"), sender.getUniqueID());
|
||||
}
|
||||
}
|
||||
});
|
@ -1,17 +1,15 @@
|
||||
package com.micle.totemofreviving.network;
|
||||
package dev.micle.totemofreviving.network;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.items.StrawTotemItem;
|
||||
import com.micle.totemofreviving.items.TotemOfRevivingItem;
|
||||
import com.micle.totemofreviving.utils.Utils;
|
||||
import net.minecraft.block.material.Material;
|
||||
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.DamageSource;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
@ -30,31 +28,31 @@ public class C2SRequestTotemCharge {
|
||||
}
|
||||
|
||||
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);
|
||||
packet_buffer.writeUniqueId(msg.player_uuid);
|
||||
packet_buffer.writeEnumValue(msg.hand);
|
||||
packet_buffer.writeEnumValue(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));
|
||||
return new C2SRequestTotemCharge(packet_buffer.readUniqueId(), packet_buffer.readEnumValue(Hand.class), packet_buffer.readEnumValue(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);
|
||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayerByUUID(msg.player_uuid);
|
||||
if (sender == null) { return; }
|
||||
|
||||
ItemStack charge_item = sender.getItemInHand(msg.item_charge_hand);
|
||||
ItemStack totem_item = sender.getItemInHand(msg.hand);
|
||||
ItemStack charge_item = sender.getHeldItem(msg.item_charge_hand);
|
||||
ItemStack totem_item = sender.getHeldItem(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));
|
||||
sender.setHeldItem(msg.hand, new ItemStack(Items.AIR));
|
||||
sender.addPotionEffect(new EffectInstance(Effects.POISON, ((fail_chance*10) / 2), 1));
|
||||
} else {
|
||||
totem_item.getOrCreateTag().putInt(StrawTotemItem.TAG_FAIL_CHANCE, fail_chance+5);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.micle.totemofreviving.network;
|
||||
package dev.micle.totemofreviving.network;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.items.TotemOfRevivingItem;
|
||||
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;
|
||||
@ -23,29 +23,29 @@ public class C2SRequestTotemTarget {
|
||||
}
|
||||
|
||||
public static void encode(final C2SRequestTotemTarget msg, final PacketBuffer packet_buffer) {
|
||||
packet_buffer.writeUUID(msg.player_uuid);
|
||||
packet_buffer.writeEnum(msg.hand);
|
||||
packet_buffer.writeUniqueId(msg.player_uuid);
|
||||
packet_buffer.writeEnumValue(msg.hand);
|
||||
}
|
||||
|
||||
public static C2SRequestTotemTarget decode(final PacketBuffer packet_buffer) {
|
||||
return new C2SRequestTotemTarget(packet_buffer.readUUID(), packet_buffer.readEnum(Hand.class));
|
||||
return new C2SRequestTotemTarget(packet_buffer.readUniqueId(), packet_buffer.readEnumValue(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);
|
||||
final ServerPlayerEntity sender = TotemOfReviving.players.getPlayerByUUID(msg.player_uuid);
|
||||
if (sender == null) { return; }
|
||||
|
||||
ItemStack item = sender.getItemInHand(msg.hand);
|
||||
ItemStack item = sender.getHeldItem(msg.hand);
|
||||
int current_player_index = item.getOrCreateTag().getInt(TotemOfRevivingItem.TAG_TARGET_INDEX) + 1;
|
||||
if (current_player_index > TotemOfReviving.players.getPlayerCount()-1) {
|
||||
if (current_player_index > TotemOfReviving.players.getCurrentPlayerCount()-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());
|
||||
sender.sendMessage(new StringTextComponent(TextFormatting.GRAY + "Target: " + TextFormatting.DARK_GRAY + item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME)), sender.getUniqueID());
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package com.micle.totemofreviving.setup;
|
||||
package dev.micle.totemofreviving.setup;
|
||||
|
||||
import com.micle.totemofreviving.items.RevivingChargeItem;
|
||||
import com.micle.totemofreviving.items.StrawChargeItem;
|
||||
import com.micle.totemofreviving.items.StrawTotemItem;
|
||||
import com.micle.totemofreviving.items.TotemOfRevivingItem;
|
||||
import dev.micle.totemofreviving.items.RevivingChargeItem;
|
||||
import dev.micle.totemofreviving.items.StrawChargeItem;
|
||||
import dev.micle.totemofreviving.items.StrawTotemItem;
|
||||
import dev.micle.totemofreviving.items.TotemOfRevivingItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
public class ModItems {
|
@ -1,7 +1,7 @@
|
||||
package com.micle.totemofreviving.setup;
|
||||
package dev.micle.totemofreviving.setup;
|
||||
|
||||
import com.micle.totemofreviving.TotemOfReviving;
|
||||
import com.micle.totemofreviving.events.ServerTickEventHandler;
|
||||
import dev.micle.totemofreviving.TotemOfReviving;
|
||||
import dev.micle.totemofreviving.events.ServerTickEventHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
@ -1,4 +1,4 @@
|
||||
package com.micle.totemofreviving.utils;
|
||||
package dev.micle.totemofreviving.utils;
|
||||
|
||||
public class Utils {
|
||||
public static float clamp(float val, float min, float max) {
|
Reference in New Issue
Block a user