aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java72
-rw-r--r--src/main/java/los/numeros/utils/GiveItem.java31
2 files changed, 69 insertions, 34 deletions
diff --git a/src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java b/src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java
index 8c1b2b3..f941fdf 100644
--- a/src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java
+++ b/src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java
@@ -4,9 +4,13 @@ import los.numeros.GameEngine.Module;
import los.numeros.utils.GiveItem;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments;
+import net.minecraft.entity.attribute.EntityAttribute;
+import net.minecraft.entity.attribute.EntityAttributeModifier;
+import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.GameMode;
@@ -20,43 +24,67 @@ public class MainModule implements Module {
}
public void giveDiggerItems(ServerPlayerEntity[] diggers) {
+ // get pickace with efficiency 3
+ ItemStack pickaxe = GiveItem.getItem("diamond_pickaxe");
+ pickaxe.addEnchantment(Enchantments.EFFICIENCY, 3);
+
+ // put unbreakable attribute into NBT tag
+ NbtCompound pTag = pickaxe.getTag();
+ pTag.putBoolean("Unbreakable", true);
+ pickaxe.setTag(pTag);
+
for (ServerPlayerEntity p : diggers) {
- GiveItem.setPlayerSlot(p, "diamond_helmet", GiveItem.ARMOR_HEAD);
- GiveItem.setPlayerSlot(p, "diamond_leggings", GiveItem.ARMOR_LEGS);
- GiveItem.setPlayerSlot(p, "diamond_chestplate", GiveItem.ARMOR_CHEST);
- GiveItem.setPlayerSlot(p, "diamond_boots", GiveItem.ARMOR_BOOTS);
- GiveItem.setPlayerSlot(p, "iron_sword", 0);
- ItemStack pickaxe = GiveItem.givePlayerSpecialItem(p, "diamond_pickaxe");
- pickaxe.addEnchantment(Enchantments.EFFICIENCY, 3);
- pickaxe.addEnchantment(Enchantments.UNBREAKING, 255); // TODO: add item attribute unbreakable
+ // give armor
+ GiveItem.givePlayerItem(p, "diamond_helmet", GiveItem.ARMOR_HEAD);
+ GiveItem.givePlayerItem(p, "diamond_leggings", GiveItem.ARMOR_LEGS);
+ GiveItem.givePlayerItem(p, "diamond_chestplate", GiveItem.ARMOR_CHEST);
+ GiveItem.givePlayerItem(p, "diamond_boots", GiveItem.ARMOR_BOOTS);
+ GiveItem.givePlayerItem(p, "iron_sword", 0);
+
+ // equip pick axe and glow diggers
p.equip(1, pickaxe);
+ p.addStatusEffect(new StatusEffectInstance(StatusEffects.GLOWING, 200000000, 3, false, false));
}
}
- public void giveHidersItems(ServerPlayerEntity[] hidders) {
- for (ServerPlayerEntity p : hidders) {
- ItemStack pickaxe = GiveItem.givePlayerSpecialItem(p, "diamond_pickaxe");
- pickaxe.addEnchantment(Enchantments.SILK_TOUCH, 1);
- pickaxe.addEnchantment(Enchantments.UNBREAKING, 255); // TODO: add item attribute unbreakable
+ public void giveHidersItems(ServerPlayerEntity[] hiders) {
+ // get pick with silk touch
+ ItemStack pickaxe = GiveItem.getItem("diamond_pickaxe");
+ pickaxe.addEnchantment(Enchantments.SILK_TOUCH, 1);
+
+ // put unbreakable attribute into NBT tag
+ NbtCompound pTag = pickaxe.getTag();
+ pTag.putBoolean("Unbreakable", true);
+ pickaxe.setTag(pTag);
+
+ for (ServerPlayerEntity p : hiders) {
+ // equip picaxe on each player
p.equip(0, pickaxe);
- GiveItem.setPlayerSlot(p, "minecraft:stone", 1);
+
+ // give stone x10
+ GiveItem.giveMultipleItem(p, "minecraft:stone", null, 10);
}
}
@Override
public int init()
{
- giveHidersItems(hidders);
- giveDiggerItems(diggers);
+ // Give items and status effects to everyone playing game
for (ServerPlayerEntity p : players) {
+ // Put everyone to full health and hunger and give them night vision on haste until game ends
+ p.inventory.clear();
p.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 200000000, 3, false, false));
p.addStatusEffect(new StatusEffectInstance(StatusEffects.HASTE, 200000000, 1, false, false));
- p.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 300, 100, false, false)); // TODO: Rplace with jsut setting health/hunger
p.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 300, 100, false, false));
- // TODO: add haste
- // TODO: add beef x64
+ p.heal(20);
+
+ // give steak x64
+ GiveItem.giveMultipleItem(p, "cooked_beef", 2, 64);
+
p.setGameMode(GameMode.SURVIVAL);
}
+ giveDiggerItems(diggers);
+ giveHidersItems(hidders);
// TODO: FILL AND TP PLAYERS AND CLEAR ALL ITEMS
return 0;
}
@@ -64,7 +92,11 @@ public class MainModule implements Module {
@Override
public int end()
{
-
+ for (ServerPlayerEntity p : players) {
+ p.clearStatusEffects();
+ p.setGameMode(GameMode.CREATIVE);
+ p.inventory.clear();
+ }
return 0;
}
} \ No newline at end of file
diff --git a/src/main/java/los/numeros/utils/GiveItem.java b/src/main/java/los/numeros/utils/GiveItem.java
index d42207d..aaaf35c 100644
--- a/src/main/java/los/numeros/utils/GiveItem.java
+++ b/src/main/java/los/numeros/utils/GiveItem.java
@@ -1,13 +1,7 @@
package los.numeros.utils;
-import java.text.AttributedCharacterIterator.Attribute;
+import org.jetbrains.annotations.Nullable;
-import net.minecraft.enchantment.Enchantment;
-import net.minecraft.enchantment.Enchantments;
-import net.minecraft.enchantment.UnbreakingEnchantment;
-import net.minecraft.entity.attribute.EntityAttribute;
-import net.minecraft.entity.attribute.EntityAttributeModifier;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
@@ -19,18 +13,27 @@ public class GiveItem {
public static final int ARMOR_LEGS = 101;
public static final int ARMOR_BOOTS = 100;
- public static void givePlayerItem(ServerPlayerEntity player, String itemID) {
- ItemStack item = new ItemStack(Registry.ITEM.get(new Identifier(itemID)));
- player.inventory.insertStack(item);
+ public static void givePlayerItem(ServerPlayerEntity player, String itemID, @Nullable Integer slot) {
+ ItemStack item = getItem(itemID);
+ if (slot == null) {
+ player.inventory.insertStack(item);
+ } else {
+ player.equip(slot, item);
+ }
}
- public static ItemStack givePlayerSpecialItem(ServerPlayerEntity player, String itemID) {
+ public static ItemStack getItem(String itemID) {
ItemStack item = new ItemStack(Registry.ITEM.get(new Identifier(itemID)));
return item;
}
- public static void setPlayerSlot(ServerPlayerEntity player, String itemID, int slot) {
- ItemStack item = new ItemStack(Registry.ITEM.get(new Identifier(itemID)));
- player.equip(slot, item);
+ public static void giveMultipleItem(ServerPlayerEntity player, String itemID, @Nullable Integer slot, int quantity) {
+ ItemStack item = getItem(itemID);
+ item.increment(quantity - 1);
+ if (slot == null) {
+ player.inventory.insertStack(item);
+ } else {
+ player.equip(slot, item);
+ }
}
}