Skip to content

Commit

Permalink
hazard protection curios support (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
screret authored Aug 21, 2024
1 parent 3f1d7b5 commit c5e9766
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 31 deletions.
6 changes: 5 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {

// EMI
modCompileOnly("dev.emi:emi-forge:${forge.versions.emi.get()}:api")

modImplementation forge.emi

// TOP
Expand All @@ -49,6 +50,9 @@ dependencies {
// Jade
modImplementation(forge.jade)

modCompileOnly("top.theillusivec4.curios:curios-forge:${forge.versions.curios.get()}:api")
modRuntimeOnly("top.theillusivec4.curios:curios-forge:${forge.versions.curios.get()}")

// AE2
modImplementation(forge.ae2) { transitive = false }
modCompileOnly("curse.maven:ae2wtlib-459929:5217955")
Expand Down Expand Up @@ -78,4 +82,4 @@ dependencies {

// Runtime only testing mods
//modRuntimeOnly(forge.worldStripper)
}
}
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencyResolutionManagement {
def flywheelForgeVersion = "0.6.10-10"
def topForgeVersion = "1.20.1-10.0.1-3"
def jadeForgeVersion = "11.6.3"
def curiosForgeVersion = "5.9.1"
def worldStripperForgeFile = "4578579"
def javdVersion = "4803995"

Expand Down Expand Up @@ -86,6 +87,9 @@ dependencyResolutionManagement {
def theoneprobe = version("theoneprobe", topForgeVersion)
library("theoneprobe", "mcjty.theoneprobe", "theoneprobe").versionRef(theoneprobe)

def curios = version("curios", curiosForgeVersion + "+" + minecraftVersion)
library("curios", "top.theillusivec4.curios", "curios-forge").versionRef(curios)

def jade = version("jade", jadeForgeVersion)
library("jade", "maven.modrinth", "jade").versionRef(jade)

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public static boolean isAE2Loaded() {
return LDLib.isModLoaded(GTValues.MODID_APPENG);
}

public static boolean isAlmostUnifiedLoaded() {
return LDLib.isModLoaded(GTValues.MODID_ALMOSTUNIFIED);
public static boolean isCuriosLoaded() {
return LDLib.isModLoaded(GTValues.MODID_CURIOS);
}

public static boolean isShimmerLoaded() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.data.chemical.material.properties;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
Expand All @@ -13,12 +14,17 @@

import net.minecraft.util.StringRepresentable;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.ItemStack;

import lombok.Getter;
import org.jetbrains.annotations.Nullable;
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.SlotResult;
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler;

import java.util.*;

Expand Down Expand Up @@ -79,15 +85,25 @@ public String getSerializedName() {

public enum ProtectionType {

MASK(ArmorItem.Type.HELMET),
HANDS(ArmorItem.Type.CHESTPLATE),
FULL(ArmorItem.Type.BOOTS, ArmorItem.Type.HELMET, ArmorItem.Type.CHESTPLATE, ArmorItem.Type.LEGGINGS),
NONE();
MASK(Set.of("head"), ArmorItem.Type.HELMET),
HANDS(Set.of("hands"), ArmorItem.Type.CHESTPLATE),
FULL(Set.of(), ArmorItem.Type.BOOTS, ArmorItem.Type.HELMET, ArmorItem.Type.CHESTPLATE, ArmorItem.Type.LEGGINGS),
NONE(Set.of());

@Getter
private final Set<ArmorItem.Type> equipmentTypes;

ProtectionType(ArmorItem.Type... equipmentTypes) {
@Getter
private final Set<String> curioSlots;

/**
* Equipment validity is treated in an OR fashion.
* that is, EITHER all curio slots are valid, OR all equipment slots are valid.
*
* @param curioSlots curio slot names to test for
* @param equipmentTypes armor slots to test for
*/
ProtectionType(Set<String> curioSlots, ArmorItem.Type... equipmentTypes) {
this.curioSlots = curioSlots;
this.equipmentTypes = Set.of(equipmentTypes);
}

Expand All @@ -104,7 +120,60 @@ public boolean isProtected(LivingEntity livingEntity) {
correctArmorItems.add(equipmentType);
}
}
return correctArmorItems.containsAll(equipmentTypes);
if (!GTCEu.isCuriosLoaded() || this.curioSlots.isEmpty()) {
return correctArmorItems.containsAll(equipmentTypes);
}
Set<String> correctCurios = new HashSet<>();
ICuriosItemHandler curiosInventory = CuriosApi.getCuriosInventory(livingEntity)
.resolve()
.orElse(null);
if (curiosInventory == null) {
return correctArmorItems.containsAll(equipmentTypes);
}
List<SlotResult> results = curiosInventory.findCurios(this.curioSlots.toArray(String[]::new));
for (SlotResult result : results) {
ItemStack armor = result.stack();
if (!armor.isEmpty() && ((armor.getItem() instanceof ArmorComponentItem armorItem &&
armorItem.getArmorLogic().isPPE()) ||
armor.getTags().anyMatch(tag -> tag.equals(CustomTags.PPE_ARMOR)))) {
correctCurios.add(result.slotContext().identifier());
}
}
return correctArmorItems.containsAll(equipmentTypes) || correctCurios.containsAll(curioSlots);
}

public void damageEquipment(Player player, int amount) {
// entity has proper safety equipment, so damage it per material every 5 seconds.
if (player.level().getGameTime() % 100 == 0) {
for (ArmorItem.Type type : this.getEquipmentTypes()) {
ItemStack armor = player.getItemBySlot(type.getSlot());
if (!armor.isEmpty() && ((armor.getItem() instanceof ArmorComponentItem armorItem &&
armorItem.getArmorLogic().isPPE()) ||
armor.getTags().anyMatch(tag -> tag.equals(CustomTags.PPE_ARMOR)))) {
armor.hurtAndBreak(amount, player, p -> p.broadcastBreakEvent(type.getSlot()));
}
}
if (GTCEu.isCuriosLoaded()) {
ICuriosItemHandler curiosInventory = CuriosApi.getCuriosInventory(player)
.resolve()
.orElse(null);
if (curiosInventory != null) {
for (String curioItem : this.getCurioSlots()) {
curiosInventory.getStacksHandler(curioItem).ifPresent(handler -> {
IDynamicStackHandler stackHandler = handler.getStacks();
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack armor = stackHandler.getStackInSlot(i);
if (!armor.isEmpty() && ((armor.getItem() instanceof ArmorComponentItem armorItem &&
armorItem.getArmorLogic().isPPE()) ||
armor.getTags().anyMatch(tag -> tag.equals(CustomTags.PPE_ARMOR)))) {
armor.hurtAndBreak(amount, player, p -> {});
}
}
});
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.saveddata.SavedData;
Expand Down Expand Up @@ -149,12 +148,7 @@ public void tickPlayerHazards(final HazardZone zone, Stream<ServerPlayer> player
playerStream.forEach(player -> {
if (zone.trigger().protectionType().isProtected(player)) {
// entity has proper safety equipment, so damage it per material every 5 seconds.
if (player.level().getGameTime() % 100 == 0) {
for (ArmorItem.Type type : zone.trigger().protectionType().getEquipmentTypes()) {
player.getItemBySlot(type.getSlot()).hurtAndBreak(1, player,
p -> p.broadcastBreakEvent(type.getSlot()));
}
}
zone.trigger().protectionType().damageEquipment(player, 1);
// don't progress this material condition if entity is protected
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.level.saveddata.SavedData;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
Expand Down Expand Up @@ -115,12 +114,7 @@ public void tickPlayerHazards(final HazardZone zone, Stream<ServerPlayer> player
playerStream.forEach(player -> {
if (zone.trigger().protectionType().isProtected(player)) {
// entity has proper safety equipment, so damage it per material every 5 seconds.
if (player.level().getGameTime() % 100 == 0) {
for (ArmorItem.Type type : zone.trigger().protectionType().getEquipmentTypes()) {
player.getItemBySlot(type.getSlot()).hurtAndBreak(1, player,
p -> p.broadcastBreakEvent(type.getSlot()));
}
}
zone.trigger().protectionType().damageEquipment(player, 1);
// don't progress this material condition if entity is protected
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -187,12 +186,7 @@ public static void tickPlayerInventoryHazards(TickEvent.PlayerTickEvent event) {
HazardProperty property = material.getProperty(PropertyKey.HAZARD);
if (property.hazardTrigger.protectionType().isProtected(player)) {
// entity has proper safety equipment, so damage it per material every 5 seconds.
if (player.level().getGameTime() % 100 == 0) {
for (ArmorItem.Type type : property.hazardTrigger.protectionType().getEquipmentTypes()) {
player.getItemBySlot(type.getSlot()).hurtAndBreak(1, player,
p -> p.broadcastBreakEvent(type.getSlot()));
}
}
property.hazardTrigger.protectionType().damageEquipment(player, 1);
// don't progress this material condition if entity is protected
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/data/gtceu/curios/entities/hands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["hands"]
}
4 changes: 4 additions & 0 deletions src/main/resources/data/gtceu/curios/entities/head.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["head"]
}

0 comments on commit c5e9766

Please sign in to comment.