-
Notifications
You must be signed in to change notification settings - Fork 497
/
RedstoneBoardNBT.java
executable file
·85 lines (63 loc) · 2.5 KB
/
RedstoneBoardNBT.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
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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.boards;
import java.util.List;
import java.util.Random;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.Constants;
public abstract class RedstoneBoardNBT<T> {
private static Random rand = new Random();
public abstract String getID();
public abstract void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced);
public abstract IRedstoneBoard<T> create(NBTTagCompound nbt, T object);
@SideOnly(Side.CLIENT)
public abstract void registerIcons(IIconRegister iconRegister);
@SideOnly(Side.CLIENT)
public abstract IIcon getIcon(NBTTagCompound nbt);
public abstract void createRandomBoard(NBTTagCompound nbt);
public abstract void createDefaultBoard(NBTTagCompound nbt);
public IBoardParameter[] getParameters(NBTTagCompound nbt) {
NBTTagList paramsNBT = nbt.getTagList("parameters", Constants.NBT.TAG_COMPOUND);
IBoardParameter[] result = new IBoardParameter[paramsNBT.tagCount()];
for (int i = 0; i < paramsNBT.tagCount(); ++i) {
NBTTagCompound subNBT = paramsNBT.getCompoundTagAt(i);
IBoardParameter p = RedstoneBoardRegistry.instance.createParameter(subNBT.getString("kind"));
p.readFromNBT(subNBT);
result[i] = p;
}
return result;
}
public void setParameters(NBTTagCompound nbt, IBoardParameter[] params) {
NBTTagList paramsNBT = new NBTTagList();
for (IBoardParameter p : params) {
NBTTagCompound subNBT = new NBTTagCompound();
subNBT.setString("kind", RedstoneBoardRegistry.instance.getKindForParam(p));
p.writeToNBT(subNBT);
paramsNBT.appendTag(subNBT);
}
nbt.setTag("parameters", paramsNBT);
}
public int getParameterNumber(NBTTagCompound nbt) {
if (!nbt.hasKey("parameters")) {
return 0;
} else {
return nbt.getTagList("parameters", Constants.NBT.TAG_COMPOUND).tagCount();
}
}
public float nextFloat(int difficulty) {
return 1F - (float) Math.pow(rand.nextFloat(), 1F / difficulty);
}
}