Version 1.0

This commit is contained in:
micle
2021-05-29 16:01:58 +01:00
commit 439440767d
26 changed files with 828 additions and 0 deletions

177
build.gradle Normal file
View File

@ -0,0 +1,177 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
version = '1.0'
group = 'com.micle.totemofreviving' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'totemofreviving'
java.toolchain.languageVersion = JavaLanguageVersion.of(8) // Mojang ships Java 8 to end users, so your mod should target Java 8.
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// Channel: Version:
// snapshot YYYYMMDD Snapshot are built nightly.
// stable # Stables are built at the discretion of the MCP team.
// official MCVersion Official field/method names from Mojang mapping files
//
// You must be aware of the Mojang license when using the 'official' mappings.
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
//
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.16.5'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
// The markers can be changed as needed.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
mods {
totemofreviving {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
// The markers can be changed as needed.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
mods {
totemofreviving {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
// The markers can be changed as needed.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'totemofreviving', '--all',
'--existing', file('src/main/resources').toString(),
'--existing', file('src/generated/resources').toString(),
'--output', file('src/generated/resources/')
mods {
totemofreviving {
source sourceSets.main
}
}
}
}
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.16.5-36.1.4'
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title": "totemofreviving",
"Specification-Vendor": "totemofrevivingsareus",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"totemofrevivingsareus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
}
}

View File

@ -0,0 +1,6 @@
8a2b88672a3111967914bf84746ee02770dc8aca assets/totemofreviving/models/item/reviving_charge.json
9802f8a76c014c4e7d5b093643a0f8f2c75474bc assets/totemofreviving/models/item/totem_of_reviving.json
97e29a14be1fa658d16ee23c9791822f6d49dab7 data/totemofreviving/advancements/recipes/misc/reviving_charge.json
9be362836ef513789b2c8e3d88d35a6b802b5d27 data/totemofreviving/advancements/recipes/misc/totem_of_reviving.json
0a4143689809621511c8e586e6f030e2dd7a5927 data/totemofreviving/recipes/reviving_charge.json
8d9f9d28b0748d5dacbf0824b8f6531a6a00bbfa data/totemofreviving/recipes/totem_of_reviving.json

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "totemofreviving:item/reviving_charge"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "totemofreviving:item/totem_of_reviving"
}
}

View File

@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"totemofreviving:reviving_charge"
]
},
"criteria": {
"has_item": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "totemofreviving:totem_of_reviving"
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "totemofreviving:reviving_charge"
}
}
},
"requirements": [
[
"has_item",
"has_the_recipe"
]
]
}

View File

@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"totemofreviving:totem_of_reviving"
]
},
"criteria": {
"has_item": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "minecraft:totem_of_undying"
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "totemofreviving:totem_of_reviving"
}
}
},
"requirements": [
[
"has_item",
"has_the_recipe"
]
]
}

View File

@ -0,0 +1,22 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"@E@",
"E#E",
"@E@"
],
"key": {
"#": {
"item": "minecraft:totem_of_undying"
},
"@": {
"item": "minecraft:diamond_block"
},
"E": {
"item": "minecraft:ender_pearl"
}
},
"result": {
"item": "totemofreviving:reviving_charge"
}
}

View File

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"@@@",
"@#@",
"@@@"
],
"key": {
"#": {
"item": "minecraft:totem_of_undying"
},
"@": {
"item": "minecraft:diamond"
}
},
"result": {
"item": "totemofreviving:totem_of_reviving"
}
}

View File

@ -0,0 +1,53 @@
package com.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 net.minecraft.server.management.PlayerList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
@Mod(TotemOfReviving.MOD_ID)
public class TotemOfReviving {
public static final String MOD_ID = "totemofreviving";
public static PlayerList players;
private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(TotemOfReviving.MOD_ID, "main"),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals
);
public TotemOfReviving() {
Registration.register();
int id = 0;
INSTANCE.registerMessage(id++,
C2SRequestPlayerRevive.class,
C2SRequestPlayerRevive::encode,
C2SRequestPlayerRevive::decode,
C2SRequestPlayerRevive::handle
);
INSTANCE.registerMessage(id++,
C2SRequestTotemTarget.class,
C2SRequestTotemTarget::encode,
C2SRequestTotemTarget::decode,
C2SRequestTotemTarget::handle
);
INSTANCE.registerMessage(id++,
C2SRequestTotemCharge.class,
C2SRequestTotemCharge::encode,
C2SRequestTotemCharge::decode,
C2SRequestTotemCharge::handle
);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
}

View File

@ -0,0 +1,24 @@
package com.micle.totemofreviving.data;
import com.micle.totemofreviving.TotemOfReviving;
import com.micle.totemofreviving.data.client.ModItemModelProvider;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
@Mod.EventBusSubscriber(modid = TotemOfReviving.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DataGenerators {
private DataGenerators() {}
@SubscribeEvent
public static void gatherData(GatherDataEvent e) {
DataGenerator gen = e.getGenerator();
ExistingFileHelper existing_file_helper = e.getExistingFileHelper();
gen.addProvider(new ModItemModelProvider(gen, existing_file_helper));
gen.addProvider(new ModRecipeProvider(gen));
}
}

View File

@ -0,0 +1,34 @@
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);
}
}

View File

@ -0,0 +1,31 @@
package com.micle.totemofreviving.data.client;
import com.google.gson.JsonElement;
import com.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);
}
@Override
protected void registerModels() {
ModelFile item_generated = getExistingFile(mcLoc("item/generated"));
builder(item_generated, "totem_of_reviving");
builder(item_generated, "reviving_charge");
}
private ItemModelBuilder builder(ModelFile item_generated, String name) {
return getBuilder(name).parent(item_generated).texture("layer0", "item/" + name);
}
}

View File

@ -0,0 +1,13 @@
package com.micle.totemofreviving.events;
import com.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();
}
}

View File

@ -0,0 +1,10 @@
package com.micle.totemofreviving.items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
public class RevivingChargeItem extends Item {
public RevivingChargeItem() {
super(new Item.Properties().tab(ItemGroup.TAB_MISC));
}
}

View File

@ -0,0 +1,75 @@
package com.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 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
@OnlyIn(Dist.CLIENT)
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand 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);
}
}

View File

@ -0,0 +1,71 @@
package com.micle.totemofreviving.network;
import com.micle.totemofreviving.TotemOfReviving;
import com.micle.totemofreviving.items.TotemOfRevivingItem;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
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) {
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) {
player_to_revive.teleportTo(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.AQUA + "Successfully revived " + TextFormatting.BLUE + player_to_revive.getDisplayName().getString()), sender.getUUID());
} else {
sender.sendMessage(new StringTextComponent(TextFormatting.AQUA + "Not enough charge! Required charge is: " + TextFormatting.BLUE + required_charge), sender.getUUID());
}
} else {
sender.sendMessage(new StringTextComponent(TextFormatting.BLUE + player_to_revive.getDisplayName().getString() + TextFormatting.AQUA + " is not in this dimension!"), sender.getUUID());
}
} else {
sender.sendMessage(new StringTextComponent(TextFormatting.BLUE + player_to_revive.getDisplayName().getString() + TextFormatting.AQUA + " is not dead!"), sender.getUUID());
}
}
});
context.setPacketHandled(true);
}
}

View File

@ -0,0 +1,49 @@
package com.micle.totemofreviving.network;
import com.micle.totemofreviving.TotemOfReviving;
import com.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.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);
});
context.setPacketHandled(true);
}
}

View File

@ -0,0 +1,52 @@
package com.micle.totemofreviving.network;
import com.micle.totemofreviving.TotemOfReviving;
import com.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.AQUA + "Target: " + TextFormatting.BLUE + item.getOrCreateTag().getString(TotemOfRevivingItem.TAG_TARGET_NAME)), sender.getUUID());
});
context.setPacketHandled(true);
}
}

View File

@ -0,0 +1,15 @@
package com.micle.totemofreviving.setup;
import com.micle.totemofreviving.items.RevivingChargeItem;
import com.micle.totemofreviving.items.TotemOfRevivingItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.fml.RegistryObject;
public class ModItems {
public static final RegistryObject<Item> TOTEM_OF_REVIVING = Registration.ITEMS.register("totem_of_reviving", TotemOfRevivingItem::new);
public static final RegistryObject<Item> REVIVING_CHARGE = Registration.ITEMS.register("reviving_charge", RevivingChargeItem::new);
static void register() {
}
}

View File

@ -0,0 +1,25 @@
package com.micle.totemofreviving.setup;
import com.micle.totemofreviving.TotemOfReviving;
import com.micle.totemofreviving.events.ServerTickEventHandler;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
public class Registration {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, TotemOfReviving.MOD_ID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TotemOfReviving.MOD_ID);
public static void register() {
IEventBus mod_event_bus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(mod_event_bus);
ITEMS.register(mod_event_bus);
MinecraftForge.EVENT_BUS.register(new ServerTickEventHandler());
ModItems.register();
}
}

View File

@ -0,0 +1,7 @@
package com.micle.totemofreviving.utils;
public class Utils {
public static float clamp(float val, float min, float max) {
return Math.max(min, Math.min(max, val));
}
}

View File

@ -0,0 +1,58 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[36,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="All rights reserved"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="totemofreviving" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Micle's Totem of Reviving" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
#logoFile="examplemod.png" #optional
# A text field displayed in the mod UI
#credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors="Micle" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
Mod for reviving players in a hardcore world.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.totemofreviving]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[36,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.totemofreviving]]
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.16.5,1.17)"
ordering="NONE"
side="BOTH"

View File

@ -0,0 +1,4 @@
{
"item.totemofreviving.totem_of_reviving": "Totem of Reviving",
"item.totemofreviving.reviving_charge": "Reviving charge"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

7
src/main/resources/pack.mcmeta Executable file
View File

@ -0,0 +1,7 @@
{
"pack": {
"description": "totemofreviving resources",
"pack_format": 6,
"_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods."
}
}