Skip to content

Commit 960faf0

Browse files
additional asteroid work
Signed-off-by: Real Ant Engineer <[email protected]>
1 parent 8d009ae commit 960faf0

File tree

19 files changed

+384
-63
lines changed

19 files changed

+384
-63
lines changed

src/main/java/com/rae/creatingspace/api/contraption/Synced2AxisContraptionEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@
4040
* more abstract version of OrientedContraptionEntity, doubled with a sync packet for smooth animation.
4141
*/
4242
public abstract class Synced2AxisContraptionEntity extends AbstractContraptionEntity {
43+
44+
4345
private float yaw;
4446
private float pitch;
47+
public float getYaw() {
48+
return yaw;
49+
}
50+
51+
public float getPitch() {
52+
return pitch;
53+
}
4554
private LinearLerpedVec3 speed = new LinearLerpedVec3(0,0,0);
4655
private @NotNull Vec3 posClientDiff = Vec3.ZERO;
4756
private @NotNull Vec2 rotSpeed = Vec2.ZERO;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import com.rae.creatingspace.content.life_support.spacesuit.NetheriteOxygenBacktankFirstPersonRenderer;
66
import com.rae.creatingspace.configs.CSConfigs;
77
import com.rae.creatingspace.content.life_support.spacesuit.OxygenBacktankArmorLayer;
8+
import com.rae.creatingspace.content.rocket.RocketHUD;
89
import com.rae.creatingspace.content.rocket.contraption.entity.RocketContraptionEntity;
910
import com.rae.creatingspace.content.rocket.engine.table.EngineFabricationBlueprint;
1011
import com.rae.creatingspace.content.rocket.engine.EngineItem;
12+
import com.rae.creatingspace.content.rocket.rocket_control.RocketControlsHandler;
1113
import com.rae.creatingspace.init.EngineMaterialInit;
1214
import com.simibubi.create.content.trains.CameraDistanceModifier;
1315
import net.minecraft.client.Minecraft;
@@ -24,6 +26,7 @@
2426
import net.minecraftforge.event.TickEvent;
2527
import net.minecraftforge.event.entity.EntityMountEvent;
2628
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
29+
import net.minecraftforge.event.level.LevelEvent;
2730
import net.minecraftforge.eventbus.api.SubscribeEvent;
2831
import net.minecraftforge.fml.common.Mod;
2932

@@ -52,6 +55,15 @@ public static void onMount(EntityMountEvent event) {
5255
}
5356
}
5457

58+
@SubscribeEvent
59+
public static void onUnloadWorld(LevelEvent.Unload event) {
60+
if (!event.getLevel()
61+
.isClientSide())
62+
return;
63+
RocketControlsHandler.levelUnloaded(event.getLevel());
64+
}
65+
66+
5567
@SubscribeEvent
5668
public static void addToItemTooltip(ItemTooltipEvent event) {
5769
if (event.getEntity() == null)
@@ -101,6 +113,7 @@ public static void addEntityRendererLayers(EntityRenderersEvent.AddLayers event)
101113
public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) {
102114
// Register overlays
103115
event.registerAbove(VanillaGuiOverlay.HELMET.id(), "remaining_oxygen", RemainingO2Overlay.INSTANCE);
116+
event.registerAbove(VanillaGuiOverlay.EXPERIENCE_BAR.id(), "train_hud", RocketHUD.OVERLAY);
104117

105118
}
106119
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.rae.creatingspace.content.rocket;
2+
3+
import com.mojang.blaze3d.vertex.PoseStack;
4+
import com.rae.creatingspace.content.rocket.contraption.entity.RocketContraptionEntity;
5+
import com.rae.creatingspace.content.rocket.rocket_control.RocketControlsHandler;
6+
import com.simibubi.create.AllPackets;
7+
import com.simibubi.create.content.contraptions.actors.trainControls.ControlsBlock;
8+
import com.simibubi.create.content.contraptions.actors.trainControls.ControlsHandler;
9+
import com.simibubi.create.content.trains.HonkPacket;
10+
import com.simibubi.create.content.trains.TrainHUD;
11+
import com.simibubi.create.content.trains.TrainHUDUpdatePacket;
12+
import com.simibubi.create.content.trains.entity.Carriage;
13+
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity;
14+
import com.simibubi.create.content.trains.entity.Train;
15+
import com.simibubi.create.foundation.gui.AllGuiTextures;
16+
import com.simibubi.create.foundation.utility.ControlsUtil;
17+
import com.simibubi.create.infrastructure.config.AllConfigs;
18+
import net.createmod.catnip.animation.LerpedFloat;
19+
import net.createmod.catnip.math.AngleHelper;
20+
import net.createmod.catnip.placement.PlacementClient;
21+
import net.minecraft.client.Minecraft;
22+
import net.minecraft.client.gui.Font;
23+
import net.minecraft.client.gui.GuiGraphics;
24+
import net.minecraft.core.BlockPos;
25+
import net.minecraft.core.Direction;
26+
import net.minecraft.network.chat.Component;
27+
import net.minecraft.util.Mth;
28+
import net.minecraft.world.entity.Entity;
29+
import net.minecraft.world.level.GameType;
30+
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
31+
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
32+
import net.minecraftforge.client.gui.overlay.ForgeGui;
33+
import net.minecraftforge.client.gui.overlay.IGuiOverlay;
34+
35+
public class RocketHUD {
36+
37+
public static final IGuiOverlay OVERLAY = TrainHUD::renderOverlay;
38+
39+
static LerpedFloat displayedSpeed = LerpedFloat.linear();//speed will be for the
40+
static LerpedFloat displayedThrottle = LerpedFloat.linear();
41+
42+
43+
static int hudPacketCooldown = 5;
44+
45+
public static Component currentPrompt;
46+
public static boolean currentPromptShadow;
47+
public static int promptKeepAlive = 0;
48+
49+
50+
public static void tick() {
51+
if (promptKeepAlive > 0)
52+
promptKeepAlive--;
53+
else
54+
currentPrompt = null;//what is the prompt ?
55+
56+
Minecraft mc = Minecraft.getInstance();
57+
58+
}
59+
60+
61+
62+
public static void renderOverlay(ForgeGui gui, GuiGraphics graphics, float partialTicks, int width,
63+
int height) {
64+
Minecraft mc = Minecraft.getInstance();
65+
if (mc.options.hideGui || mc.gameMode.getPlayerMode() == GameType.SPECTATOR)
66+
return;
67+
68+
if (!(RocketControlsHandler.getContraption() instanceof RocketContraptionEntity cce))
69+
return;
70+
Entity cameraEntity = Minecraft.getInstance()
71+
.getCameraEntity();
72+
if (cameraEntity == null)
73+
return;
74+
BlockPos localPos = RocketControlsHandler.getControlsPos();
75+
if (localPos == null)
76+
return;
77+
78+
PoseStack poseStack = graphics.pose();
79+
poseStack.pushPose();
80+
81+
// todo put the custom rocket HUD logic here.
82+
83+
84+
poseStack.popPose();
85+
}
86+
87+
public static boolean onScroll(double delta) {
88+
return true;
89+
}
90+
91+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.rae.creatingspace.content.rocket.rocket_control;
2+
3+
import java.lang.ref.WeakReference;
4+
import java.util.Collection;
5+
import java.util.HashSet;
6+
import java.util.Vector;
7+
8+
import com.simibubi.create.content.contraptions.actors.trainControls.ControlsInputPacket;
9+
import net.minecraftforge.api.distmarker.Dist;
10+
import net.minecraftforge.api.distmarker.OnlyIn;
11+
import org.jetbrains.annotations.Nullable;
12+
import org.lwjgl.glfw.GLFW;
13+
14+
import com.mojang.blaze3d.platform.InputConstants;
15+
import com.simibubi.create.AllPackets;
16+
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
17+
import com.simibubi.create.foundation.utility.ControlsUtil;
18+
import com.simibubi.create.foundation.utility.CreateLang;
19+
20+
import net.minecraft.client.KeyMapping;
21+
import net.minecraft.client.Minecraft;
22+
import net.minecraft.core.BlockPos;
23+
import net.minecraft.world.level.LevelAccessor;
24+
25+
//can we just extends ControlsHandler ? The issue is that we need our own key mapping (we are adding a bunch of them and
26+
// might add joystick handling) -> no we can't because teh entity ref is private, we would need a getter.
27+
//TODO add accessors to the ControlsHandler so we can expand it and change the tick methode.
28+
29+
/**
30+
* this is a client only class, that's why the methode are static and not by player entity : we don't need that because
31+
* only one player does inputs per client.
32+
*/
33+
public class RocketControlsHandler {//this is client only ?
34+
35+
public static Collection<Integer> currentlyPressed = new HashSet<>();
36+
37+
public static int PACKET_RATE = 5;
38+
private static int packetCooldown;
39+
40+
private static WeakReference<AbstractContraptionEntity> entityRef = new WeakReference<>(null);
41+
private static BlockPos controlsPos;
42+
43+
public static void levelUnloaded(LevelAccessor level) {
44+
packetCooldown = 0;
45+
entityRef = new WeakReference<>(null);
46+
controlsPos = null;
47+
currentlyPressed.clear();
48+
}
49+
50+
public static void startControlling(AbstractContraptionEntity entity, BlockPos controllerLocalPos) {
51+
entityRef = new WeakReference<>(entity);
52+
controlsPos = controllerLocalPos;
53+
//todo : what about
54+
Minecraft.getInstance().player.displayClientMessage(
55+
CreateLang.translateDirect("contraption.controls.start_controlling", entity.getContraptionName()), true);
56+
}
57+
58+
public static void stopControlling() {
59+
ControlsUtil.getControls()
60+
.forEach(kb -> kb.setDown(ControlsUtil.isActuallyPressed(kb)));
61+
AbstractContraptionEntity abstractContraptionEntity = entityRef.get();
62+
63+
if (!currentlyPressed.isEmpty() && abstractContraptionEntity != null)
64+
AllPackets.getChannel().sendToServer(new ControlsInputPacket(currentlyPressed, false,
65+
abstractContraptionEntity.getId(), controlsPos, false));
66+
67+
packetCooldown = 0;
68+
entityRef = new WeakReference<>(null);
69+
controlsPos = null;
70+
currentlyPressed.clear();
71+
72+
Minecraft.getInstance().player.displayClientMessage(CreateLang.translateDirect("contraption.controls.stop_controlling"),
73+
true);
74+
}
75+
76+
//for now it's just a blatant copy but I plan to expand on it
77+
@OnlyIn(Dist.CLIENT)
78+
public static void tick() {
79+
AbstractContraptionEntity entity = entityRef.get();
80+
if (entity == null)
81+
return;
82+
if (packetCooldown > 0)
83+
packetCooldown--;
84+
85+
if (entity.isRemoved() || InputConstants.isKeyDown(Minecraft.getInstance()
86+
.getWindow()
87+
.getWindow(), GLFW.GLFW_KEY_ESCAPE)) {
88+
BlockPos pos = controlsPos;
89+
stopControlling();
90+
AllPackets.getChannel()
91+
.sendToServer(new ControlsInputPacket(currentlyPressed, false, entity.getId(), pos, true));
92+
return;
93+
}
94+
95+
Vector<KeyMapping> controls = RocketControlsUtil.getControls();
96+
Collection<Integer> pressedKeys = new HashSet<>();
97+
for (int i = 0; i < controls.size(); i++) {
98+
if (RocketControlsUtil.isActuallyPressed(controls.get(i)))
99+
pressedKeys.add(i);
100+
}
101+
102+
Collection<Integer> newKeys = new HashSet<>(pressedKeys);
103+
Collection<Integer> releasedKeys = currentlyPressed;
104+
newKeys.removeAll(releasedKeys);
105+
releasedKeys.removeAll(pressedKeys);
106+
107+
// Released Keys
108+
if (!releasedKeys.isEmpty()) {
109+
AllPackets.getChannel()
110+
.sendToServer(new ControlsInputPacket(releasedKeys, false, entity.getId(), controlsPos, false));
111+
// AllSoundEvents.CONTROLLER_CLICK.playAt(player.level, player.blockPosition(), 1f, .5f, true);
112+
}
113+
114+
// Newly Pressed Keys
115+
if (!newKeys.isEmpty()) {
116+
AllPackets.getChannel().sendToServer(new ControlsInputPacket(newKeys, true, entity.getId(), controlsPos, false));
117+
packetCooldown = PACKET_RATE;
118+
// AllSoundEvents.CONTROLLER_CLICK.playAt(player.level, player.blockPosition(), 1f, .75f, true);
119+
}
120+
121+
// Keepalive Pressed Keys
122+
if (packetCooldown == 0) {
123+
// if (!pressedKeys.isEmpty()) {
124+
AllPackets.getChannel()
125+
.sendToServer(new ControlsInputPacket(pressedKeys, true, entity.getId(), controlsPos, false));
126+
packetCooldown = PACKET_RATE;
127+
// }
128+
}
129+
130+
currentlyPressed = pressedKeys;
131+
controls.forEach(kb -> kb.setDown(false));
132+
}
133+
134+
@Nullable
135+
public static AbstractContraptionEntity getContraption() {
136+
return entityRef.get();
137+
}
138+
139+
@Nullable
140+
public static BlockPos getControlsPos() {//used for rendering
141+
return controlsPos;
142+
}
143+
144+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.rae.creatingspace.content.rocket.rocket_control;
2+
3+
import com.mojang.blaze3d.platform.InputConstants;
4+
import com.rae.creatingspace.init.KeysInit;
5+
import com.simibubi.create.AllKeys;
6+
import net.minecraft.client.KeyMapping;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.client.Options;
9+
10+
import java.util.Vector;
11+
12+
public class RocketControlsUtil {
13+
14+
private static Vector<KeyMapping> standardControls;
15+
16+
public static Vector<KeyMapping> getControls() {
17+
if (standardControls == null) {
18+
Options gameSettings = Minecraft.getInstance().options;
19+
standardControls = new Vector<>(6);
20+
standardControls.add(gameSettings.keyUp);
21+
standardControls.add(gameSettings.keyDown);
22+
standardControls.add(gameSettings.keyLeft);
23+
standardControls.add(gameSettings.keyRight);
24+
standardControls.add(gameSettings.keyJump);
25+
standardControls.add(gameSettings.keyShift);
26+
standardControls.add(KeysInit.PITCH_UP.getKeybind());//6
27+
standardControls.add(KeysInit.PITCH_DOWN.getKeybind());//7
28+
standardControls.add(KeysInit.YAW_LEFT.getKeybind());//8
29+
standardControls.add(KeysInit.YAW_RIGHT.getKeybind());//9
30+
standardControls.add(KeysInit.SWITCH_MODE.getKeybind());//10
31+
standardControls.add(gameSettings.keySprint);//11
32+
}
33+
return standardControls;
34+
}
35+
36+
public static boolean isActuallyPressed(KeyMapping kb) {
37+
InputConstants.Key key = kb.getKey();
38+
if (key.getType() == InputConstants.Type.MOUSE) {
39+
return AllKeys.isMouseButtonDown(key.getValue());
40+
} else {
41+
return AllKeys.isKeyDown(key.getValue());
42+
}
43+
}
44+
}

src/main/java/com/rae/creatingspace/content/worldgen/WorleyNoise.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public float cellular3x3x3(float px, float py, float pz) {
112112
float jitterY = ((Mth.floor(fk) % 8) * K - Ko) * jitter;
113113
float jitterZ = ((Mth.floor(permuted * K2)) * Kz - Kzo) * jitter;
114114

115-
float ytest = cellY + jitterY+ yi;
115+
float ytest = cellY + jitterY;
116116

117117
if (ytest < yMinOffset || ytest > yMaxOffset) continue;
118118

0 commit comments

Comments
 (0)