Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void setResponder(Consumer<String> stringConsumer){
}

@Override
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
super.render(graphics, mouseX, mouseY, partialTicks);
protected void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
super.renderWidget(graphics, mouseX, mouseY, partialTicks);
//editBox.render(ms,mouseX,mouseY,partialTicks);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean isMouseOver(double mouseX, double mouseY) {
}

@Override
public void render(@NotNull GuiGraphics ms, int mouseX, int mouseY, float partialTicks) {
protected void renderWidget(@NotNull GuiGraphics ms, int mouseX, int mouseY, float partialTicks) {
if (visible) {
isHovered = isMouseOver(mouseX, mouseY);
beforeRender(ms, mouseX, mouseY, partialTicks);
Expand Down
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you changed thoses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was throwing an error about using render(), the suggested approach was using renderWidget(). But if it works without the change, definitely switch it back

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setMax(int max) {
this.max = max;
}
@Override
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
protected void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
if (visible){
lerpedValue.tickChaser();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.rae.creatingspace.content.life_support.spacesuit;

import com.mojang.serialization.MapCodec;
import com.rae.creatingspace.init.DataComponentsInit;
import com.rae.creatingspace.init.graphics.ShapesInit;
import com.rae.creatingspace.init.ingameobject.BlockEntityInit;
import com.simibubi.create.AllEnchantments;
import com.simibubi.create.foundation.block.IBE;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand All @@ -27,13 +29,16 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -42,6 +47,7 @@
import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.NonnullDefault;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
@NonnullDefault
Expand Down Expand Up @@ -111,12 +117,8 @@ public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable
if (worldIn.isClientSide)
return;
withBlockEntityDo(worldIn, pos, be -> {
//
be.setCapacityEnchantLevel(stack.getEnchantmentLevel(worldIn.holderOrThrow(AllEnchantments.CAPACITY)));
be.setOxygenLevel((int) stack.getOrCreateTag()//TODO implement a DataComponent for Oxygen Level in DataComponentInit
.getFloat("Oxygen"));
if (stack.isEnchanted())
be.setEnchantmentTag(stack.getEnchantmentTags());//TODO look at BacktankBlock
be.setOxygenLevel(stack.getOrDefault(DataComponentsInit.OXYGEN_LEVEL, 0));
if (stack.has(DataComponents.CUSTOM_NAME))
be.setCustomName(stack.getHoverName());
});
Expand Down Expand Up @@ -151,25 +153,15 @@ public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelRead
item = placeable.getActualItem();
}

ItemStack stack = new ItemStack(item);
Optional<OxygenBacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(level, pos);

DataComponentPatch components = blockEntityOptional.map(OxygenBacktankBlockEntity::getComponentPatch)
.orElse(DataComponentPatch.EMPTY);
int air = blockEntityOptional.map(OxygenBacktankBlockEntity::getOxygenLevel)
.orElse(0);
CompoundTag tag = stack.getOrCreateTag(); //TODO DataComponent
tag.putFloat("Oxygen", air);
tag.putFloat("prevOxygen",air);

ListTag enchants = blockEntityOptional.map(OxygenBacktankBlockEntity::getEnchantmentTag)
.orElse(new ListTag());
if (!enchants.isEmpty()) {
ListTag enchantmentTagList = stack.getEnchantmentTags(); //TODO look at BacktankBlock
enchantmentTagList.addAll(enchants);
tag.put("Enchantments", enchantmentTagList);
}

blockEntityOptional.map(OxygenBacktankBlockEntity::getCustomName).ifPresent(stack::setHoverName); //TODO look at BacktankBlock
return stack;
ItemStack stack = new ItemStack(item.builtInRegistryHolder(), 1, components);
stack.set(DataComponentsInit.OXYGEN_LEVEL, air);
return stack;
}

@Override
Expand All @@ -193,4 +185,26 @@ public boolean isPathfindable(BlockState state, PathComputationType type) {
return false;
}

@Override
public List<ItemStack> getDrops(BlockState pState, LootParams.Builder pBuilder) {
List<ItemStack> lootDrops = super.getDrops(pState, pBuilder);

BlockEntity blockEntity = pBuilder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (!(blockEntity instanceof OxygenBacktankBlockEntity bbe))
return lootDrops;

DataComponentPatch components = bbe.getComponentPatch()
.forget(c -> c.equals(DataComponentsInit.OXYGEN_LEVEL));
if (components.isEmpty())
return lootDrops;

return lootDrops.stream()
.peek(stack -> {
if (stack.getItem() instanceof OxygenBacktankItem)
stack.applyComponents(components);
})
.toList();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand Down Expand Up @@ -41,8 +42,9 @@ public class OxygenBacktankBlockEntity extends SmartBlockEntity implements Namea
private Component customName;
private int capacityEnchantLevel;
private ListTag enchantmentTag;
private DataComponentPatch componentPatch;

private final FluidTank OXYGEN_TANK = new FluidTank(1000){
private final FluidTank OXYGEN_TANK = new FluidTank(1000) {
@Override
protected void onContentsChanged() {

Expand All @@ -65,8 +67,8 @@ public static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(
Capabilities.FluidHandler.BLOCK,
BlockEntityInit.OXYGEN_BACKTANK.get(),
(be, context)-> {
if (context == Direction.DOWN){
(be, context) -> {
if (context == Direction.DOWN) {
return be.OXYGEN_TANK;
}
return null;
Expand Down Expand Up @@ -114,23 +116,29 @@ public int getComparatorOutput() {
}
//TODO add DataComponent and remove prevOxygen + timer (I'm not sure we are using it)

public void setComponentPatch(DataComponentPatch componentPatch) {
this.componentPatch = componentPatch;
}

public DataComponentPatch getComponentPatch() {
return componentPatch;
}

@Override
protected void write(CompoundTag compound,HolderLookup.Provider registries, boolean clientPacket) {
super.write(compound,registries, clientPacket);
protected void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
super.write(compound, registries, clientPacket);
compound.putInt("Oxygen", oxygenLevel);
compound.putInt("prevOxygen",prevOxygenLevel);
compound.putInt("prevOxygen", prevOxygenLevel);
compound.putInt("Timer", oxygenLevelTimer);
compound.putInt("CapacityEnchantment", capacityEnchantLevel);
if (this.customName != null)
compound.putString("CustomName", Component.Serializer.toJson(this.customName,registries));
compound.putString("CustomName", Component.Serializer.toJson(this.customName, registries));
compound.put("Enchantments", enchantmentTag);
}

@Override
protected void read(CompoundTag compound,HolderLookup.Provider registries, boolean clientPacket) {
super.read(compound,registries, clientPacket);
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
super.read(compound, registries, clientPacket);
int prev = oxygenLevel;
capacityEnchantLevel = compound.getInt("CapacityEnchantment");
OXYGEN_TANK.setCapacity(OxygenBacktankUtil.maxOxygen(capacityEnchantLevel));
Expand All @@ -151,7 +159,7 @@ protected void playFilledEffect() {
for (int i = 0; i < 360; i += 10) {
Vec3 m = VecHelper.rotate(baseMotion, i, Axis.Y);
Vec3 v = baseVec.add(m.normalize()
.scale(.25f));
.scale(.25f));

level.addParticle(ParticleTypes.SPIT, v.x, v.y, v.z, m.x, m.y, m.z);
}
Expand All @@ -160,7 +168,7 @@ protected void playFilledEffect() {
@Override
public Component getName() {
return this.customName != null ? this.customName
: defaultName;
: defaultName;
}

public int getOxygenLevel() {
Expand All @@ -169,7 +177,7 @@ public int getOxygenLevel() {

public void setOxygenLevel(int oxygenLevel) {
this.oxygenLevel = oxygenLevel;
OXYGEN_TANK.setFluid(new FluidStack(FluidInit.LIQUID_OXYGEN.get(),oxygenLevel));
OXYGEN_TANK.setFluid(new FluidStack(FluidInit.LIQUID_OXYGEN.get(), oxygenLevel));
setChanged();
sendData();
}
Expand All @@ -195,4 +203,4 @@ public void setCapacityEnchantLevel(int capacityEnchantLevel) {
this.OXYGEN_TANK.setCapacity(OxygenBacktankUtil.maxOxygen(capacityEnchantLevel));
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rae.creatingspace.content.life_support.spacesuit;

import com.rae.creatingspace.init.DataComponentsInit;
import com.simibubi.create.foundation.item.LayeredArmorItem;
import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -29,20 +30,6 @@ public OxygenBacktankItem(Holder<ArmorMaterial> material, Properties properties,
this.blockItem = placeable;
}

@Override
public void inventoryTick(ItemStack backtank, Level level, Entity entity, int nbr, boolean isMoving) {
CompoundTag tag = backtank.getOrCreateTag();//TODO data component + remove the prev oxygenLevel and toUpdate as we don't need it.

float o2amount = tag.getFloat("Oxygen");
float prevO2amount = tag.getFloat("prevOxygen");
boolean toUpdate = tag.getBoolean("toUpdate");
if (toUpdate) {
tag.putFloat("prevOxygen",o2amount);
tag.putBoolean("toUpdate", false);
}
// may be ? -> in the ticking entity logic make the server update the itemstack -> here don't now what is before and after
}

@Nullable
public static OxygenBacktankItem getWornBy(Entity entity) {
if (!(entity instanceof LivingEntity livingEntity)) {
Expand All @@ -60,7 +47,6 @@ public static OxygenBacktankItem getWornBy(Entity entity) {
.useOn(ctx);
}

@Override
public boolean canBeDepleted() {
return false;
}
Expand Down Expand Up @@ -89,9 +75,8 @@ public Block getBlock() {
return blockItem.get().getBlock();
}

public static float getRemainingAir(ItemStack stack) {
CompoundTag orCreateTag = stack.getOrCreateTag();//TODO DataComponent
return orCreateTag.getFloat("Oxygen");
public static int getRemainingAir(ItemStack stack) {
return stack.getOrDefault(DataComponentsInit.OXYGEN_LEVEL, 0);
}

public static class O2BacktankBlockItem extends BlockItem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rae.creatingspace.content.life_support.spacesuit;

import com.rae.creatingspace.init.DataComponentsInit;
import com.rae.creatingspace.init.TagsInit;
import com.simibubi.create.AllEnchantments;
import com.simibubi.create.AllSoundEvents;
Expand Down Expand Up @@ -62,19 +63,15 @@ public static boolean hasOxygenRemaining(ItemStack backtank) {
return getOxygen(backtank) > 0;
}

public static float getOxygen(ItemStack backtank) {
CompoundTag tag = backtank.getOrCreateTag();//TODO DataComponent
return Math.min(tag.getFloat("Oxygen"), maxOxygen(backtank));
public static int getOxygen(ItemStack backtank) {
return Math.min(backtank.getOrDefault(DataComponentsInit.OXYGEN_LEVEL, 0), maxOxygen(backtank));
}

public static void consumeOxygen(LivingEntity entity, ItemStack backtank, int i) {
CompoundTag tag = backtank.getOrCreateTag();
int maxOxygen = maxOxygen(backtank);
float oxygen = getOxygen(backtank);
float newOxygen = Math.max(oxygen - i, 0);
tag.putFloat("Oxygen", Math.min(newOxygen, maxOxygen));
tag.putBoolean("toUpdate",true);
backtank.setTag(tag);
int oxygen = getOxygen(backtank);
int newOxygen = Math.max(oxygen - i, 0);
backtank.set(DataComponentsInit.OXYGEN_LEVEL, Math.min(newOxygen, maxOxygen));

if (!(entity instanceof ServerPlayer player))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.rae.creatingspace.api.gui.elements.SliderWidget;
import com.rae.creatingspace.configs.CSConfigs;
import com.rae.creatingspace.init.DataComponentsInit;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.LayeredDraw;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -35,9 +37,7 @@ public void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
ItemStack itemInChestSlot = player.getItemBySlot(EquipmentSlot.CHEST);

if (itemInChestSlot.getItem() instanceof OxygenBacktankItem){
CompoundTag tag = itemInChestSlot.getOrCreateTag();//TODO DataComponents
float o2Value = tag.getFloat("Oxygen");

int o2Value = itemInChestSlot.getOrDefault(DataComponentsInit.OXYGEN_LEVEL, 0);
gauge.setMax(OxygenBacktankUtil.maxOxygen(itemInChestSlot));
gauge.setChase((int) o2Value);
gauge.render(graphics, (int) mc.mouseHandler.xpos(),(int) mc.mouseHandler.ypos() ,deltaTracker.getRealtimeDeltaTicks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void breatheUnderwater(EntityTickEvent.Pre event) {
entity.getPersistentData()
.putInt("VisualBacktankAir", Math.round(O2Backtanks.stream()
.map(OxygenBacktankUtil::getOxygen)
.reduce(0f, Float::sum)));
.reduce(0, Integer::sum)));

if (!second)
return;
Expand Down
Loading