File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
main/java/com/robotgryphon/compactmachines/teleportation
test/java/com/robotgryphon/compactmachines/tests/util Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1919import net .minecraftforge .common .util .INBTSerializable ;
2020
2121import javax .annotation .Nonnull ;
22+ import java .util .Objects ;
2223import java .util .Optional ;
2324
2425public class DimensionalPosition implements INBTSerializable <CompoundNBT > {
@@ -93,6 +94,19 @@ public BlockPos getBlockPosition() {
9394 return new BlockPos (position .x , position .y , position .z );
9495 }
9596
97+ @ Override
98+ public boolean equals (Object o ) {
99+ if (this == o ) return true ;
100+ if (o == null || getClass () != o .getClass ()) return false ;
101+ DimensionalPosition that = (DimensionalPosition ) o ;
102+ return Objects .equals (dimension , that .dimension ) && Objects .equals (position , that .position );
103+ }
104+
105+ @ Override
106+ public int hashCode () {
107+ return Objects .hash (dimension , position );
108+ }
109+
96110 @ Override
97111 public String toString () {
98112 return "DimensionalPosition{" +
Original file line number Diff line number Diff line change 1+ package com .robotgryphon .compactmachines .tests .util ;
2+
3+ import com .google .gson .Gson ;
4+ import com .google .gson .JsonElement ;
5+ import net .minecraft .nbt .CompoundNBT ;
6+ import net .minecraft .nbt .CompressedStreamTools ;
7+
8+ import java .io .IOException ;
9+ import java .io .InputStream ;
10+ import java .io .InputStreamReader ;
11+ import java .net .URL ;
12+
13+ public class FileHelper {
14+ public static final FileHelper INSTANCE = new FileHelper ();
15+
16+ private FileHelper () {
17+ }
18+
19+ public InputStream getFileStream (String filename ) {
20+ return getClass ().getClassLoader ().getResourceAsStream (filename );
21+ }
22+
23+ public InputStreamReader openFile (String filename ) {
24+ URL res = getClass ().getClassLoader ().getResource (filename );
25+ try {
26+ InputStream inputStream = res .openStream ();
27+ return new InputStreamReader (inputStream );
28+ } catch (IOException e ) {
29+ e .printStackTrace ();
30+ }
31+
32+ return null ;
33+ }
34+
35+ public JsonElement getJsonFromFile (String filename ) {
36+ Gson g = new Gson ();
37+ InputStreamReader isr = openFile (filename );
38+ return g .fromJson (isr , JsonElement .class );
39+ }
40+
41+ public CompoundNBT getNbtFromFile (String filename ) throws IOException {
42+ InputStream isr = getFileStream (filename );
43+ return CompressedStreamTools .readCompressed (isr );
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments