Skip to content

Commit

Permalink
Add Space Suite base on GTArmors (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrquentin authored May 20, 2024
1 parent 65c23e4 commit 0b08bf8
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 13 deletions.
11 changes: 3 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ loom {
// this will be added to the jar manifest as well!
mixinConfigs = [
"cosmiccore.mixins.json"

]

// missing access transformers?
Expand All @@ -47,12 +46,7 @@ loom {
runConfigs.named("data").configure {
programArg("--existing=" + file("src/main/resources").absolutePath)
programArgs("--client", "--server")



}


}

repositories {
Expand Down Expand Up @@ -165,10 +159,11 @@ dependencies {
// Mixin Extras
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${project.mixinextras_version}"))
implementation(include("io.github.llamalad7:mixinextras-forge:${project.mixinextras_version}"))
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'

// lombok
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.gregtechceu.gtceu.common.item.armor.AdvancedNanoMuscleSuite;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class AdvancedNanoMuscleSpaceSuite extends AdvancedNanoMuscleSuite implements ISpaceSuite {

public AdvancedNanoMuscleSpaceSuite(int energyPerUse, long capacity, int tier) {
super(energyPerUse, capacity, tier);
}

@Override
public void onArmorTick(Level world, Player player, ItemStack itemStack) {
super.onArmorTick(world, player, itemStack);
onArmorTick(world, player, itemStack, type);
}

@Override
public void addInfo(ItemStack itemStack, List<Component> lines) {
super.addInfo(itemStack, lines);
addInfo(itemStack, lines, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.gregtechceu.gtceu.common.item.armor.AdvancedQuarkTechSuite;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class AdvancedQuarkTechSpaceSuite extends AdvancedQuarkTechSuite implements ISpaceSuite {

public AdvancedQuarkTechSpaceSuite(int energyPerUse, long capacity, int tier) {
super(energyPerUse, capacity, tier);
}

@Override
public void onArmorTick(Level world, Player player, ItemStack itemStack) {
super.onArmorTick(world, player, itemStack);
onArmorTick(world, player, itemStack, type);
}

@Override
public void addInfo(ItemStack itemStack, List<Component> lines) {
super.addInfo(itemStack, lines);
addInfo(itemStack, lines, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.ghostipedia.cosmiccore.common.data.tag.item.CosmicItemTags;
import earth.terrarium.adastra.api.systems.OxygenApi;
import earth.terrarium.adastra.common.constants.ConstantComponents;
import earth.terrarium.adastra.common.registry.ModFluids;
import earth.terrarium.adastra.common.utils.FluidUtils;
import earth.terrarium.adastra.common.utils.TooltipUtils;
import earth.terrarium.botarium.common.fluid.FluidConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;
import java.util.stream.StreamSupport;

public interface ISpaceSuite {

default void tickOxygen(Level Level, Player player, ItemStack itemStack) {
if (Level.isClientSide) return;
if (player.isCreative() || player.isSpectator()) return;
if (!(itemStack.getItem() instanceof SpaceArmorComponentItem suit)) return;
if (!hasFullNanoSet(player) && !hasFullQuantumSet(player)) return;
player.setTicksFrozen(0);
if (player.tickCount % 12 == 0 && suit.hasOxygen(player)) {
if (!OxygenApi.API.hasOxygen(player)) suit.consumeOxygen(itemStack, 1);
if (player.isEyeInFluid(FluidTags.WATER)) {
suit.consumeOxygen(itemStack, 1);
player.setAirSupply(Math.min(player.getMaxAirSupply(), player.getAirSupply() + 4 * 10));
}
}
}

static boolean hasFullNanoSet(LivingEntity entity) {
return hasFullSet(entity, CosmicItemTags.NANOMUSCLE_SPACE_SUITE);
}

static boolean hasFullQuantumSet(LivingEntity entity) {
return hasFullSet(entity, CosmicItemTags.QUARKTECH_SPACE_SUITE);
}

static boolean hasFullSet(LivingEntity entity, TagKey<Item> tagKey) {
return StreamSupport.stream(entity.getArmorSlots().spliterator(), false)
.allMatch(itemStack -> itemStack.is(tagKey));
}


default void onArmorTick(Level Level, Player player, ItemStack itemStack, ArmorItem.Type type) {
if (type == ArmorItem.Type.CHESTPLATE) this.tickOxygen(Level, player, itemStack);
}

default void addInfo(ItemStack itemStack, List<Component> lines, ArmorItem.Type type) {
if (type == ArmorItem.Type.CHESTPLATE && itemStack.getItem() instanceof SpaceArmorComponentItem suit) {
lines.add(TooltipUtils.getFluidComponent(
FluidUtils.getTank(itemStack),
FluidConstants.fromMillibuckets(suit.getFluidContainer(itemStack).getTankCapacity(0)),
ModFluids.OXYGEN.get()));
TooltipUtils.addDescriptionComponent(lines, ConstantComponents.SPACE_SUIT_INFO);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.gregtechceu.gtceu.common.item.armor.NanoMuscleSuite;
import earth.terrarium.adastra.common.constants.ConstantComponents;
import earth.terrarium.adastra.common.registry.ModFluids;
import earth.terrarium.adastra.common.utils.FluidUtils;
import earth.terrarium.adastra.common.utils.TooltipUtils;
import earth.terrarium.botarium.common.fluid.FluidConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class NanoMuscleSpaceSuite extends NanoMuscleSuite implements ISpaceSuite {

public NanoMuscleSpaceSuite(ArmorItem.Type slot, int energyPerUse, long maxCapacity, int tier) {
super(slot, energyPerUse, maxCapacity, tier);
}

@Override
public void onArmorTick(Level world, Player player, ItemStack itemStack) {
super.onArmorTick(world, player, itemStack);
onArmorTick(world, player, itemStack, type);
}

@Override
public void addInfo(ItemStack itemStack, List<Component> lines) {
super.addInfo(itemStack, lines);
addInfo(itemStack, lines, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.gregtechceu.gtceu.common.item.armor.QuarkTechSuite;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class QuarkTechSpaceSuite extends QuarkTechSuite implements ISpaceSuite{

public QuarkTechSpaceSuite(ArmorItem.Type slot, int energyPerUse, long capacity, int tier) {
super(slot, energyPerUse, capacity, tier);
}

@Override
public void onArmorTick(Level world, Player player, ItemStack itemStack) {
super.onArmorTick(world, player, itemStack);
onArmorTick(world, player, itemStack, type);
}

@Override
public void addInfo(ItemStack itemStack, List<Component> lines) {
super.addInfo(itemStack, lines);
addInfo(itemStack, lines, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.ghostipedia.cosmiccore.api.item.armor;

import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem;
import com.gregtechceu.gtceu.api.item.armor.IArmorLogic;
import com.gregtechceu.gtceu.api.item.component.IDurabilityBar;
import com.gregtechceu.gtceu.api.item.component.IItemComponent;
import earth.terrarium.adastra.common.tags.ModFluidTags;
import earth.terrarium.adastra.common.utils.FluidUtils;
import earth.terrarium.botarium.common.fluid.FluidConstants;
import earth.terrarium.botarium.common.fluid.base.BotariumFluidItem;
import earth.terrarium.botarium.common.fluid.base.FluidContainer;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.impl.SimpleFluidContainer;
import earth.terrarium.botarium.common.fluid.impl.WrappedItemFluidContainer;
import earth.terrarium.botarium.common.fluid.utils.ClientFluidHooks;
import earth.terrarium.botarium.common.item.ItemStackHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;

import java.util.List;

public class SpaceArmorComponentItem extends ArmorComponentItem implements BotariumFluidItem<WrappedItemFluidContainer> {

protected final long tankSize;

public SpaceArmorComponentItem(ArmorMaterial material, Type type, long size, Properties properties) {
super(material, type, properties);
this.tankSize = size;
}

@Override
public void attachComponents(IItemComponent... components) {
super.attachComponents(components);

IDurabilityBar durabilityBar = new IDurabilityBar() {
@Override
public int getBarColor(ItemStack stack) {
return ClientFluidHooks.getFluidColor(FluidUtils.getTank(stack));
}

@Override
public int getBarWidth(ItemStack stack) {
var fluidContainer = getFluidContainer(stack);
return (int) (((double) fluidContainer.getFirstFluid().getFluidAmount() / fluidContainer.getTankCapacity(0)) * 13);
}

@Override
public boolean isBarVisible(ItemStack stack) {
return FluidUtils.hasFluid(stack);
}

@Override
public boolean showEmptyBar(ItemStack itemStack) {
return false;
}
};

this.components.add(durabilityBar);
durabilityBar.onAttached(this);
}

public SpaceArmorComponentItem setArmorLogic(IArmorLogic armorLogic) {
return (SpaceArmorComponentItem) super.setArmorLogic(armorLogic);
}

@Override
public WrappedItemFluidContainer getFluidContainer(ItemStack holder) {
return new WrappedItemFluidContainer(holder,
new SimpleFluidContainer(FluidConstants.fromMillibuckets(tankSize), 1, (t, f) -> f.is(ModFluidTags.OXYGEN)));
}

public long getOxygenAmount(Entity entity) {
if (!(entity instanceof LivingEntity livingEntity)) return 0;
var stack = livingEntity.getItemBySlot(EquipmentSlot.CHEST);
if (!(stack.getItem() instanceof SpaceArmorComponentItem suit)) return 0;
return suit.getFluidContainer(stack).getFirstFluid().getFluidAmount();
}

public boolean hasOxygen(Entity entity) {
return getOxygenAmount(entity) > FluidConstants.fromMillibuckets(1);
}

public void consumeOxygen(ItemStack stack, long amount) {
ItemStackHolder holder = new ItemStackHolder(stack);
var container = FluidContainer.of(holder);
if (container == null) return;
FluidHolder extracted = container.extractFluid(container.getFirstFluid().copyWithAmount(FluidConstants.fromMillibuckets(amount)), false);
if (holder.isDirty() || extracted.getFluidAmount() > 0) stack.setTag(holder.getStack().getTag());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ghostipedia.cosmiccore.api.item.component;

import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;

public class FluidStats {
public FluidStats() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import com.ghostipedia.cosmiccore.api.registries.CosmicRegistration;
import com.ghostipedia.cosmiccore.common.data.lang.CosmicLangHandler;
import com.ghostipedia.cosmiccore.common.data.tag.CosmicTagsHandler;
import com.gregtechceu.gtceu.common.registry.GTRegistration;
import com.gregtechceu.gtceu.data.tags.TagsHandler;
import com.tterrag.registrate.providers.ProviderType;

public class CosmicCoreDatagen {

public static void init() {
//TODO: IDK IF I NEED THESE YET, MIGHT BE NEEDED IDK
// CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.ITEM_TAGS, TagsHandler::initItem);
// CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.BLOCK_TAGS, TagsHandler::initBlock);
// CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.FLUID_TAGS, TagsHandler::initFluid);
// CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.ENTITY_TAGS, TagsHandler::initEntity);
CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.ITEM_TAGS, CosmicTagsHandler::initItem);
CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.BLOCK_TAGS, CosmicTagsHandler::initBlock);
CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.FLUID_TAGS, CosmicTagsHandler::initFluid);
CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.ENTITY_TAGS, CosmicTagsHandler::initEntity);
CosmicRegistration.REGISTRATE.addDataGenerator(ProviderType.LANG, CosmicLangHandler::init);
}

}
Loading

0 comments on commit 0b08bf8

Please sign in to comment.