Now spending time in limbo, items randomly will get frayed.

This commit is contained in:
MalekiRe 2021-06-10 17:42:35 -07:00
parent 050f00f662
commit 68a8290296

View file

@ -3,9 +3,11 @@ package org.dimdev.dimdoors.mixin;
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.criteria.ModCriteria;
import org.dimdev.dimdoors.enchantment.ModEnchants;
import org.dimdev.dimdoors.entity.limbo.LimboEntranceSource;
import org.dimdev.dimdoors.entity.stat.ModStats;
import org.dimdev.dimdoors.api.util.TeleportUtil;
@ -35,6 +37,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
private static final float RANDOM_ACTION_CHANCE = 0.1F;
private static final float CHANCE_TO_DECREASE_ARMOR_DURABILITY = 0.03F;
private static final float CHANCE_TO_REPLACE_ITEMSLOT_WITH_UNRAVLED_FABRIC = 0.005F;
private static final float CHANCE_TO_ENCHANT_WITH_FRAY = 0.01F;
Random random = new Random();
public ServerPlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
@ -43,11 +46,16 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
public void mobTickMixin(CallbackInfo ci) {
if (PlayerModifiersComponent.getFray(this) >= 125) {
if (random.nextFloat() <= RANDOM_ACTION_CHANCE) {
if (random.nextFloat() <= RANDOM_ACTION_CHANCE) {
if (PlayerModifiersComponent.getFray(this) >= 125) {
doRandomFunction(this);
}
if(ModDimensions.isLimboDimension(((PlayerEntity)(Object)(this)).getEntityWorld())) {
tryAddingFrayEnchantment((PlayerEntity) (Object)this);
}
}
}
private void doRandomFunction(LivingEntity player) {
@ -63,29 +71,44 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin {
}
private void tryAddingFrayEnchantment(PlayerEntity player) {
if (!(random.nextFloat() <= CHANCE_TO_ENCHANT_WITH_FRAY)) {
return;
}
int slot = random.nextInt(player.getInventory().size());
if (!player.getInventory().getStack(slot).isEnchantable()) {
return;
}
ItemStack stack = player.getInventory().getStack(slot);
stack.addEnchantment(ModEnchants.FRAYED_ENCHAMENT, 1);
player.getInventory().setStack(slot, stack);
((ExtendedServerPlayNetworkHandler) (Object) ((ServerPlayerEntity) (Object) this).networkHandler).getDimDoorsPacketHandler().sendPacket(new PlayerInventorySlotUpdateS2CPacket(slot, stack));
}
//TODO: Fix this shit so it syncs.
private void addRandomUnravledFabric(PlayerEntity player) {
if(PlayerModifiersComponent.getFray(player) < DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.unravledFabricInInventoryFray)
if (PlayerModifiersComponent.getFray(player) < DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.unravledFabricInInventoryFray)
return;
if(!(random.nextFloat() <= CHANCE_TO_REPLACE_ITEMSLOT_WITH_UNRAVLED_FABRIC))
if (!(random.nextFloat() <= CHANCE_TO_REPLACE_ITEMSLOT_WITH_UNRAVLED_FABRIC))
return;
int slot = random.nextInt(player.getInventory().main.size());
if(!player.getInventory().main.get(slot).isEmpty() && ! (player.getInventory().main.get(slot).getItem() == ModItems.UNRAVELLED_FABRIC))
if (!player.getInventory().main.get(slot).isEmpty() && !(player.getInventory().main.get(slot).getItem() == ModItems.UNRAVELLED_FABRIC))
return;
if (player.getInventory().main.get(slot).getCount() >= 64)
return;
ItemStack stack = new ItemStack(ModItems.UNRAVELLED_FABRIC, 1 + player.getInventory().main.get(slot).getCount());
player.getInventory().main.set(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));
}
private void decreaseArmorDurability(PlayerEntity player) {
if(PlayerModifiersComponent.getFray(player) < DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.unravledFabricInInventoryFray)
if (PlayerModifiersComponent.getFray(player) < DimensionalDoorsInitializer.getConfig().getPlayerConfig().fray.unravledFabricInInventoryFray)
return;
for (int i = 0; i < player.getInventory().armor.size(); i++)
if(random.nextFloat() <= CHANCE_TO_DECREASE_ARMOR_DURABILITY)
if (random.nextFloat() <= CHANCE_TO_DECREASE_ARMOR_DURABILITY)
player.getArmorItems().forEach((itemStack) -> {
itemStack.setDamage(itemStack.getDamage() + 1);
});