Skip to content

Commit

Permalink
Make it compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed May 7, 2024
1 parent bc80b7d commit b6b5954
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.soulfiremc.generator.generators.BlocksJavaGenerator;
import com.soulfiremc.generator.generators.DefaultTagsDataGenerator;
import com.soulfiremc.generator.generators.EffectsDataGenerator;
import com.soulfiremc.generator.generators.EffectsJavaGenerator;
import com.soulfiremc.generator.generators.EnchantmentsDataGenerator;
import com.soulfiremc.generator.generators.EnchantmentsJavaGenerator;
import com.soulfiremc.generator.generators.EntitiesDataGenerator;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class DataGenerators {
new FluidsDataGenerator(),
new FluidsJavaGenerator(),
new EffectsDataGenerator(),
new EffectsJavaGenerator(),
new EnchantmentsDataGenerator(),
new EnchantmentsJavaGenerator(),
new EntitiesDataGenerator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static JsonObject generateEffect(MobEffect effect) {
"key",
Objects.requireNonNull(BuiltInRegistries.MOB_EFFECT.getKey(effect)).toString());

effectDesc.addProperty("category", effect.getCategory().name());

if (effect.isBeneficial()) {
effectDesc.addProperty("beneficial", true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.generator.generators;

import com.soulfiremc.generator.util.GeneratorConstants;
import com.soulfiremc.generator.util.ResourceHelper;
import java.util.Locale;
import java.util.Objects;
import net.minecraft.core.registries.BuiltInRegistries;

public class EffectsJavaGenerator implements IDataGenerator {
@Override
public String getDataName() {
return "EffectType.java";
}

@Override
public String generateDataJson() {
var base = ResourceHelper.getResource("/templates/EffectType.java");
return base.replace(
GeneratorConstants.VALUES_REPLACE,
String.join(
"\n ",
BuiltInRegistries.MOB_EFFECT.stream()
.map(
s -> {
var key = Objects.requireNonNull(BuiltInRegistries.MOB_EFFECT.getKey(s));
return "public static final EffectType "
+ key.getPath().toUpperCase(Locale.ROOT)
+ " = register(\""
+ key
+ "\");";
})
.toArray(String[]::new)));
}
}
75 changes: 75 additions & 0 deletions data-generator/src/main/resources/templates/EffectType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.data;

import it.unimi.dsi.fastutil.ints.Int2ReferenceMap;
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ReferenceMap;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import lombok.AccessLevel;
import lombok.With;

@SuppressWarnings("unused")
@With(value = AccessLevel.PRIVATE)
public record EffectType(int id, ResourceKey key, EffectCategory category, boolean beneficial, boolean instantenous) {
public static final Int2ReferenceMap<EffectType> FROM_ID = new Int2ReferenceOpenHashMap<>();
public static final Object2ReferenceMap<ResourceKey, EffectType> FROM_KEY = new Object2ReferenceOpenHashMap<>();

//@formatter:off
// VALUES REPLACE
//@formatter:on

public static EffectType register(String key) {
var instance =
GsonDataHelper.fromJson("/minecraft/effects.json", key, EffectType.class);

FROM_ID.put(instance.id(), instance);
FROM_KEY.put(instance.key(), instance);
return instance;
}

public static EffectType getById(int id) {
return FROM_ID.get(id);
}

public static EffectType getByKey(ResourceKey key) {
return FROM_KEY.get(key);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EffectType other)) {
return false;
}
return id == other.id;
}

@Override
public int hashCode() {
return id;
}

public enum EffectCategory {
BENEFICIAL,
HARMFUL,
NEUTRAL
}
}
113 changes: 113 additions & 0 deletions server/src/main/java/com/soulfiremc/server/data/EffectType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.server.data;

import it.unimi.dsi.fastutil.ints.Int2ReferenceMap;
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ReferenceMap;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import lombok.AccessLevel;
import lombok.With;

@SuppressWarnings("unused")
@With(value = AccessLevel.PRIVATE)
public record EffectType(int id, ResourceKey key, EffectCategory category, boolean beneficial, boolean instantenous) {
public static final Int2ReferenceMap<EffectType> FROM_ID = new Int2ReferenceOpenHashMap<>();
public static final Object2ReferenceMap<ResourceKey, EffectType> FROM_KEY = new Object2ReferenceOpenHashMap<>();

//@formatter:off
public static final EffectType SPEED = register("minecraft:speed");
public static final EffectType SLOWNESS = register("minecraft:slowness");
public static final EffectType HASTE = register("minecraft:haste");
public static final EffectType MINING_FATIGUE = register("minecraft:mining_fatigue");
public static final EffectType STRENGTH = register("minecraft:strength");
public static final EffectType INSTANT_HEALTH = register("minecraft:instant_health");
public static final EffectType INSTANT_DAMAGE = register("minecraft:instant_damage");
public static final EffectType JUMP_BOOST = register("minecraft:jump_boost");
public static final EffectType NAUSEA = register("minecraft:nausea");
public static final EffectType REGENERATION = register("minecraft:regeneration");
public static final EffectType RESISTANCE = register("minecraft:resistance");
public static final EffectType FIRE_RESISTANCE = register("minecraft:fire_resistance");
public static final EffectType WATER_BREATHING = register("minecraft:water_breathing");
public static final EffectType INVISIBILITY = register("minecraft:invisibility");
public static final EffectType BLINDNESS = register("minecraft:blindness");
public static final EffectType NIGHT_VISION = register("minecraft:night_vision");
public static final EffectType HUNGER = register("minecraft:hunger");
public static final EffectType WEAKNESS = register("minecraft:weakness");
public static final EffectType POISON = register("minecraft:poison");
public static final EffectType WITHER = register("minecraft:wither");
public static final EffectType HEALTH_BOOST = register("minecraft:health_boost");
public static final EffectType ABSORPTION = register("minecraft:absorption");
public static final EffectType SATURATION = register("minecraft:saturation");
public static final EffectType GLOWING = register("minecraft:glowing");
public static final EffectType LEVITATION = register("minecraft:levitation");
public static final EffectType LUCK = register("minecraft:luck");
public static final EffectType UNLUCK = register("minecraft:unluck");
public static final EffectType SLOW_FALLING = register("minecraft:slow_falling");
public static final EffectType CONDUIT_POWER = register("minecraft:conduit_power");
public static final EffectType DOLPHINS_GRACE = register("minecraft:dolphins_grace");
public static final EffectType BAD_OMEN = register("minecraft:bad_omen");
public static final EffectType HERO_OF_THE_VILLAGE = register("minecraft:hero_of_the_village");
public static final EffectType DARKNESS = register("minecraft:darkness");
public static final EffectType TRIAL_OMEN = register("minecraft:trial_omen");
public static final EffectType RAID_OMEN = register("minecraft:raid_omen");
public static final EffectType WIND_CHARGED = register("minecraft:wind_charged");
public static final EffectType WEAVING = register("minecraft:weaving");
public static final EffectType OOZING = register("minecraft:oozing");
public static final EffectType INFESTED = register("minecraft:infested");
//@formatter:on

public static EffectType register(String key) {
var instance =
GsonDataHelper.fromJson("/minecraft/effects.json", key, EffectType.class);

FROM_ID.put(instance.id(), instance);
FROM_KEY.put(instance.key(), instance);
return instance;
}

public static EffectType getById(int id) {
return FROM_ID.get(id);
}

public static EffectType getByKey(ResourceKey key) {
return FROM_KEY.get(key);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EffectType other)) {
return false;
}
return id == other.id;
}

@Override
public int hashCode() {
return id;
}

public enum EffectCategory {
BENEFICIAL,
HARMFUL,
NEUTRAL
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.server.data;

import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static TickResult getRequiredMiningTicks(
var efficiency = itemStack.getEnchantmentLevel(EnchantmentType.EFFICIENCY);
if (efficiency > 0) {
// Efficiency is capped at 255
efficiency = MathHelper.shortClamp(efficiency, (short) 0, (short) 255);
efficiency = MathHelper.shortClamp((short) efficiency, (short) 0, (short) 255);
speedMultiplier += (float) (efficiency * efficiency + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void onJoined(BotJoinedEvent event) {
var playerInventory = inventoryManager.playerInventory();

var edibleSlot = playerInventory.findMatchingSlotForAction(
slot -> slot.item() != null && ItemTypeHelper.isGoodEdibleFood(slot.item().type()));
slot -> slot.item() != null && ItemTypeHelper.isGoodEdibleFood(slot.item()));
if (edibleSlot.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.soulfiremc.server.protocol.bot.container;

import com.soulfiremc.server.data.EquipmentSlot;
import com.soulfiremc.server.data.ItemType;
import com.soulfiremc.server.protocol.BotConnection;
import com.soulfiremc.server.protocol.bot.SessionDataManager;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
Expand All @@ -43,7 +42,7 @@ public class InventoryManager {
private final PlayerInventoryContainer playerInventory = new PlayerInventoryContainer(this);
private final Int2ObjectMap<Container> containerData =
new Int2ObjectOpenHashMap<>(Map.of(0, playerInventory));
private final Map<EquipmentSlot, ItemType> lastInEquipment = new EnumMap<>(EquipmentSlot.class);
private final Map<EquipmentSlot, SFItemStack> lastInEquipment = new EnumMap<>(EquipmentSlot.class);
private final ReentrantLock inventoryControlLock = new ReentrantLock();
@ToString.Exclude
private final SessionDataManager dataManager;
Expand Down Expand Up @@ -163,12 +162,12 @@ private void applyIfMatches(EquipmentSlot equipmentSlot) {
var previousItem = lastInEquipment.get(equipmentSlot);
boolean hasChanged;
if (previousItem != null) {
if (item == null || previousItem != item.type()) {
if (item == null || previousItem.type() != item.type()) {
// Item before, but we don't have one now, or it's different
hasChanged = true;

// Remove the old item's modifiers
dataManager.clientEntity().attributeState().removeItemModifiers(previousItem);
dataManager.clientEntity().attributeState().removeItemModifiers(previousItem, equipmentSlot);
} else {
// Item before, and we have the same one now
hasChanged = false;
Expand All @@ -178,10 +177,10 @@ private void applyIfMatches(EquipmentSlot equipmentSlot) {
hasChanged = item != null;
}

if (hasChanged && item != null && item.type().attributeSlot() == equipmentSlot) {
dataManager.clientEntity().attributeState().putItemModifiers(item.type());
if (hasChanged && item != null) {
dataManager.clientEntity().attributeState().putItemModifiers(item, equipmentSlot);
}

lastInEquipment.put(equipmentSlot, item == null ? null : item.type());
lastInEquipment.put(equipmentSlot, item);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.server.protocol.bot.container;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ public static SFItemStack forTypeSingle(ItemType itemType) {
return new SFItemStack(itemType, 1);
}

public static SFItemStack forTypeStack(ItemType itemType) {
return new SFItemStack(itemType, itemType.stackSize());
}

public short getEnchantmentLevel(EnchantmentType enchantment) {
return this.enchantments.getShort(enchantment.key());
public int getEnchantmentLevel(EnchantmentType enchantment) {
return components().getOptional(DataComponentType.ENCHANTMENTS)
.map(enchantments -> {
for (var itemEnchantment : enchantments.getEnchantments().entrySet()) {
if (itemEnchantment.getKey() == enchantment.id()) {
return itemEnchantment.getValue();
}
}

return 0;
})
.orElse(0);
}

public SFItemStack withAmount(int amount) {
Expand Down
Loading

0 comments on commit b6b5954

Please sign in to comment.