Now there is a StringTheory enchantment that will decrease the amount of fray you get from something, by 15 percent per enchanted armor piece.

This commit is contained in:
MalekiRe 2021-06-10 21:20:01 -07:00
parent 68a8290296
commit 18f974e6c8
5 changed files with 47 additions and 10 deletions

View file

@ -16,5 +16,9 @@ public class FrayedEnchantment extends Enchantment {
public int getMaxLevel() { public int getMaxLevel() {
return 1; return 1;
} }
@Override
public boolean isCursed(){
return true;
}
} }

View file

@ -1,21 +1,24 @@
package org.dimdev.dimdoors.enchantment; package org.dimdev.dimdoors.enchantment;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import org.dimdev.matrix.Registrar;
import org.dimdev.matrix.RegistryEntry;
public class ModEnchants { public class ModEnchants {
public static Enchantment FRAYED_ENCHAMENT; public static Enchantment FRAYED_ENCHANTMENT;
public static Enchantment STRING_THEORY_ENCHANTMENT;
public static void init() { public static void init() {
FRAYED_ENCHAMENT = Registry.register( FRAYED_ENCHANTMENT = Registry.register(
Registry.ENCHANTMENT, Registry.ENCHANTMENT,
new Identifier("dimdoors", "frayed"), new Identifier("dimdoors", "frayed"),
new FrayedEnchantment(Enchantment.Rarity.VERY_RARE, EnchantmentTarget.BREAKABLE, new EquipmentSlot[] {EquipmentSlot.MAINHAND, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.HEAD, EquipmentSlot.LEGS}) new FrayedEnchantment(Enchantment.Rarity.VERY_RARE, EnchantmentTarget.BREAKABLE, new EquipmentSlot[] {EquipmentSlot.MAINHAND, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.HEAD, EquipmentSlot.LEGS})
); );
STRING_THEORY_ENCHANTMENT = Registry.register(
Registry.ENCHANTMENT,
new Identifier("dimdoors", "string_theory"),
new StringTheoryEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentTarget.WEARABLE, new EquipmentSlot[] {EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.CHEST, EquipmentSlot.HEAD})
);
} }
} }

View file

@ -0,0 +1,23 @@
package org.dimdev.dimdoors.enchantment;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
public class StringTheoryEnchantment extends Enchantment {
public StringTheoryEnchantment(Rarity weight, EnchantmentTarget type, EquipmentSlot[] slotTypes) {
super(weight, type, slotTypes);
}
@Override
public int getMinPower(int level) {
return 10000;
}
@Override
public int getMaxLevel() {
return 1;
}
public boolean isTreasure() {
return true;
}
}

View file

@ -1,10 +1,6 @@
package org.dimdev.dimdoors.mixin; package org.dimdev.dimdoors.mixin;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.jmx.Server;
import org.dimdev.dimdoors.DimensionalDoorsInitializer; import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.criteria.ModCriteria; import org.dimdev.dimdoors.criteria.ModCriteria;
import org.dimdev.dimdoors.enchantment.ModEnchants; import org.dimdev.dimdoors.enchantment.ModEnchants;
@ -80,7 +76,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
return; return;
} }
ItemStack stack = player.getInventory().getStack(slot); ItemStack stack = player.getInventory().getStack(slot);
stack.addEnchantment(ModEnchants.FRAYED_ENCHAMENT, 1); stack.addEnchantment(ModEnchants.FRAYED_ENCHANTMENT, 1);
player.getInventory().setStack(slot, stack); player.getInventory().setStack(slot, stack);
((ExtendedServerPlayNetworkHandler) (Object) ((ServerPlayerEntity) (Object) this).networkHandler).getDimDoorsPacketHandler().sendPacket(new PlayerInventorySlotUpdateS2CPacket(slot, stack)); ((ExtendedServerPlayNetworkHandler) (Object) ((ServerPlayerEntity) (Object) this).networkHandler).getDimDoorsPacketHandler().sendPacket(new PlayerInventorySlotUpdateS2CPacket(slot, stack));

View file

@ -2,6 +2,8 @@ package org.dimdev.dimdoors.world.level.component;
import dev.onyxstudios.cca.api.v3.component.ComponentV3; import dev.onyxstudios.cca.api.v3.component.ComponentV3;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import org.dimdev.dimdoors.DimensionalDoorsComponents; import org.dimdev.dimdoors.DimensionalDoorsComponents;
import org.dimdev.dimdoors.DimensionalDoorsInitializer; import org.dimdev.dimdoors.DimensionalDoorsInitializer;
@ -12,6 +14,10 @@ import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import org.dimdev.dimdoors.block.ModBlocks; import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.enchantment.ModEnchants;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
public class PlayerModifiersComponent implements ComponentV3, AutoSyncedComponent { public class PlayerModifiersComponent implements ComponentV3, AutoSyncedComponent {
private int fray = 0; private int fray = 0;
@ -68,6 +74,11 @@ public class PlayerModifiersComponent implements ComponentV3, AutoSyncedComponen
} }
public static int incrementFray(PlayerEntity player, int amount) { public static int incrementFray(PlayerEntity player, int amount) {
for(int i = 0; i < player.getInventory().armor.size(); i++) {
if(EnchantmentHelper.getLevel(ModEnchants.STRING_THEORY_ENCHANTMENT, player.getInventory().armor.get(i)) > 0) {
amount *= 0.85;
}
}
int v = get(player).incrementFray(amount); int v = get(player).incrementFray(amount);
PlayerModifiersComponent.sync(player); PlayerModifiersComponent.sync(player);
if(getFray(player) == DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.maxFray) { if(getFray(player) == DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.maxFray) {