This repository has been archived by the owner on May 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12183c0
commit 6e0edf6
Showing
24 changed files
with
1,077 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* GNU LESSER GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
* | ||
* You can view LICENCE file for details. | ||
* | ||
* @author The Dragonet Team | ||
*/ | ||
|
||
package org.dragonet.inventory; | ||
|
||
import com.google.common.collect.Lists; | ||
import java.util.ArrayList; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class ItemList { | ||
private ArrayList<ItemStack> items; | ||
|
||
public ItemList() { | ||
this.items = new ArrayList<>(); | ||
} | ||
|
||
public ItemList(ArrayList<ItemStack> items) { | ||
this.items = items; | ||
} | ||
|
||
public ItemList(ItemStack[] items){ | ||
this.items = Lists.newArrayList(items); | ||
} | ||
|
||
public ItemList(Inventory inventory){ | ||
this(); | ||
for(int i = 0; i < inventory.getSize(); i++){ | ||
if(inventory.getItem(i) != null){ | ||
this.items.add(inventory.getItem(i)); | ||
} | ||
} | ||
} | ||
|
||
public boolean tryToRemove(ItemStack item){ | ||
ArrayList<ItemStack> original = this.cloneList(); | ||
if(item == null || item.getTypeId() == 0) return true; | ||
int toRemove = item.getAmount(); | ||
for(int i = 0; i < items.size(); i++){ | ||
if(toRemove == 0) break; | ||
if(items.get(i) == null) continue; | ||
int typeID = items.get(i).getTypeId(); | ||
int damage = items.get(i).getDurability(); | ||
int amount = items.get(i).getAmount(); | ||
if(typeID == item.getTypeId() && damage == item.getDurability()){ | ||
//We found the item | ||
if(amount > toRemove){ | ||
//SUCCESS | ||
items.get(i).setAmount(amount - toRemove); | ||
return true; | ||
}else{ | ||
items.set(i, null); | ||
toRemove -= amount; | ||
} | ||
} | ||
} | ||
if(toRemove <= 0){ | ||
return true; | ||
}else{ | ||
this.items = original; | ||
return false; | ||
} | ||
} | ||
|
||
private ArrayList<ItemStack> cloneList(){ | ||
ArrayList<ItemStack> cloned = new ArrayList<>(); | ||
for(ItemStack item : this.items){ | ||
cloned.add(item.clone()); | ||
} | ||
return cloned; | ||
} | ||
|
||
public ArrayList<ItemStack> getItems() { | ||
return items; | ||
} | ||
|
||
public ItemStack[] getContents(){ | ||
return this.items.toArray(new ItemStack[0]); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/dragonet/net/packet/minecraft/AddItemEntityPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* GNU LESSER GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
* | ||
* You can view LICENCE file for details. | ||
* | ||
* @author The Dragonet Team | ||
*/ | ||
|
||
package org.dragonet.net.packet.minecraft; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.dragonet.inventory.PEInventorySlot; | ||
import org.dragonet.utilities.io.PEBinaryWriter; | ||
|
||
public class AddItemEntityPacket extends PEPacket { | ||
|
||
public int eid; | ||
public PEInventorySlot item; | ||
public float x; | ||
public float y; | ||
public float z; | ||
public byte yaw; | ||
public byte pitch; | ||
public byte roll; | ||
|
||
@Override | ||
public int pid() { | ||
return PEPacketIDs.ADD_ITEM_ENTITY_PACKET; | ||
} | ||
|
||
@Override | ||
public void encode() { | ||
try { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
PEBinaryWriter writer = new PEBinaryWriter(bos); | ||
writer.writeByte((byte) (this.pid() & 0xFF)); | ||
writer.writeInt(eid); | ||
PEInventorySlot.writeSlot(writer, item); | ||
writer.writeFloat(x); | ||
writer.writeFloat(y); | ||
writer.writeFloat(z); | ||
writer.writeByte(yaw); | ||
writer.writeByte(pitch); | ||
writer.writeByte(roll); | ||
this.setData(bos.toByteArray()); | ||
} catch (IOException e) { | ||
} | ||
} | ||
|
||
@Override | ||
public void decode() { | ||
} | ||
|
||
} |
Oops, something went wrong.