Skip to content

Commit

Permalink
Added the ability to texture blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
The64thGamer committed Mar 24, 2024
1 parent 5040a33 commit 34b3f1a
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 112 deletions.
12 changes: 6 additions & 6 deletions Scenes/node_3d.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[ext_resource type="FontFile" uid="uid://cq3fhluvc2kjn" path="res://Fonts/adm-3a.otf" id="4_tu8wd"]
[ext_resource type="Script" path="res://Scripts/Placing.cs" id="6_c3d1i"]
[ext_resource type="Script" path="res://Scripts/PhotoMode.cs" id="7_8ade3"]
[ext_resource type="Script" path="res://Scripts/Texturing.cs" id="7_uco8b"]
[ext_resource type="PackedScene" uid="uid://ctebjgs6cgjjn" path="res://Particles/Break Brush.tscn" id="8_htych"]
[ext_resource type="Script" path="res://Scripts/DrawLine3D.cs" id="9_dc1ri"]
[ext_resource type="Texture2D" uid="uid://ietyxumfo2yv" path="res://Cursor.png" id="9_yvr36"]
[ext_resource type="Script" path="res://Scripts/ScrollBar.cs" id="10_etxye"]
[ext_resource type="Texture2D" uid="uid://bxkpuapk2ls6t" path="res://UI/Slot Vertex.png" id="10_n1m02"]
Expand Down Expand Up @@ -101,7 +101,7 @@ shadow_size = 3
shadow_color = Color(0, 0, 0, 1)
shadow_offset = Vector2(0, 0)

[node name="World" type="Node3D" node_paths=PackedStringArray("envController", "destroyBrushParticles", "debugLine")]
[node name="World" type="Node3D" node_paths=PackedStringArray("envController", "destroyBrushParticles")]
script = ExtResource("1_qvi55")
envController = NodePath("WorldEnvironment")
curve1 = SubResource("Curve_tpjr8")
Expand All @@ -111,7 +111,6 @@ curve4 = SubResource("Curve_81qg4")
curve5 = SubResource("Curve_yefdb")
curve6 = SubResource("Curve_ijfoo")
destroyBrushParticles = NodePath("Break Brush Particles")
debugLine = NodePath("DebugDraw")

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_rruv5")
Expand Down Expand Up @@ -151,6 +150,10 @@ worldGen = NodePath("../../../..")
script = ExtResource("6_c3d1i")
worldGen = NodePath("../../../..")

[node name="Texturing" type="Node3D" parent="Player/Player Head/Player Camera" node_paths=PackedStringArray("worldGen")]
script = ExtResource("7_uco8b")
worldGen = NodePath("../../../..")

[node name="Debug Text" type="Label" parent="Player/Player Head/Player Camera" groups=["Player"]]
texture_filter = 1
offset_right = 40.0
Expand Down Expand Up @@ -492,6 +495,3 @@ shadow_blur = 0.364
directional_shadow_split_1 = 0.052
directional_shadow_blend_splits = true
directional_shadow_max_distance = 2374.0

[node name="DebugDraw" type="Node2D" parent="."]
script = ExtResource("9_dc1ri")
4 changes: 1 addition & 3 deletions Scripts/Mining.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public override void _PhysicsProcess(double delta)
Godot.Collections.Dictionary result = spaceState.IntersectRay(query);
if (result.Count > 0)
{
Vector3 position = ((Node3D)result["collider"]).GlobalPosition;

WorldGen.Brush b = worldGen.DestroyBlock(((Node3D)result["collider"]).GetParent().GetParent() as Node3D, Mathf.FloorToInt(((int)result["face_index"])));
WorldGen.Brush b = worldGen.DestroyBlock(((Node3D)result["collider"]).GetParent().GetParent() as Node3D, (int)result["face_index"]);
totalBrushes += Mathf.CeilToInt(worldGen.VolumeOfMesh(b.vertices));
for (int i = 0; i < b.textures.Length; i++)
{
Expand Down
33 changes: 33 additions & 0 deletions Scripts/Texturing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Godot;
using System;

public partial class Texturing : Node3D
{
[Export] public WorldGen worldGen;
public override void _PhysicsProcess(double delta)
{
if (PhotoMode.photoModeEnabled || ScrollBar.currentHotbarSelection <= ScrollBar.miningSlot)
{
return;
}
if (Input.IsActionJustPressed("Action") && Inventory.inventory[ScrollBar.currentHotbarSelection - ScrollBar.miningSlot] > 0)
{
PhysicsDirectSpaceState3D spaceState = GetWorld3D().DirectSpaceState;
PhysicsRayQueryParameters3D query = PhysicsRayQueryParameters3D.Create(this.GlobalPosition, this.GlobalPosition + (-this.GlobalTransform.Basis.Z * 50));
query.CollisionMask = 0b00000000_00000000_00000000_00000100; //Brushes
Godot.Collections.Dictionary result = spaceState.IntersectRay(query);
if (result.Count > 0)
{
int assignment = worldGen.AssignBrushTexture(((Node3D)result["collider"]).GetParent().GetParent() as Node3D, (int)result["face_index"], (uint)(ScrollBar.currentHotbarSelection - ScrollBar.miningSlot));
if(assignment > -1)
{
Inventory.inventory[ScrollBar.currentHotbarSelection - ScrollBar.miningSlot]--;
}
if (assignment > 0)
{
Inventory.inventory[assignment]++;
}
}
}
}
}
Loading

0 comments on commit 34b3f1a

Please sign in to comment.