mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-11 15:57:31 +00:00
Chisel 1.5.3
This commit is contained in:
1 parent
1525907cdd
commit
48e0c168b6
20 files changed
+1301
-1839
No files matched your search
@@ -19,11 +19,11 @@ public class Carving {
|
||||
public static Carving needle=new Carving();
|
||||
|
||||
String key(Item item,int metadata){
|
||||
return item.getUnlocalizedName()+"|"+metadata;
|
||||
return Item.itemRegistry.getNameForObject(item)+"|"+metadata;
|
||||
}
|
||||
|
||||
String key(Block block, int metadata){
|
||||
return block.getUnlocalizedName()+"|"+metadata;
|
||||
return Block.blockRegistry.getNameForObject(block)+"|"+metadata;
|
||||
}
|
||||
|
||||
public boolean isVariationOfSameClass(Block target,int metadata1, Block block2, int metadata2){
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,13 +1,8 @@
|
||||
package info.jbcs.minecraft.chisel;
|
||||
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
import info.jbcs.minecraft.utilities.packets.PacketData;
|
||||
import info.jbcs.minecraft.utilities.packets.PacketHandler;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
import pl.asie.lib.network.MessageHandlerBase;
|
||||
import pl.asie.lib.network.Packet;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package info.jbcs.minecraft.chisel.block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class BlockPoweredMarble extends BlockCarvable {
|
||||
public BlockPoweredMarble(Material m) {
|
||||
public class BlockCarvablePowered extends BlockCarvable {
|
||||
public BlockCarvablePowered(Material m) {
|
||||
super(m);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package info.jbcs.minecraft.chisel.block;
|
||||
|
||||
import info.jbcs.minecraft.chisel.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -19,12 +20,12 @@ public class BlockMarbleIceStairs extends BlockMarbleStairs {
|
||||
|
||||
@Override
|
||||
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) {
|
||||
Chisel.blockIce.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
ChiselBlocks.blockIce.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random) {
|
||||
return Chisel.blockIce.quantityDropped(par1Random);
|
||||
return ChiselBlocks.blockIce.quantityDropped(par1Random);
|
||||
}
|
||||
@Override
|
||||
public int damageDropped(int i) {
|
||||
@@ -33,7 +34,7 @@ public class BlockMarbleIceStairs extends BlockMarbleStairs {
|
||||
|
||||
@Override
|
||||
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
|
||||
Chisel.blockIce.updateTick(par1World, par2, par3, par4, par5Random);
|
||||
ChiselBlocks.blockIce.updateTick(par1World, par2, par3, par4, par5Random);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,15 +22,15 @@ public class BlockMarbleStairsMaker {
|
||||
blockBase=base;
|
||||
}
|
||||
|
||||
public void create(){
|
||||
create(null);
|
||||
public void create(String name){
|
||||
create(null, name);
|
||||
}
|
||||
|
||||
public void create(BlockMarbleStairsMakerCreator creator){
|
||||
public void create(BlockMarbleStairsMakerCreator creator, String name){
|
||||
blocks=new BlockMarbleStairs[carverHelper.variations.size()/2];
|
||||
|
||||
for(int i=0;i<blocks.length;i++){
|
||||
String n=blockName+"."+i;
|
||||
String n=name+"."+i;
|
||||
blocks[i]=creator==null?
|
||||
new BlockMarbleStairs(blockBase, i*2, carverHelper):
|
||||
creator.create(blockBase, i*2, carverHelper);
|
||||
@@ -42,7 +42,7 @@ public class BlockMarbleStairsMaker {
|
||||
CarvableVariation variation=carverHelper.variations.get(i*2+meta);
|
||||
|
||||
for(int j=0;j<8;j++)
|
||||
carverHelper.registerVariation(blockName+".orientation."+j,variation,blocks[i],j+meta*8);
|
||||
carverHelper.registerVariation(name+".orientation."+j,variation,blocks[i],j+meta*8);
|
||||
|
||||
CraftingManager.getInstance().addRecipe(new ItemStack(blocks[i], 4, meta*8), new Object[] { "* ", "** ", "***", '*', new ItemStack(blockBase, 1, i*2+meta)});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package info.jbcs.minecraft.chisel.entity;
|
||||
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
import info.jbcs.minecraft.chisel.GeneralChiselClient;
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -91,10 +92,10 @@ public class EntityBallOMoss extends EntityThrowable {
|
||||
resBlock = Blocks.mossy_cobblestone;
|
||||
} else if(block.equals(Blocks.cobblestone_wall) && meta==0){
|
||||
resMeta=1;
|
||||
} else if(block.equals(Chisel.blockCobblestone)){
|
||||
resBlock=Chisel.blockCobblestoneMossy;
|
||||
} else if(block.equals(Chisel.blockTemple)){
|
||||
resBlock=Chisel.blockTempleMossy;
|
||||
} else if(block.equals(ChiselBlocks.blockCobblestone)){
|
||||
resBlock=ChiselBlocks.blockCobblestoneMossy;
|
||||
} else if(block.equals(ChiselBlocks.blockTemple)){
|
||||
resBlock=ChiselBlocks.blockTempleMossy;
|
||||
}
|
||||
|
||||
if(resBlock.equals(block) && resMeta==meta) return;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package info.jbcs.minecraft.chisel.entity;
|
||||
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -96,7 +97,7 @@ public class EntityCloudInABottle extends EntityThrowable {
|
||||
for (int k2 = y; k2 < y + random.nextInt(1) + 2; k2++) {
|
||||
for (int l2 = z; l2 < z + random.nextInt(4) + 1; l2++) {
|
||||
if (world.getBlock(j2, k2, l2).isAir(world, j2, k2, l2) && Math.abs(j2 - x) + Math.abs(k2 - y) + Math.abs(l2 - z) < 4 * 1 + random.nextInt(2)) {
|
||||
world.setBlock(j2, k2, l2, Chisel.blockCloud);
|
||||
world.setBlock(j2, k2, l2, ChiselBlocks.blockCloud);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ import info.jbcs.minecraft.chisel.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.Carving;
|
||||
import info.jbcs.minecraft.chisel.CarvingVariation;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
import info.jbcs.minecraft.chisel.GeneralChiselClient;
|
||||
import info.jbcs.minecraft.chisel.Packets;
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
import info.jbcs.minecraft.utilities.packets.PacketData;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
@@ -71,6 +69,8 @@ public class ItemChisel extends ItemTool {
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack stack, final int x, final int y, final int z, EntityPlayer player){
|
||||
if(!Chisel.enableChiseling) return true;
|
||||
|
||||
World world=player.worldObj;
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int blockMeta=world.getBlockMetadata(x,y,z);
|
||||
@@ -86,7 +86,11 @@ public class ItemChisel extends ItemTool {
|
||||
|
||||
boolean chiselHasBlockInside=true;
|
||||
|
||||
boolean noReplace = false;
|
||||
|
||||
if(chiselTarget==null){
|
||||
chiselHasBlockInside=false;
|
||||
|
||||
Long useTime=chiselUseTime.get(player.getCommandSenderName());
|
||||
String loc=chiselUseLocation.get(player.getCommandSenderName());
|
||||
|
||||
@@ -94,65 +98,76 @@ public class ItemChisel extends ItemTool {
|
||||
long cooldown=20;
|
||||
long time=world.getWorldInfo().getWorldTotalTime();
|
||||
|
||||
if(time>useTime-cooldown && time<useTime+cooldown)
|
||||
return true;
|
||||
|
||||
//if(time>useTime-cooldown && time<useTime+cooldown) noReplace = true;
|
||||
}
|
||||
|
||||
CarvingVariation[] variations=carving.getVariations(block, blockMeta);
|
||||
if(variations==null || variations.length<2) return true;
|
||||
|
||||
int index=random.nextInt(variations.length-1);
|
||||
if(variations[index].equals(block) && variations[index].meta==blockMeta){
|
||||
index++;
|
||||
if(index>=variations.length) index=0;
|
||||
if(variations==null || variations.length<2) noReplace = true;
|
||||
else {
|
||||
int index=random.nextInt(variations.length-1);
|
||||
while (variations[index].block.equals(block) && variations[index].damage==blockMeta){
|
||||
index++;
|
||||
if(index>=variations.length) index=0;
|
||||
}
|
||||
CarvingVariation var=variations[index];
|
||||
chiselTarget=new ItemStack(var.block,1,var.damage);
|
||||
}
|
||||
CarvingVariation var=variations[index];
|
||||
chiselTarget=new ItemStack(var.block,1,var.damage);
|
||||
}
|
||||
Item result = null;
|
||||
int targetMeta = 0;
|
||||
|
||||
if(!noReplace) {
|
||||
Item target = chiselTarget.getItem();
|
||||
|
||||
chiselHasBlockInside=false;
|
||||
targetMeta=chiselTarget.getItemDamage();
|
||||
|
||||
boolean match = carving.isVariationOfSameClass(Block.getBlockFromItem(target),targetMeta,block,blockMeta);
|
||||
result = target;
|
||||
|
||||
/* special case: stone can be carved to cobble and bricks */
|
||||
if(Chisel.chiselStoneToCobbleBricks) {
|
||||
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ChiselBlocks.blockCobblestone))
|
||||
match=true;
|
||||
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ChiselBlocks.stoneBrick))
|
||||
match=true;
|
||||
}
|
||||
if(match == false) noReplace = true;
|
||||
}
|
||||
|
||||
Item target = chiselTarget.getItem();
|
||||
int updateValue = 2;
|
||||
|
||||
int targetMeta=chiselTarget.getItemDamage();
|
||||
|
||||
boolean match=carving.isVariationOfSameClass(Block.getBlockFromItem(target),targetMeta,block,blockMeta);
|
||||
Item result = target;
|
||||
if(noReplace) {
|
||||
result = Item.getItemFromBlock(block);
|
||||
targetMeta = blockMeta;
|
||||
}
|
||||
if(Block.getBlockFromItem(result).equals(block) && targetMeta == blockMeta) updateValue |= 4;
|
||||
//if(Block.getBlockFromItem(result) == null) return true;
|
||||
|
||||
|
||||
/* special case: stone can be carved to cobble and bricks */
|
||||
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(Chisel.blockCobblestone))
|
||||
match=true;
|
||||
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(Chisel.stoneBrick))
|
||||
match=true;
|
||||
|
||||
if(!match) return true;
|
||||
if(result.equals(block) && targetMeta == blockMeta) return true;
|
||||
|
||||
if(! world.isRemote || chiselHasBlockInside)
|
||||
world.setBlock(x, y, z, Block.getBlockFromItem(result), chiselTarget.getItemDamage(), 2);
|
||||
if(! world.isRemote || chiselHasBlockInside) {
|
||||
System.out.println("Changing to " + Item.itemRegistry.getNameForObject(result) + ":" + chiselTarget.getItemDamage());
|
||||
world.setBlock(x, y, z, Block.getBlockFromItem(result), targetMeta, updateValue);
|
||||
}
|
||||
|
||||
switch(FMLCommonHandler.instance().getEffectiveSide()){
|
||||
case SERVER:
|
||||
chiselUseTime.put(player.getCommandSenderName(), world.getWorldInfo().getWorldTotalTime());
|
||||
chiselUseLocation.put(player.getCommandSenderName(),x+"|"+y+"|"+z);
|
||||
|
||||
try {
|
||||
Packet packet = Chisel.packet.create(Packets.CHISELED).writeInt(x).writeInt(y).writeInt(z);
|
||||
Chisel.packet.sendToAllAround(packet, new TargetPoint(player.dimension, x, y, z, 30.0f));
|
||||
} catch(Exception e) { e.printStackTrace(); }
|
||||
break;
|
||||
|
||||
case CLIENT:
|
||||
if(chiselHasBlockInside){
|
||||
String sound=carving.getVariationSound(result, chiselTarget.getItemDamage());
|
||||
GeneralChiselClient.spawnChiselEffect(x, y, z, sound);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case SERVER:
|
||||
chiselUseTime.put(player.getCommandSenderName(), world.getWorldInfo().getWorldTotalTime());
|
||||
chiselUseLocation.put(player.getCommandSenderName(),x+"|"+y+"|"+z);
|
||||
|
||||
try {
|
||||
Packet packet = Chisel.packet.create(Packets.CHISELED).writeInt(x).writeInt(y).writeInt(z);
|
||||
Chisel.packet.sendToAllAround(packet, new TargetPoint(player.dimension, x, y, z, 30.0f));
|
||||
} catch(Exception e) { e.printStackTrace(); }
|
||||
break;
|
||||
|
||||
case CLIENT:
|
||||
if(chiselHasBlockInside){
|
||||
String sound=carving.getVariationSound(result, chiselTarget.getItemDamage());
|
||||
GeneralChiselClient.spawnChiselEffect(x, y, z, sound);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
stack.damageItem(1, player);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package info.jbcs.minecraft.chisel.render;
|
||||
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
import info.jbcs.minecraft.utilities.Drawing;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -66,7 +67,7 @@ public class BlockSpikesRenderer implements ISimpleBlockRenderingHandler {
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
|
||||
Tessellator tessellator=Tessellator.instance;
|
||||
IIcon icon=Chisel.blockSpiketrap.iconSpike;
|
||||
IIcon icon=ChiselBlocks.blockSpiketrap.iconSpike;
|
||||
// Icon icon=Chisel.blockSpiketrap.iconBase;
|
||||
|
||||
double h=0.85;
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class ContainerTileEntity<T extends TileEntity & IInventory> extends Container {
|
||||
public final IInventory playerInventory;
|
||||
public final T entity;
|
||||
public int playerSlotsCount;
|
||||
|
||||
public ContainerTileEntity(IInventory playerInv, T tileEntity,int startX,int startY) {
|
||||
playerInventory = playerInv;
|
||||
entity = tileEntity;
|
||||
|
||||
for (int k = 0; k < 3; k++) {
|
||||
for (int j1 = 0; j1 < 9; j1++) {
|
||||
addSlotToContainer(new Slot(playerInv, j1 + k * 9 + 9, startX + j1 * 18, startY + k * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l = 0; l < 9; l++) {
|
||||
addSlotToContainer(new Slot(playerInv, l, startX + l * 18, startY + 142-84));
|
||||
}
|
||||
|
||||
playerSlotsCount=inventorySlots.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return entity.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityplayer, int i) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(i);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (i < playerSlotsCount) {
|
||||
if (!mergeItemStack(itemstack1, playerSlotsCount, inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!mergeItemStack(itemstack1, 0, playerSlotsCount, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class Infodata {
|
||||
public String name;
|
||||
|
||||
public Hashtable<String, String> fields = new Hashtable<String, String>();
|
||||
public String[] lines;
|
||||
|
||||
public Infodata(String n) {
|
||||
name = n;
|
||||
}
|
||||
|
||||
public Infodata(String n,int lineCount) {
|
||||
name = n;
|
||||
lines = new String[lineCount];
|
||||
}
|
||||
|
||||
public String field(String key,String dflt) {
|
||||
String n = key.toLowerCase();
|
||||
|
||||
if (fields.containsKey(n)) return fields.get(n);
|
||||
|
||||
return dflt;
|
||||
}
|
||||
|
||||
public String field(String key) {
|
||||
return field(key, null);
|
||||
}
|
||||
|
||||
public int value(String key) {
|
||||
return Integer.parseInt(field(key, null));
|
||||
}
|
||||
|
||||
public void set(String key,String value) {
|
||||
fields.put(key.length() == 1 ? key : key.toLowerCase(), value);
|
||||
}
|
||||
|
||||
public void set(String key,int value) {
|
||||
fields.put(key.length() == 1 ? key : key.toLowerCase(), "" + value);
|
||||
}
|
||||
|
||||
public void write(Writer writer,int linebreakEvery) throws IOException {
|
||||
writer.write(name + " {\n");
|
||||
|
||||
Enumeration<String> keys = fields.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
if (key.length() == 1) continue;
|
||||
|
||||
writer.write("\t" + key + " = " + fields.get(key) + "\n");
|
||||
}
|
||||
|
||||
writer.write("\n");
|
||||
int linesWritten = 0;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
writer.write("\t" + lines[i] + "\n");
|
||||
linesWritten++;
|
||||
if (linebreakEvery != 0 && linesWritten % linebreakEvery == 0) writer.write("\n");
|
||||
}
|
||||
writer.write("\n");
|
||||
|
||||
keys = fields.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
if (key.length() != 1) continue;
|
||||
|
||||
writer.write("\t" + key + " = " + fields.get(key) + "\n");
|
||||
}
|
||||
writer.write("}");
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Infofile {
|
||||
static String[] stringArray=new String[0];
|
||||
public ArrayList<Infodata> data=new ArrayList<Infodata>();
|
||||
|
||||
public Infofile(File file) throws IOException {
|
||||
LineReader reader = new LineReader(file);
|
||||
String line;
|
||||
|
||||
Infodata d=null;
|
||||
ArrayList<String> lines=new ArrayList<String>();
|
||||
|
||||
int state = 0;
|
||||
|
||||
try{
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if((line=line.trim()).isEmpty()) continue;
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (line.charAt(line.length() - 1) != '{') {
|
||||
reader.die("unexpected: \""+line+"\" (expecting name and opening bracket)");
|
||||
}
|
||||
|
||||
|
||||
line=line.substring(0,line.length()-1).trim();
|
||||
state=1;
|
||||
|
||||
d=new Infodata(line);
|
||||
|
||||
lines.clear();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (line.equals("}")) {
|
||||
state=0;
|
||||
|
||||
d.lines=lines.toArray(stringArray);
|
||||
data.add(d);
|
||||
continue;
|
||||
}
|
||||
|
||||
int index=line.indexOf('=');
|
||||
if(index!=-1){
|
||||
String key=line.substring(0, index).trim().toLowerCase();
|
||||
String val=line.substring(index+1,line.length()).trim();
|
||||
|
||||
d.fields.put(key,val);
|
||||
} else{
|
||||
lines.add(line);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally{
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class InventoryStatic implements IInventory {
|
||||
public final ItemStack items[];
|
||||
|
||||
public InventoryStatic(int size) {
|
||||
items = new ItemStack[size];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onInventoryChanged(int slot) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return items[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (items[i] != null) {
|
||||
if (items[i].stackSize <= j) {
|
||||
ItemStack itemstack = items[i];
|
||||
items[i] = null;
|
||||
onInventoryChanged();
|
||||
onInventoryChanged(i);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
ItemStack itemstack1 = items[i].splitStack(j);
|
||||
|
||||
if (items[i].stackSize == 0) {
|
||||
items[i] = null;
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
onInventoryChanged(i);
|
||||
return itemstack1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
items[i] = itemstack;
|
||||
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
onInventoryChanged(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound1.getByte("slot") & 0xff;
|
||||
|
||||
if (j >= 0 && j < items.length) {
|
||||
items[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("slot", (byte) i);
|
||||
items[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("items", nbttaglist);
|
||||
}
|
||||
|
||||
private int getFirstEmptyStack(int start, int end) {
|
||||
for (int i = start; i <= end; i++) {
|
||||
if (items[i] == null) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int storeItemStack(ItemStack itemstack, int start, int end) {
|
||||
for (int i = start; i <= end; i++) {
|
||||
if (items[i] != null && items[i].getItem().equals(itemstack.getItem() )&& items[i].isStackable() && items[i].stackSize < items[i].getMaxStackSize() && items[i].stackSize < getInventoryStackLimit() && (!items[i].getHasSubtypes() || items[i].getItemDamage() == itemstack.getItemDamage())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int storePartialItemStack(ItemStack itemstack, int start, int end) {
|
||||
Item i = itemstack.getItem();
|
||||
int j = itemstack.stackSize;
|
||||
int k = storeItemStack(itemstack, start, end);
|
||||
|
||||
if (k < 0) {
|
||||
k = getFirstEmptyStack(start, end);
|
||||
}
|
||||
|
||||
if (k < 0) {
|
||||
return j;
|
||||
}
|
||||
|
||||
if (items[k] == null) {
|
||||
items[k] = new ItemStack(i, 0, itemstack.getItemDamage());
|
||||
}
|
||||
|
||||
int l = j;
|
||||
|
||||
if (l > items[k].getMaxStackSize() - items[k].stackSize) {
|
||||
l = items[k].getMaxStackSize() - items[k].stackSize;
|
||||
}
|
||||
|
||||
if (l > getInventoryStackLimit() - items[k].stackSize) {
|
||||
l = getInventoryStackLimit() - items[k].stackSize;
|
||||
}
|
||||
|
||||
if (l == 0) {
|
||||
return j;
|
||||
} else {
|
||||
j -= l;
|
||||
items[k].stackSize += l;
|
||||
items[k].animationsToGo = 5;
|
||||
onInventoryChanged();
|
||||
onInventoryChanged(k);
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addItemStackToInventory(ItemStack itemstack, int start, int end) {
|
||||
if (itemstack == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!itemstack.isItemDamaged()) {
|
||||
int i;
|
||||
|
||||
do {
|
||||
i = itemstack.stackSize;
|
||||
itemstack.stackSize = storePartialItemStack(itemstack, start, end);
|
||||
} while (itemstack.stackSize > 0 && itemstack.stackSize < i);
|
||||
|
||||
return itemstack.stackSize < i;
|
||||
}
|
||||
|
||||
int j = getFirstEmptyStack(start, end);
|
||||
|
||||
if (j >= 0) {
|
||||
items[j] = ItemStack.copyItemStack(itemstack);
|
||||
items[j].animationsToGo = 5;
|
||||
itemstack.stackSize = 0;
|
||||
onInventoryChanged();
|
||||
onInventoryChanged(j);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addItemStackToInventory(ItemStack itemstack) {
|
||||
return addItemStackToInventory(itemstack, 0, items.length - 1);
|
||||
}
|
||||
|
||||
public ItemStack takeItems(Item item, int damage, int count) {
|
||||
ItemStack res = null;
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] == null || !items[i].getItem().equals(item) || items[i].getItemDamage() != damage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (res == null) {
|
||||
res = new ItemStack(item, 0, damage);
|
||||
}
|
||||
|
||||
while (items[i] != null && res.stackSize < count && items[i].stackSize > 0) {
|
||||
res.stackSize++;
|
||||
items[i].stackSize--;
|
||||
|
||||
if (items[i].stackSize == 0) {
|
||||
items[i] = null;
|
||||
}
|
||||
|
||||
onInventoryChanged(i);
|
||||
}
|
||||
|
||||
if (res.stackSize >= count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onInventoryChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null && items[i].getItem() != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void throwItems(World world, int x, int y, int z){
|
||||
if(world.isRemote) return;
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
ItemStack itemstack = items[i];
|
||||
if (itemstack == null) continue;
|
||||
|
||||
items[i]=null;
|
||||
|
||||
float xx = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float yy = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float zz = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
while (itemstack.stackSize > 0) {
|
||||
int c = world.rand.nextInt(21) + 10;
|
||||
if (c > itemstack.stackSize) {
|
||||
c = itemstack.stackSize;
|
||||
}
|
||||
|
||||
itemstack.stackSize -= c;
|
||||
EntityItem entityitem = new EntityItem(world, x + xx, y + yy, z + zz, new ItemStack(itemstack.getItem(), c, itemstack.getItemDamage()));
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
|
||||
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
|
||||
onInventoryChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LineReader extends BufferedReader {
|
||||
String filename;
|
||||
int line = 0;
|
||||
|
||||
public LineReader(File file) throws FileNotFoundException {
|
||||
super(new FileReader(file));
|
||||
|
||||
filename = file.getName();
|
||||
}
|
||||
|
||||
@Override public String readLine() {
|
||||
line++;
|
||||
|
||||
try {
|
||||
return super.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
String where(){
|
||||
return filename+", line "+line;
|
||||
}
|
||||
|
||||
public void die(String cause) throws IOException{
|
||||
throw new IOException(where()+": "+cause);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class PacketData {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
byte packetIndex;
|
||||
|
||||
public abstract void data(DataOutputStream stream) throws IOException;
|
||||
|
||||
ByteArrayOutputStream getData() {
|
||||
DataOutputStream stream = new DataOutputStream(s);
|
||||
|
||||
try {
|
||||
stream.writeByte(packetIndex);
|
||||
data(stream);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package info.jbcs.minecraft.utilities.packets;
|
||||
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public abstract class PacketHandler implements Comparable {
|
||||
/*static ArrayList<PacketHandler> items = new ArrayList<PacketHandler>();
|
||||
|
||||
public static final String channel = "AUTO:Multi";
|
||||
public static final String channelDummy = "AUTO:-";
|
||||
|
||||
int index;
|
||||
Object mod;
|
||||
String name;
|
||||
|
||||
public PacketHandler(String n) {
|
||||
items.add(this);
|
||||
name = n;
|
||||
}
|
||||
|
||||
public void create() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object a) {
|
||||
return name.compareTo(((PacketHandler) a).name);
|
||||
}
|
||||
|
||||
public void sendToPlayer(EntityPlayerMP player,PacketData data) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() != Side.SERVER)
|
||||
return;
|
||||
|
||||
|
||||
data.packetIndex = (byte) index;
|
||||
ByteArrayOutputStream stream = data.getData();
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channel;
|
||||
packet.data = stream.toByteArray();
|
||||
packet.length = stream.size();
|
||||
player.playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
}
|
||||
|
||||
public void sendToPlayers(double posX,double posY,double posZ,int dimension,double distance,PacketData data) {
|
||||
ServerConfigurationManager mgr = MinecraftServer.getServer().getConfigurationManager();
|
||||
for (int j = 0; j < mgr.playerEntityList.size(); ++j) {
|
||||
EntityPlayerMP p = (EntityPlayerMP) mgr.playerEntityList.get(j);
|
||||
|
||||
if (p.dimension != dimension) continue;
|
||||
if (! General.isInRange(distance, p.posX, p.posY, p.posZ, posX, posY, posZ)) continue;
|
||||
|
||||
sendToPlayer(p,data);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToServer(PacketData data) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() != Side.CLIENT)
|
||||
return;
|
||||
|
||||
data.packetIndex = (byte) index;
|
||||
ByteArrayOutputStream stream = data.getData();
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channel;
|
||||
packet.data = stream.toByteArray();
|
||||
packet.length = stream.size();
|
||||
PacketHandlerClient.send(packet);
|
||||
}
|
||||
|
||||
public static void register(Object mod) {
|
||||
Collections.sort(items);
|
||||
int index = 0;
|
||||
|
||||
for (PacketHandler h : items) {
|
||||
if(h.mod==null)
|
||||
h.mod = mod;
|
||||
h.index = index++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPacketData(INetworkManager manager, Packet250CustomPayload packet, EntityPlayer player) {
|
||||
if (!packet.channel.equals(channel))
|
||||
return;
|
||||
packet.channel=channelDummy;
|
||||
|
||||
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
try {
|
||||
byte index = inputStream.readByte();
|
||||
|
||||
if (index >= items.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
items.get(index).onData(inputStream, player);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onData(DataInputStream stream, EntityPlayer player) throws IOException;
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user