Skip to content

Commit

Permalink
1.3.BETA4
Browse files Browse the repository at this point in the history
- allow baubles to retain compatibility with mods created for older
versions.
- BaublesApi.getBaubles now returns IInventory again and a new method
has been created to return the new handler if you want to use that
instead.
  • Loading branch information
Azanor committed Oct 4, 2016
1 parent 15ada5d commit b2a15b8
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 14 deletions.
3 changes: 1 addition & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gradlew build
pause
cmd /k gradlew build
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'


version = "1.10.2-1.3.BETA3"
version = "1.10.2-1.3.BETA4"
group= "com.azanor.baubles"
archivesBaseName = "Baubles"

srcCompat = JavaVersion.VERSION_1_8
targetCompat = JavaVersion.VERSION_1_8

minecraft {
version = "1.10.2-12.18.1.2076"
version = "1.10.2-12.18.1.2084"
runDir = "run"
mappings = "snapshot_20160518"
makeObfSourceJar = false
Expand Down
3 changes: 1 addition & 2 deletions rebuild.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gradlew setupDecompWorkspace eclipse
pause
cmd /k gradlew setupDecompWorkspace eclipse
13 changes: 11 additions & 2 deletions src/main/java/baubles/api/BaublesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import baubles.api.cap.BaublesCapabilities;
import baubles.api.cap.IBaublesItemHandler;
import baubles.api.inv.BaublesInventoryWrapper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;

/**
* @author Azanor
Expand All @@ -11,11 +13,18 @@ public class BaublesApi
{

/**
* Retrieves the baubles inventory for the supplied player
* Retrieves the baubles inventory capability handler for the supplied player
*/
public static IBaublesItemHandler getBaubles(EntityPlayer player)
public static IBaublesItemHandler getBaublesHandler(EntityPlayer player)
{
return player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null);
}

/**
* Retrieves the baubles capability handler wrapped as a IInventory for the supplied player
*/
public static IInventory getBaubles(EntityPlayer player)
{
return new BaublesInventoryWrapper(player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null));
}
}
106 changes: 106 additions & 0 deletions src/main/java/baubles/api/inv/BaublesInventoryWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package baubles.api.inv;

import baubles.api.cap.IBaublesItemHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

public class BaublesInventoryWrapper implements IInventory {

final IBaublesItemHandler handler;

public BaublesInventoryWrapper(IBaublesItemHandler handler) {
super();
this.handler = handler;
}

@Override
public String getName() {
return "BaublesInventory";
}

@Override
public boolean hasCustomName() {
return false;
}

@Override
public ITextComponent getDisplayName() {
return new TextComponentString(this.getName());
}

@Override
public int getSizeInventory() {
return handler.getSlots();
}

@Override
public ItemStack getStackInSlot(int index) {
return handler.getStackInSlot(index);
}

@Override
public ItemStack decrStackSize(int index, int count) {
return handler.extractItem(index, count, false);
}

@Override
public ItemStack removeStackFromSlot(int index) {
ItemStack out = this.getStackInSlot(index);
handler.setStackInSlot(index, null);
return out;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
handler.setStackInSlot(index, stack);
}

@Override
public int getInventoryStackLimit() {
return 64;
}

@Override
public void markDirty() { }

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}

@Override
public void openInventory(EntityPlayer player) { }

@Override
public void closeInventory(EntityPlayer player) { }

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return handler.isItemValidForSlot(index, stack, null);
}

@Override
public int getField(int id) {
return 0;
}

@Override
public void setField(int id, int value) {}

@Override
public int getFieldCount() {
return 0;
}

@Override
public void clear() {
for (int i = 0; i < this.getSizeInventory(); ++i)
{
this.setInventorySlotContents(i, null);
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/baubles/api/package-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@API(owner = "Baubles", apiVersion = "1.3.0.0", provides = "Baubles|API")
@API(owner = "Baubles", apiVersion = "1.3.0.1", provides = "Baubles|API")
package baubles.api;

import net.minecraftforge.fml.common.API;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baubles/common/Baubles.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Baubles {

public static final String MODID = "baubles";
public static final String MODNAME = "Baubles";
public static final String VERSION = "1.3.BETA3";
public static final String VERSION = "1.3.BETA4";

@SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy")
public static CommonProxy proxy;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/baubles/common/event/EventHandlerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void playerTick(PlayerEvent.LivingUpdateEvent event) {
if (event.getEntity() instanceof EntityPlayer) {

EntityPlayer player = (EntityPlayer) event.getEntity();
IBaublesItemHandler baubles = BaublesApi.getBaubles(player);
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);

for (int a = 0; a < baubles.getSlots(); a++) {
if (baubles.getStackInSlot(a) != null && baubles.getStackInSlot(a).getItem() instanceof IBauble) {
Expand All @@ -71,7 +71,7 @@ public void playerDeath(PlayerDropsEvent event) {
}

public void dropItemsAt(EntityPlayer player, List<EntityItem> drops, Entity e) {
IBaublesItemHandler baubles = BaublesApi.getBaubles(player);
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); ++i) {
if (baubles.getStackInSlot(i) != null) {
EntityItem ei = new EntityItem(e.worldObj,
Expand Down Expand Up @@ -115,7 +115,7 @@ public void loadPlayerBaubles(EntityPlayer player, File file1, File file2) {
}

if (data != null) {
IBaublesItemHandler baubles = BaublesApi.getBaubles(player);
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
NBTTagList tagList = data.getTagList("Baubles.Inventory", 10);
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound nbttagcompound = (NBTTagCompound) tagList.getCompoundTagAt(i);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baubles/common/items/ItemRing.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public BaubleType getBaubleType(ItemStack itemstack) {
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
if(!world.isRemote) {
IBaublesItemHandler baubles = BaublesApi.getBaubles(player);
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
for(int i = 0; i < baubles.getSlots(); i++)
if(baubles.getStackInSlot(i) == null && baubles.isItemValidForSlot(i, stack, player)) {
baubles.setStackInSlot(i, stack.copy());
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.3.BETA4
- allow baubles to retain compatibility with mods created for older versions.
- BaublesApi.getBaubles now returns IInventory again and a new method has been created to return the new handler if you want to use that instead.

1.3.BETA3
- a few minor fixes / tweaks

Expand Down

0 comments on commit b2a15b8

Please sign in to comment.