Skip to content

Commit 2c0b39b

Browse files
committed
Added PneumaticCraft API
1 parent 8303a53 commit 2c0b39b

26 files changed

+1272
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package pneumaticCraft.api.block;
2+
3+
import net.minecraft.block.Block;
4+
5+
public class BlockSupplier{
6+
private static Class blockClass;
7+
8+
public static Block getBlock(String blockName){
9+
try {
10+
if(blockClass == null) blockClass = Class.forName("pneumaticCraft.common.block.Blocks");
11+
return (Block)blockClass.getField(blockName).get(null);
12+
} catch(Exception e) {
13+
System.err.println("[PneumaticCraft API] Block supply failed for block: " + blockName);
14+
return null;
15+
}
16+
}
17+
18+
/*
19+
The following is a list of all the block names that can be passed as argument in getBlock(String) to get a PneumaticCraft block.
20+
21+
22+
pressureTube meta = tube type
23+
airCompressor
24+
airCannon
25+
pressureChamberWall meta < 6 ? wall : window
26+
pressureChamberValve
27+
pressureChamberInterface
28+
squidPlant
29+
fireFlower
30+
creeperPlant
31+
slimePlant
32+
rainPlant
33+
enderPlant
34+
lightningPlant
35+
adrenalinePlant
36+
burstPlant
37+
potionPlant
38+
repulsionPlant
39+
heliumPlant
40+
flyingFlower
41+
musicPlant
42+
propulsionPlant
43+
chopperPlant
44+
chargingStation
45+
elevatorBase
46+
elevatorFrame
47+
vacuumPump
48+
pneumaticDoorBase
49+
pneumaticDoor
50+
assemblyPlatform
51+
assemblyIOUnit
52+
assemblyDrill
53+
assemblyLaser
54+
assemblyController
55+
advancedPressureTube meta = tube type (like 'pressureTube')
56+
compressedIron
57+
uvLightBox
58+
etchingAcid
59+
securityStation
60+
universalSensor
61+
pneumaticGenerator
62+
electricCompressor
63+
pneumaticEngine
64+
kineticCompressor
65+
aerialInterface
66+
electrostaticCompressor
67+
aphorismTile
68+
omnidirectionalHopper
69+
70+
*/
71+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package pneumaticCraft.api.block;
2+
3+
import net.minecraft.entity.player.EntityPlayer;
4+
import net.minecraft.world.World;
5+
import net.minecraftforge.common.ForgeDirection;
6+
7+
/**
8+
* Should be implemented by any block that allows to be rotated by a Pneumatic Wrench. It uses almost the same
9+
* rotate method as the Vanilla (Forge) method. However it uses energy to rotate (when rotateBlock() return true).
10+
*/
11+
public interface IPneumaticWrenchable{
12+
13+
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side);
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package pneumaticCraft.api.client;
2+
3+
import net.minecraft.client.gui.inventory.GuiContainer;
4+
import net.minecraft.item.ItemStack;
5+
6+
/**
7+
* With this class you can retrieve new instances of the PneumaticCraft's IGuiAnimatedStat implementation. You can use these in Gui's as
8+
* well as anywhere you like. When you use these in Gui's you need to pass a valid GuiContainer instance, if you don't you can just pass
9+
* null.
10+
*/
11+
public class GuiAnimatedStatSupplier{
12+
private static Class animatedStatClass;
13+
14+
public static IGuiAnimatedStat getAnimatedStat(GuiContainer gui, int backgroundColor){
15+
return getAnimatedStat(new Class[]{GuiContainer.class, int.class}, gui, backgroundColor);
16+
}
17+
18+
/**
19+
* Returns a GuiAnimatedStat which uses an itemstack as statistic icon.
20+
* @param gui
21+
* @param iconStack
22+
* @param backgroundColor
23+
* @return
24+
*/
25+
public static IGuiAnimatedStat getAnimatedStat(GuiContainer gui, ItemStack iconStack, int backgroundColor){
26+
return getAnimatedStat(new Class[]{GuiContainer.class, int.class, ItemStack.class}, gui, backgroundColor, iconStack);
27+
}
28+
29+
/**
30+
* Returns a GuiAnimatedStat which uses a texture location as statistic icon.
31+
* @param gui
32+
* @param iconTexture
33+
* @param backgroundColor
34+
* @return
35+
*/
36+
public static IGuiAnimatedStat getAnimatedStat(GuiContainer gui, String iconTexture, int backgroundColor){
37+
return getAnimatedStat(new Class[]{GuiContainer.class, int.class, String.class}, gui, backgroundColor, iconTexture);
38+
}
39+
40+
private static IGuiAnimatedStat getAnimatedStat(Class[] constructorClasses, Object... constructorParameters){
41+
try {
42+
if(animatedStatClass == null) animatedStatClass = Class.forName("pneumaticCraft.client.gui.GuiAnimatedStat");
43+
return (IGuiAnimatedStat)animatedStatClass.getConstructor(constructorClasses).newInstance(constructorParameters);
44+
} catch(Exception e) {
45+
System.err.println("Failed to retrieve an GuiAnimatedStat intance of PneumaticCraft.");
46+
}
47+
return null;
48+
}
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package pneumaticCraft.api.client;
2+
3+
import java.lang.reflect.Method;
4+
5+
import net.minecraft.client.gui.FontRenderer;
6+
7+
public class GuiElementRenderer{
8+
private static Method drawGaugeMethod;
9+
10+
/**
11+
* Draws a Pressure Gauge, the same which is also used in many PneumaticCraft applications.
12+
* @param fontRenderer fontrenderer used to draw the numbers of the pressure gauge.
13+
* @param minPressure The minimal pressure that needs to be displayed (this is -1 in most applications).
14+
* @param maxPressure The maximal pressure that needs to be rendererd (this is 7 for tier one machines, and 25 for tier two).
15+
* @param dangerPressure The transition pressure from green to red (this is 5 for tier one, and 29 for tier two machines).
16+
* @param minWorkingPressure The transition pressure from yellow to green (variates per machine).
17+
* @param currentPressure The pressure that the needle should point to.
18+
* @param xPos x position of the gauge.
19+
* @param yPos y position of the gauge.
20+
* @param zLevel z position of the gauge (Gui#zLevel, -90, for in normal GUI's).
21+
*/
22+
public static void drawPressureGauge(FontRenderer fontRenderer, float minPressure, float maxPressure, float dangerPressure, float minWorkingPressure, float currentPressure, int xPos, int yPos, float zLevel){
23+
try {
24+
if(drawGaugeMethod == null) {
25+
drawGaugeMethod = Class.forName("pneumaticCraft.client.gui.GuiUtils").getMethod("drawPressureGauge", FontRenderer.class, float.class, float.class, float.class, float.class, float.class, int.class, int.class, float.class);
26+
}
27+
drawGaugeMethod.invoke(null, fontRenderer, minPressure, maxPressure, dangerPressure, minWorkingPressure, currentPressure, xPos, yPos, zLevel);
28+
} catch(Exception e) {
29+
System.err.println("Failed to render a Pressure Gauge from PneumaticCraft.");
30+
}
31+
}
32+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package pneumaticCraft.api.client;
2+
3+
import java.awt.Rectangle;
4+
import java.util.List;
5+
6+
import net.minecraft.client.gui.FontRenderer;
7+
8+
/**
9+
* This interface doesn't have to be implemented. In PneumaticCraft there already is one class which implements this interface
10+
* which is used many times in PneumaticCraft (GUI stats, Pneumatic Helmet 2D and 3D stats). You can get an instance of this
11+
* class as well. Information about this you can find in GuiAnimatedStatSupplier.java. Implementing your own version of
12+
* animated stats can be implemented as well via this interface, and they will interact with the PneumaticCraft GuiAnimatedStats
13+
* if you implement it correctly.
14+
*/
15+
16+
public interface IGuiAnimatedStat{
17+
18+
/**
19+
* When you call this method with a set of coordinates representing the button location and dimensions, you'll get
20+
* these parameters back scaled to the GuiAnimatedStat's scale.
21+
* @param origX Button start X.
22+
* @param origY Button start Y.
23+
* @param width Button width.
24+
* @param height Button height.
25+
* @return rectangle containing the new location and dimensions.
26+
*/
27+
public Rectangle getButtonScaledRectangle(int origX, int origY, int width, int height);
28+
29+
/**
30+
* When passed 0.5F for example, the text of the stat will be half as big (so more text can fit into a certain area).
31+
* @param scale
32+
*/
33+
public void scaleTextSize(float scale);
34+
35+
/**
36+
* Returns true if the statistic expands to the left.
37+
* @return
38+
*/
39+
public boolean isLeftSided();
40+
41+
/**
42+
* Returns true if the statistic is done with expanding (when text will be displayed).
43+
* @return
44+
*/
45+
public boolean isDoneExpanding();
46+
47+
/**
48+
* Pass true if the statistic should expand to the left, otherwise false.
49+
* @param leftSided
50+
*/
51+
public void setLeftSided(boolean leftSided);
52+
53+
/**
54+
* Sets the main text of this stat. Every line should be stored in a seperate list element. Upon rendering,
55+
* EnumChatFormattings will be respected. When you call this method, Too long lines will be divided into multiple shorter ones
56+
* to fit in the GUI.
57+
* @param text
58+
*/
59+
public void setText(List<String> text);
60+
61+
/**
62+
* Sets the line to a single line. Upon rendering,
63+
* EnumChatFormattings will be respected. When you call this method, Too long lines will be divided into multiple shorter ones
64+
* to fit in the GUI.
65+
* @param text
66+
*/
67+
public void setText(String text);
68+
69+
/**
70+
* Sets the main text of this stat. Every line should be stored in a seperate list element. Upon rendering,
71+
* EnumChatFormattings will be respected. This version of the text setting doesn't handle too long lines.
72+
* @param text
73+
*/
74+
public void setTextWithoutCuttingString(List<String> text);
75+
76+
/**
77+
* Sets the title of this stat. It will automatically get the yellow color assigned.
78+
* @param title
79+
*/
80+
public void setTitle(String title);
81+
82+
/**
83+
* Returns the title of this stat (obviously without color prefix).
84+
* @return
85+
*/
86+
public String getTitle();
87+
88+
/**
89+
* Defines what dimensions the stat should have when it is not expanded (default 17x17) and resets the stat to these dimensions.
90+
* Used in PneumaticCraft by the block/entity tracker stats, they are 0x0 when not expanded so it looks like they expand
91+
* (and appear) from nothing.
92+
* @param minWidth
93+
* @param minHeight
94+
*/
95+
public void setMinDimensionsAndReset(int minWidth, int minHeight);
96+
97+
/**
98+
* When this stat gets a parent stat assigned, the y of this stat will be the same as the parent's plus this stat's
99+
* baseY. This will cause this stat to move up and down when the parent's stat expands/moves.
100+
* @param stat
101+
*/
102+
public void setParentStat(IGuiAnimatedStat stat);
103+
104+
/**
105+
* Sets the x location of this stat.
106+
* @param x
107+
*/
108+
public void setBaseX(int x);
109+
110+
/**
111+
* Sets the base Y of this stat.
112+
* @param y
113+
*/
114+
public void setBaseY(int y);
115+
116+
/**
117+
* Returns the real Y of this stat. This is the same as getBaseY when there is no parent stat, but if there is this method
118+
* returns the value described in setParentStat(IGuiAnimatedStat stat).
119+
* @return
120+
*/
121+
public int getAffectedY();
122+
123+
public int getBaseX();
124+
125+
public int getBaseY();
126+
127+
/**
128+
* Returns the Y size of this stat.
129+
* @return
130+
*/
131+
public int getHeight();
132+
133+
/**
134+
* Returns the X size of this stat.
135+
* @return
136+
*/
137+
public int getWidth();
138+
139+
/**
140+
* This method should be called every game tick to update the logic of the stat (expanding of the stat).
141+
* NOTE!! PneumaticCraft's version of GuiAnimatedStat registers the stat when it creates an instance to automatically invoke the
142+
* update() method every tick. This means that if you use GuiAnimatedStatSupplier.getAnimatedStat() you shouldn't call update()
143+
* yourself!
144+
*/
145+
public void update();
146+
147+
/**
148+
* Should be called every render tick when and where you want to render the stat.
149+
* @param fontRenderer
150+
* @param zLevel
151+
* @param partialTicks
152+
*/
153+
public void render(FontRenderer fontRenderer, float zLevel, float partialTicks);
154+
155+
/**
156+
* This method will handle mouse clicks. This will handle open/closing of the stat when the mouse clicks it.
157+
* @param x
158+
* @param y
159+
* @param button
160+
* @return
161+
*/
162+
public boolean mouseClicked(int x, int y, int button);
163+
164+
/**
165+
* Forces the stat to close.
166+
*/
167+
public void closeWindow();
168+
169+
/**
170+
* Forces the stat to expand.
171+
*/
172+
public void openWindow();
173+
174+
/**
175+
* Returns true if the stat is expanding.
176+
* @return
177+
*/
178+
public boolean isClicked();
179+
180+
/**
181+
* Will handle the tooltip.
182+
* @param fontRenderer
183+
* @param x
184+
* @param y
185+
*/
186+
public void onMouseHovering(FontRenderer fontRenderer, int x, int y);
187+
}

0 commit comments

Comments
 (0)