-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Space Suite base on GTArmors (#19)
- Loading branch information
Showing
17 changed files
with
397 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/AdvancedNanoMuscleSpaceSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/AdvancedQuarkTechSpaceSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/ISpaceSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/NanoMuscleSpaceSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/QuarkTechSpaceSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/com/ghostipedia/cosmiccore/api/item/armor/SpaceArmorComponentItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/ghostipedia/cosmiccore/api/item/component/FluidStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.