-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
189 lines (163 loc) · 5.24 KB
/
Block.java
File metadata and controls
189 lines (163 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
class Block {
// Fields
String name; // Name of block
boolean renewable; // If the block is renewable naturally
String stackable; // How stackable this block is in your inventory
double blastRes; // In-game blast resistance
double hardness; // The in-game hardness of the block
double luminous; // If this block gives off light
boolean flammable; // If the block is flammable from natural fire
String dimension; // Primary Dimension of the block
boolean craftability; // texture file path that we will put on the block model
String sfx; // SFX path
// Creating a block
public Block(String name, boolean renewable, String stackable, double blastRes, double hardness, double luminous,boolean flammable, String dimension, boolean craftability, String sfx)
{
this.name = name;
this.renewable = renewable;
this.stackable = stackable;
this.hardness = hardness;
this.blastRes = blastRes;
this.luminous = luminous;
this.flammable = flammable;
this.dimension = dimension;
this.craftability = craftability;
this.sfx = sfx;
}
public String toStringA() {
String flammableInfo = "";
if (flammable)
flammableInfo = "This block also catches fire.";
else
flammableInfo = "This block is not flammable.";
return "It spawns in the " + dimension +". " + "Stackability: " + stackable + " Hardness: " + hardness
+ "\nBlast Resistance: " + blastRes + " Is Renewable: "
+ renewable + ". " + flammableInfo;
}
//Accessor and Mutator methods (IDK how to put this anywhere else. This'll have to do)
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public boolean getRenewability()
{
return renewable;
}
public void setRenewability(boolean renewable)
{
this.renewable = renewable;
}
public String getStackability()
{
return stackable;
}
public void setStackability(String stackability)
{
this.stackable = stackable;
}
public double getBlastres()
{
return blastRes;
}
public void setBlastres(double blastRes)
{
this.blastRes = blastRes;
}
public double getHardness()
{
return hardness;
}
public void setHardness(double hardness)
{
this.hardness = hardness;
}
public double getLuminous()
{
return luminous;
}
public void setLuminous(double luminous)
{
this.luminous = luminous;
}
public boolean getFlammable() {
return flammable;
}
public void setFlammable(boolean flammable)
{
this.flammable = flammable;
}
public String getDimension()
{
return dimension;
}
public void setDimension(String dimension)
{
this.dimension = dimension;
}
public String getSFX()
{
return sfx;
}
public void setSFX(String sfx)
{
this.sfx = sfx;
}
public boolean getcraftability()
{
return craftability;
}
public void setTexture(boolean craftability)
{
this.craftability = craftability;
}
public String toCsvString()
{
return String.join(",",
getName(),
Boolean.toString(getRenewability()),
getStackability(),
Double.toString(getBlastres()),
Double.toString(getHardness()),
Double.toString(getLuminous()),
Boolean.toString(getFlammable()),
getDimension(),
Boolean.toString(getcraftability()),
getSFX());
}
//End of setters and getters
/* IMPORTANT: HOW TO USE - First create a Clip object:
Clip currentClip = playSFX("Block_Break.wav", 5f);
When you want it to stop do the following:
if (currentClip != null)
currentClip.stop(); // Stop the currently playing sound effect
The if structure prevents the program from stopping a clip that has alread finished
*/
// It takes .wav format files, not .mp3 files.
public Clip playSFX(String song, float volume)
{
Clip clip = null;
try
{
AudioInputStream audioStream = AudioSystem.getAudioInputStream(this.getClass().getResource("/res/"+song));
clip = AudioSystem.getClip();
clip.open(audioStream);
FloatControl setVolume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
setVolume.setValue(volume); // Reduces the volume by the input value
clip.start();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Runtime error when adding audio file " + song);
}
return clip;
}
}