Skip to content

Commit d552dcf

Browse files
committed
initial
1 parent 634d4f2 commit d552dcf

19 files changed

+760
-2
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# eclipse
2+
bin
3+
*.launch
4+
.settings
5+
.metadata
6+
.classpath
7+
.project
8+
9+
# idea
10+
out
11+
*.ipr
12+
*.iws
13+
*.iml
14+
.idea
15+
16+
# gradle
17+
build
18+
.gradle
19+
gradle
20+
21+
# other
22+
eclipse
23+
run

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# mc-XPBox
2-
1.10.2 port for Minecraft MOD ExPContainer
1+
# XPBox
2+
This is 1.10.2 port for Minecraft MOD ExPContainer (made by clocka [[OP Link]](http://forum.minecraftuser.jp/viewtopic.php?t=15105)).
3+
This MOD adds a block that stores players' xp and persists, be it broken or the player is dead (acting like ender chests).

build.gradle

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
maven { url = "http://files.minecraftforge.net/maven" }
5+
}
6+
dependencies {
7+
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
8+
}
9+
}
10+
apply plugin: 'net.minecraftforge.gradle.forge'
11+
//Only edit below this line, the above code adds and enables the nessasary things for Forge to be setup.
12+
13+
14+
version = "1.0"
15+
group= "plodsoft.xpbox" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
16+
archivesBaseName = "XPBox"
17+
18+
sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
19+
compileJava {
20+
sourceCompatibility = targetCompatibility = "1.8"
21+
}
22+
23+
minecraft {
24+
version = "1.10.2-12.18.3.2185"
25+
runDir = "run"
26+
27+
// the mappings can be changed at any time, and must be in the following format.
28+
// snapshot_YYYYMMDD snapshot are built nightly.
29+
// stable_# stables are built at the discretion of the MCP team.
30+
// Use non-default mappings at your own risk. they may not allways work.
31+
// simply re-run your setup task after changing the mappings to update your workspace.
32+
mappings = "snapshot_20161111"
33+
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
34+
}
35+
36+
dependencies {
37+
// you may put jars on which you depend on in ./libs
38+
// or you may define them like so..
39+
//compile "some.group:artifact:version:classifier"
40+
//compile "some.group:artifact:version"
41+
42+
// real examples
43+
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
44+
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
45+
46+
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
47+
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
48+
49+
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
50+
// except that these dependencies get remapped to your current MCP mappings
51+
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
52+
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
53+
54+
// for more info...
55+
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
56+
// http://www.gradle.org/docs/current/userguide/dependency_management.html
57+
58+
}
59+
60+
processResources
61+
{
62+
// this will ensure that this task is redone when the versions change.
63+
inputs.property "version", project.version
64+
inputs.property "mcversion", project.minecraft.version
65+
66+
// replace stuff in mcmod.info, nothing else
67+
from(sourceSets.main.resources.srcDirs) {
68+
include 'mcmod.info'
69+
70+
// replace version and mcversion
71+
expand 'version':project.version, 'mcversion':project.minecraft.version
72+
}
73+
74+
// copy everything else, thats not the mcmod.info
75+
from(sourceSets.main.resources.srcDirs) {
76+
exclude 'mcmod.info'
77+
}
78+
}

src/main/java/xpbox/BlockXPBox.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package xpbox;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.material.Material;
5+
import net.minecraft.block.state.IBlockState;
6+
import net.minecraft.creativetab.CreativeTabs;
7+
import net.minecraft.entity.player.EntityPlayer;
8+
import net.minecraft.entity.player.EntityPlayerMP;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.util.EnumFacing;
11+
import net.minecraft.util.EnumHand;
12+
import net.minecraft.util.math.BlockPos;
13+
import net.minecraft.world.World;
14+
15+
import javax.annotation.Nullable;
16+
17+
public class BlockXPBox extends Block {
18+
public static final String NAME = "xpbox";
19+
20+
public BlockXPBox() {
21+
super(Material.ROCK);
22+
setRegistryName(NAME);
23+
setUnlocalizedName(NAME);
24+
setHardness(.5f);
25+
setCreativeTab(CreativeTabs.DECORATIONS);
26+
}
27+
28+
@Override
29+
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
30+
if (!worldIn.isRemote) {
31+
sendXPMessage(playerIn);
32+
}
33+
return true;
34+
}
35+
36+
private static void sendXPMessage(EntityPlayer player) {
37+
PacketHandler.wrapper.sendTo(
38+
new MessageXP(player.getCapability(XPBox.XP_CAPABILITY, null).value,
39+
getTotalXP(player)),
40+
(EntityPlayerMP) player);
41+
}
42+
43+
public static int getTotalXP(EntityPlayer player) {
44+
int xp = 0;
45+
for (int lv = 0; lv < player.experienceLevel; ++lv) {
46+
xp += xpBarCap(lv);
47+
}
48+
return xp + Math.round(player.experience * player.xpBarCap());
49+
}
50+
51+
private static int xpBarCap(int lv) {
52+
return lv >= 30 ? 112 + (lv - 30) * 9 : (lv >= 15 ? 37 + (lv - 15) * 5 : 7 + lv * 2);
53+
}
54+
55+
public static void updateXP(EntityPlayer player, int op, int xp) {
56+
int exp;
57+
XPCapability cap = player.getCapability(XPBox.XP_CAPABILITY, null);
58+
59+
switch (op) {
60+
case MessageOp.WITHDRAW:
61+
player.addExperience(xp);
62+
cap.value -= xp;
63+
break;
64+
case MessageOp.DEPOSIT:
65+
exp = getTotalXP(player);
66+
player.experience = 0;
67+
player.experienceLevel = 0;
68+
player.experienceTotal = 0;
69+
player.addExperience(exp - xp);
70+
cap.value += xp;
71+
break;
72+
case MessageOp.SETLEVEL:
73+
exp = getTotalXP(player) + cap.value;
74+
player.experience = 0;
75+
player.experienceLevel = 0;
76+
player.experienceTotal = 0;
77+
for (int lv = 0; lv < xp; ++lv) {
78+
int t = xpBarCap(lv);
79+
if (exp >= t) {
80+
exp -= t;
81+
player.addExperience(t);
82+
} else {
83+
player.addExperience(exp);
84+
exp = 0;
85+
break;
86+
}
87+
}
88+
if (exp > GuiXPBox.MAX)
89+
exp = GuiXPBox.MAX;
90+
cap.value = exp;
91+
break;
92+
}
93+
sendXPMessage(player);
94+
}
95+
}

src/main/java/xpbox/ClientProxy.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package xpbox;
2+
3+
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
4+
import net.minecraft.item.Item;
5+
import net.minecraftforge.client.model.ModelLoader;
6+
7+
public class ClientProxy extends CommonProxy {
8+
@Override
9+
public void registerItemRenderer(Item item) {
10+
ModelLoader.setCustomModelResourceLocation(item, 0,
11+
new ModelResourceLocation(item.getRegistryName().toString(), "inventory"));
12+
}
13+
}

src/main/java/xpbox/CommonProxy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package xpbox;
2+
3+
import net.minecraft.item.Item;
4+
5+
public class CommonProxy {
6+
public void registerItemRenderer(Item item) {}
7+
}

0 commit comments

Comments
 (0)