/
Util.java
59 lines (48 loc) · 1.67 KB
/
Util.java
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
package slimeknights.tmechworks.library;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;
public class Util
{
public static final String RESOURCE = "tmechworks";
public static final Random rand = new Random();
public static FakePlayer createFakePlayer (World world)
{
if (!(world instanceof WorldServer))
{
return null;
}
return FakePlayerFactory.get((WorldServer) world, new GameProfile(UUID.randomUUID(), "MechworksWorker"));
}
/**
* Returns the given Resource prefixed with tinkers resource location. Use this function instead of hardcoding
* resource locations.
*/
public static String resource (String res)
{
return String.format("%s:%s", RESOURCE, res);
}
public static ResourceLocation getResource (String res)
{
return new ResourceLocation(RESOURCE, res);
}
public static ModelResourceLocation getModelResource (String res, String variant)
{
return new ModelResourceLocation(resource(res), variant);
}
/**
* Prefixes the given unlocalized name with tinkers prefix. Use this when passing unlocalized names for a uniform
* namespace.
*/
public static String prefix (String name)
{
return String.format("%s.%s", RESOURCE, name.toLowerCase(Locale.US));
}
}