Skip to content

Commit 003cfbf

Browse files
more todo
1 parent 3f6a86e commit 003cfbf

File tree

5 files changed

+46
-40
lines changed

5 files changed

+46
-40
lines changed

src/main/java/com/rae/creatingspace/content/event/DataEventHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import net.minecraft.resources.ResourceKey;
1111
import net.minecraft.world.entity.player.Player;
1212
import net.minecraft.world.level.LevelAccessor;
13-
import net.minecraftforge.event.entity.player.PlayerEvent;
14-
import net.minecraftforge.event.level.LevelEvent;
15-
import net.minecraftforge.event.server.ServerStartedEvent;
16-
import net.minecraftforge.eventbus.api.SubscribeEvent;
17-
import net.minecraftforge.fml.common.Mod;
13+
import net.neoforged.bus.api.SubscribeEvent;
14+
import net.neoforged.fml.common.EventBusSubscriber;
15+
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
16+
import net.neoforged.neoforge.event.level.LevelEvent;
17+
import net.neoforged.neoforge.event.server.ServerStartedEvent;
1818
import org.apache.logging.log4j.LogManager;
1919
import org.apache.logging.log4j.Logger;
2020

2121
import java.util.Objects;
2222

23-
@Mod.EventBusSubscriber(modid = CreatingSpace.MODID)
23+
@EventBusSubscriber(modid = CreatingSpace.MODID)
2424
public class DataEventHandler {
2525
//if it's null, then your server is distant and your on the client
2626
private static final Logger LOGGER = LogManager.getLogger();

src/main/java/com/rae/creatingspace/content/planets/CustomDimensionEffects.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.mojang.blaze3d.systems.RenderSystem;
44
import com.mojang.blaze3d.vertex.*;
55
import com.mojang.math.Axis;
6+
import net.neoforged.api.distmarker.Dist;
7+
import net.neoforged.api.distmarker.OnlyIn;
68
import org.joml.Matrix4f;
79
import org.joml.Vector3f;
810
import net.minecraft.client.Camera;
@@ -13,10 +15,9 @@
1315
import net.minecraft.core.BlockPos;
1416
import net.minecraft.resources.ResourceLocation;
1517
import net.minecraft.world.phys.Vec3;
16-
import net.minecraftforge.api.distmarker.Dist;
17-
import net.minecraftforge.api.distmarker.OnlyIn;
1818

1919
public abstract class CustomDimensionEffects extends DimensionSpecialEffects {
20+
//TODO replace with ResourceLocation.parse(), or CreatingSpace.resource()
2021
private static final ResourceLocation SPACE_SKY_LOCATION = new ResourceLocation("creatingspace", "textures/environment/space_sky.png");
2122
private static final ResourceLocation EARTH_LOCATION = new ResourceLocation("creatingspace", "textures/environment/earth.png");
2223
private static final ResourceLocation MOON_LOCATION = new ResourceLocation("creatingspace", "textures/environment/moon.png");
@@ -44,9 +45,7 @@ private static BufferBuilder renderSpaceSky(PoseStack poseStack) {
4445
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
4546
RenderSystem.setShaderTexture(0, SPACE_SKY_LOCATION);
4647
Tesselator tesselator = Tesselator.getInstance();
47-
BufferBuilder bufferbuilder = tesselator.getBuilder();
48-
49-
48+
BufferBuilder bufferbuilder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);//Only position and uv to set.
5049
for(int i = 0; i < 6; ++i) {
5150
poseStack.pushPose();
5251
//make all the face
@@ -79,13 +78,14 @@ private static BufferBuilder renderSpaceSky(PoseStack poseStack) {
7978

8079
float size = 100.0F;
8180
float distance = 100.0F;
81+
//this is the standard brut force way to draw a square with a texture
82+
// uv is the coordinates on the texture and the addVertex takes the perspective matrix and the 3 position
8283
Matrix4f matrix4f = poseStack.last().pose();
83-
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
84-
bufferbuilder.vertex(matrix4f, -size, -distance, -size).uv(col_end, l_end).color(255,255,255,255).endVertex();
85-
bufferbuilder.vertex(matrix4f, -size, -distance, size).uv(col_begin, l_end).color(255,255,255,255).endVertex();
86-
bufferbuilder.vertex(matrix4f, size, -distance, size).uv(col_begin, l_begin).color(255,255,255,255).endVertex();
87-
bufferbuilder.vertex(matrix4f, size, -distance, -size).uv(col_end, l_begin).color(255,255,255,255).endVertex();
88-
BufferUploader.drawWithShader(bufferbuilder.end());
84+
bufferbuilder.addVertex(matrix4f, -size, -distance, -size).setUv(col_end, l_end);
85+
bufferbuilder.addVertex(matrix4f, -size, -distance, size).setUv(col_begin, l_end);
86+
bufferbuilder.addVertex(matrix4f, size, -distance, size).setUv(col_begin, l_begin);
87+
bufferbuilder.addVertex(matrix4f, size, -distance, -size).setUv(col_end, l_begin);
88+
BufferUploader.drawWithShader(bufferbuilder.buildOrThrow());
8989
//tesselator.end();
9090
poseStack.popPose();
9191
}
@@ -233,6 +233,7 @@ protected void renderAstralBody(PoseStack poseStack, BufferBuilder bufferbuilder
233233
Matrix4f matrix4f = poseStack.last().pose();
234234
RenderSystem.setShader(GameRenderer::getPositionTexShader);
235235
RenderSystem.setShaderTexture(0, bodyTexture);
236+
//TODO same as end of renderSpaceSky
236237
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
237238
bufferbuilder.vertex(matrix4f, -bodySize, bodyDistance, -bodySize).uv(f15, f14).endVertex();
238239
bufferbuilder.vertex(matrix4f, bodySize, bodyDistance, -bodySize).uv(f13, f14).endVertex();

src/main/java/com/rae/creatingspace/content/ponders/CustomProcessingScene.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import net.minecraft.nbt.CompoundTag;
1919
import net.minecraft.world.item.Items;
2020
import net.minecraft.world.phys.Vec3;
21-
import net.minecraftforge.fluids.FluidStack;
21+
import net.neoforged.neoforge.fluids.FluidStack;
2222

2323
public class CustomProcessingScene {
2424
public static void electrolysis(SceneBuilder builder, SceneBuildingUtil util) {
@@ -64,8 +64,8 @@ public static void electrolysis(SceneBuilder builder, SceneBuildingUtil util) {
6464
nbt.put("VisualizedFluids",
6565
NBTHelper.writeCompoundList(ImmutableList.of(
6666
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_HYDROGEN.get(), 160)),
67-
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_OXYGEN.get(), 80))), ia -> ia.getValue()
68-
.writeToNBT(new CompoundTag())));
67+
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_OXYGEN.get(), 80))), ia -> (CompoundTag) ia.getValue()
68+
.saveOptional(scene.world().getHolderLookupProvider())));
6969
});
7070
scene.idle(4);
7171
//scene.world.createItemOnBelt(util.grid.at(1, 1, 1), Direction.UP, purple);
@@ -146,8 +146,8 @@ public static void chemical(SceneBuilder builder, SceneBuildingUtil util) {
146146
nbt.put("VisualizedFluids",
147147
NBTHelper.writeCompoundList(ImmutableList.of(
148148
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_HYDROGEN.get(), 286)),
149-
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_CO2.get(), 100))), ia -> ia.getValue()
150-
.writeToNBT(new CompoundTag())));
149+
IntAttached.with(10, new FluidStack(FluidInit.LIQUID_CO2.get(), 100))), ia ->
150+
(CompoundTag) ia.getValue().saveOptional(scene.world().getHolderLookupProvider())));
151151
});
152152
scene.idle(4);
153153
//scene.world.createItemOnBelt(util.grid.at(1, 1, 1), Direction.UP, purple);

src/main/java/com/rae/creatingspace/content/rocket/CustomTeleporter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import net.minecraft.server.level.ServerLevel;
55
import net.minecraft.server.level.ServerPlayer;
66
import net.minecraft.world.entity.Entity;
7-
import net.minecraft.world.level.portal.PortalInfo;
87
import net.minecraft.world.phys.Vec3;
9-
import net.minecraftforge.common.util.ITeleporter;
108
import org.jetbrains.annotations.Nullable;
119

1210
import java.util.function.Function;
13-
11+
//TODO ask Chatgpt
1412
public class CustomTeleporter implements ITeleporter {
1513
protected final ServerLevel level;
1614

src/main/java/com/rae/creatingspace/content/rocket/engine/design/DesignBlueprintItem.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.rae.creatingspace.content.rocket.engine.design;
22

33
import com.rae.creatingspace.legacy.saved.UnlockedDesignManager;
4+
import net.minecraft.core.component.DataComponents;
45
import net.minecraft.nbt.CompoundTag;
56
import net.minecraft.nbt.NbtOps;
67
import net.minecraft.network.chat.Component;
@@ -11,7 +12,9 @@
1112
import net.minecraft.world.item.Item;
1213
import net.minecraft.world.item.ItemStack;
1314
import net.minecraft.world.item.TooltipFlag;
15+
import net.minecraft.world.item.component.CustomData;
1416
import net.minecraft.world.level.Level;
17+
import net.neoforged.neoforge.registries.DeferredRegister;
1518
import org.jetbrains.annotations.Nullable;
1619

1720
import java.util.List;
@@ -24,21 +27,25 @@ public DesignBlueprintItem(Properties properties) {
2427
super(properties);
2528
}
2629

30+
2731
@Override
28-
public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Component> components, TooltipFlag flag) {
29-
CompoundTag nbt = itemStack.getOrCreateTag();
30-
ResourceLocation registry = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
31-
nbt.get("design_type")).result().orElse(null);
32-
ResourceLocation location = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
33-
nbt.get("design")).result().orElse(null);
34-
if (registry != null) {
35-
components.add(Component.translatable(registry.toLanguageKey())
36-
.append(" : ")
37-
.append(Component.translatable(
38-
registry.getPath() + "." +
39-
location.getNamespace() + "." + location.getPath())));
32+
public void appendHoverText(ItemStack itemStack, TooltipContext context, List<Component> components, TooltipFlag flag) {
33+
CustomData data = itemStack.get(DataComponents.CUSTOM_DATA);
34+
if ( data!=null) {
35+
CompoundTag nbt =data.copyTag();
36+
ResourceLocation registry = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
37+
nbt.get("design_type")).result().orElse(null);
38+
ResourceLocation location = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
39+
nbt.get("design")).result().orElse(null);
40+
if (registry != null) {
41+
components.add(Component.translatable(registry.toLanguageKey())
42+
.append(" : ")
43+
.append(Component.translatable(
44+
registry.getPath() + "." +
45+
location.getNamespace() + "." + location.getPath())));
46+
}
47+
super.appendHoverText(itemStack, context, components, flag);
4048
}
41-
super.appendHoverText(itemStack, level, components, flag);
4249
}
4350

4451
/*@Override
@@ -71,7 +78,7 @@ public void fillItemCategory(CreativeModeTab modeTab, NonNullList<ItemStack> ite
7178
@Override
7279
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionHand) {
7380
ItemStack stack = player.getItemInHand(interactionHand);
74-
CompoundTag nbt = stack.getOrCreateTag();
81+
CompoundTag nbt = stack.getOrCreateTag();//TODO replace with a data component call with null check -> same as in first methode
7582
ResourceLocation registry = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
7683
nbt.get("design_type")).result().orElse(null);
7784
ResourceLocation location = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
@@ -92,7 +99,7 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera
9299
}
93100

94101
private static void save(ItemStack stack, Player player) {
95-
CompoundTag nbt = stack.getOrCreateTag();
102+
CompoundTag nbt = stack.getOrCreateTag();//TODO replace with a data component call with null check
96103
ResourceLocation registry = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,
97104
nbt.get("design_type")).result().orElse(null);
98105
ResourceLocation location = ResourceLocation.CODEC.parse(NbtOps.INSTANCE,

0 commit comments

Comments
 (0)