- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
Latest commit
189 lines (163 loc) · 5.24 KB
/
Copy pathBlock.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
importjavax.sound.sampled.AudioInputStream;
importjavax.sound.sampled.AudioSystem;
importjavax.sound.sampled.Clip;
importjavax.sound.sampled.FloatControl;
classBlock {
// Fields
Stringname; // Name of block
booleanrenewable; // If the block is renewable naturally
Stringstackable; // How stackable this block is in your inventory
doubleblastRes; // In-game blast resistance
doublehardness; // The in-game hardness of the block
doubleluminous; // If this block gives off light
booleanflammable; // If the block is flammable from natural fire
Stringdimension; // Primary Dimension of the block
booleancraftability; // texture file path that we will put on the block model
Stringsfx; // SFX path
// Creating a block
publicBlock(Stringname, booleanrenewable, Stringstackable, doubleblastRes, doublehardness, doubleluminous,booleanflammable, Stringdimension, booleancraftability, Stringsfx)
{
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;
}
publicStringtoStringA() {
StringflammableInfo = "";
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)
publicStringgetName()
{
returnname;
}
publicvoidsetName(Stringname)
{
this.name = name;
}
publicbooleangetRenewability()
{
returnrenewable;
}
publicvoidsetRenewability(booleanrenewable)
{
this.renewable = renewable;
}
publicStringgetStackability()
{
returnstackable;
}
publicvoidsetStackability(Stringstackability)
{
this.stackable = stackable;
}
publicdoublegetBlastres()
{
returnblastRes;
}
publicvoidsetBlastres(doubleblastRes)
{
this.blastRes = blastRes;
}
publicdoublegetHardness()
{
returnhardness;
}
publicvoidsetHardness(doublehardness)
{
this.hardness = hardness;
}
publicdoublegetLuminous()
{
returnluminous;
}
publicvoidsetLuminous(doubleluminous)
{
this.luminous = luminous;
}
publicbooleangetFlammable() {
returnflammable;
}
publicvoidsetFlammable(booleanflammable)
{
this.flammable = flammable;
}
publicStringgetDimension()
{
returndimension;
}
publicvoidsetDimension(Stringdimension)
{
this.dimension = dimension;
}
publicStringgetSFX()
{
returnsfx;
}
publicvoidsetSFX(Stringsfx)
{
this.sfx = sfx;
}
publicbooleangetcraftability()
{
returncraftability;
}
publicvoidsetTexture(booleancraftability)
{
this.craftability = craftability;
}
publicStringtoCsvString()
{
returnString.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.
publicClipplaySFX(Stringsong, floatvolume)
{
Clipclip = null;
try
{
AudioInputStreamaudioStream = AudioSystem.getAudioInputStream(this.getClass().getResource("/res/"+song));
clip = AudioSystem.getClip();
clip.open(audioStream);
FloatControlsetVolume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
setVolume.setValue(volume); // Reduces the volume by the input value
clip.start();
}
catch (Exceptione)
{
e.printStackTrace();
System.out.println("Runtime error when adding audio file " + song);
}
returnclip;
}
}