mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-23 21:59:51 +00:00
Lots of changes, fixed a few crashes, and minor bugs. Also, doesnt need Asielib anymore
This commit is contained in:
1 parent
333c1d6596
commit
fd4351711a
146 files changed
+12167
-9527
No files matched your search
Executable → Regular
+36
-29
@@ -1,29 +1,36 @@
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.entity.EntityBallOMoss;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBallOMoss extends Item{
|
||||
|
||||
public ItemBallOMoss() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode) {
|
||||
--par1ItemStack.stackSize;
|
||||
}
|
||||
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!par2World.isRemote) {
|
||||
par2World.spawnEntityInWorld(new EntityBallOMoss(par2World,par3EntityPlayer));
|
||||
}
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
}
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.entity.EntityBallOMoss;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemBallOMoss extends Item
|
||||
{
|
||||
|
||||
public ItemBallOMoss()
|
||||
{
|
||||
super();
|
||||
setUnlocalizedName("ballMoss");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
if(!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
--par1ItemStack.stackSize;
|
||||
}
|
||||
|
||||
if(par2World.isRemote)
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if(!par2World.isRemote)
|
||||
{
|
||||
par2World.spawnEntityInWorld(new EntityBallOMoss(par2World, par3EntityPlayer));
|
||||
}
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+63
-57
@@ -1,57 +1,63 @@
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.CarvableVariation;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.api.Carvable;
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class ItemCarvable extends ItemBlock {
|
||||
|
||||
public ItemCarvable(Block block) {
|
||||
super(block);
|
||||
setMaxDamage(0);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack) {
|
||||
return "item." + Block.getBlockFromItem(this).getUnlocalizedName() + "." + itemstack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int damage) {
|
||||
return Block.getBlockFromItem(this).getIcon(2,damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips) {
|
||||
if(! Chisel.blockDescriptions) return;
|
||||
|
||||
Item item=General.getItem(stack);
|
||||
if(item==null) return;
|
||||
|
||||
Block block = Block.getBlockFromItem(this);
|
||||
if(! (block instanceof Carvable)) return;
|
||||
|
||||
Carvable carvable=(Carvable) block;
|
||||
CarvableVariation var=carvable.getVariation(stack.getItemDamage());
|
||||
if(var==null) return;
|
||||
|
||||
lines.add(var.description);
|
||||
}
|
||||
|
||||
}
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.api.ICarvable;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableVariation;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.utilities.General;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class ItemCarvable extends ItemBlock
|
||||
{
|
||||
|
||||
public ItemCarvable(Block block)
|
||||
{
|
||||
super(block);
|
||||
setMaxDamage(0);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack)
|
||||
{
|
||||
return "item." + Block.getBlockFromItem(this).getUnlocalizedName() + "." + itemstack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int damage)
|
||||
{
|
||||
return Block.getBlockFromItem(this).getIcon(2, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips)
|
||||
{
|
||||
if(!Chisel.blockDescriptions) return;
|
||||
|
||||
Item item = General.getItem(stack);
|
||||
if(item == null) return;
|
||||
|
||||
Block block = Block.getBlockFromItem(this);
|
||||
if(!(block instanceof ICarvable)) return;
|
||||
|
||||
ICarvable carvable = (ICarvable) block;
|
||||
CarvableVariation var = carvable.getVariation(stack.getItemDamage());
|
||||
if(var == null) return;
|
||||
|
||||
lines.add(var.description);
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+193
-185
@@ -1,185 +1,193 @@
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
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 java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import pl.asie.lib.network.Packet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.ServerConfigurationManager;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
public class ItemChisel extends ItemTool {
|
||||
Random random=new Random();
|
||||
public Carving carving;
|
||||
|
||||
private static final HashSet<String> toolSet = new HashSet<String>();
|
||||
|
||||
public ItemChisel(Carving c) {
|
||||
super(1,ToolMaterial.IRON,CarvableHelper.getChiselBlockSet());
|
||||
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(500);
|
||||
efficiencyOnProperMaterial=100f;
|
||||
|
||||
toolSet.add("chisel");
|
||||
carving=c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack) {
|
||||
return toolSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public void registerIcons(IconRegister register)
|
||||
{
|
||||
}*/
|
||||
|
||||
HashMap<String,Long> chiselUseTime=new HashMap<String,Long>();
|
||||
HashMap<String,String> chiselUseLocation=new HashMap<String,String>();
|
||||
|
||||
@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);
|
||||
|
||||
if(! ForgeHooks.isToolEffective(stack, block, blockMeta))
|
||||
return false;
|
||||
|
||||
ItemStack chiselTarget=null;
|
||||
|
||||
if(stack.stackTagCompound!=null){
|
||||
chiselTarget=ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("chiselTarget"));
|
||||
}
|
||||
|
||||
boolean chiselHasBlockInside=true;
|
||||
|
||||
boolean noReplace = false;
|
||||
|
||||
if(chiselTarget==null){
|
||||
chiselHasBlockInside=false;
|
||||
|
||||
Long useTime=chiselUseTime.get(player.getCommandSenderName());
|
||||
String loc=chiselUseLocation.get(player.getCommandSenderName());
|
||||
|
||||
if(useTime!=null && chiselUseLocation!=null && loc.equals(x+"|"+y+"|"+z)){
|
||||
long cooldown=20;
|
||||
long time=world.getWorldInfo().getWorldTotalTime();
|
||||
|
||||
//if(time>useTime-cooldown && time<useTime+cooldown) noReplace = true;
|
||||
}
|
||||
|
||||
CarvingVariation[] variations=carving.getVariations(block, blockMeta);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Item result = null;
|
||||
int targetMeta = 0;
|
||||
|
||||
if(!noReplace) {
|
||||
Item target = chiselTarget.getItem();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int updateValue = 2;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
stack.damageItem(1, player);
|
||||
if(stack.stackSize==0){
|
||||
player.inventory.mainInventory[player.inventory.currentItem]=
|
||||
chiselHasBlockInside?
|
||||
chiselTarget:
|
||||
null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.carving.CarvableHelper;
|
||||
import info.jbcs.minecraft.chisel.carving.Carving;
|
||||
import info.jbcs.minecraft.chisel.carving.CarvingVariation;
|
||||
import info.jbcs.minecraft.chisel.Chisel;
|
||||
import info.jbcs.minecraft.chisel.ChiselBlocks;
|
||||
import info.jbcs.minecraft.chisel.client.GeneralChiselClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class ItemChisel extends ItemTool
|
||||
{
|
||||
Random random = new Random();
|
||||
public Carving carving;
|
||||
|
||||
private static final HashSet<String> toolSet = new HashSet<String>();
|
||||
|
||||
public ItemChisel(Carving c)
|
||||
{
|
||||
super(1, ToolMaterial.IRON, CarvableHelper.getChiselBlockSet());
|
||||
|
||||
maxStackSize = 1;
|
||||
setMaxDamage(500);
|
||||
efficiencyOnProperMaterial = 100f;
|
||||
setUnlocalizedName("chisel");
|
||||
|
||||
toolSet.add("chisel");
|
||||
carving = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack)
|
||||
{
|
||||
return toolSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
|
||||
{
|
||||
entityplayer.openGui(Chisel.instance, 0, world, 0, 0, 0);
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
HashMap<String, Long> chiselUseTime = new HashMap<String, Long>();
|
||||
HashMap<String, String> chiselUseLocation = new HashMap<String, String>();
|
||||
|
||||
@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);
|
||||
|
||||
if(!ForgeHooks.isToolEffective(stack, block, blockMeta))
|
||||
return false;
|
||||
|
||||
ItemStack chiselTarget = null;
|
||||
|
||||
if(stack.stackTagCompound != null)
|
||||
{
|
||||
chiselTarget = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("chiselTarget"));
|
||||
}
|
||||
|
||||
boolean chiselHasBlockInside = true;
|
||||
|
||||
boolean noReplace = false;
|
||||
|
||||
if(chiselTarget == null)
|
||||
{
|
||||
chiselHasBlockInside = false;
|
||||
|
||||
Long useTime = chiselUseTime.get(player.getCommandSenderName());
|
||||
String loc = chiselUseLocation.get(player.getCommandSenderName());
|
||||
|
||||
if(useTime != null && chiselUseLocation != null && loc.equals(x + "|" + y + "|" + z))
|
||||
{
|
||||
long cooldown = 20;
|
||||
long time = world.getWorldInfo().getWorldTotalTime();
|
||||
|
||||
//if(time>useTime-cooldown && time<useTime+cooldown) noReplace = true;
|
||||
}
|
||||
|
||||
CarvingVariation[] variations = carving.getVariations(block, blockMeta);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Item result = null;
|
||||
int targetMeta = 0;
|
||||
|
||||
if(!noReplace)
|
||||
{
|
||||
Item target = chiselTarget.getItem();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int updateValue = 2;
|
||||
|
||||
if(noReplace)
|
||||
{
|
||||
result = Item.getItemFromBlock(block);
|
||||
targetMeta = blockMeta;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
//TODO chisel left click thingy
|
||||
// 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);
|
||||
if(stack.stackSize == 0)
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] =
|
||||
chiselHasBlockInside ?
|
||||
chiselTarget :
|
||||
null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable → Regular
+36
-33
@@ -1,33 +1,36 @@
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.entity.EntityCloudInABottle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemCloudInABottle extends Item {
|
||||
|
||||
public ItemCloudInABottle() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is
|
||||
* pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode) {
|
||||
--par1ItemStack.stackSize;
|
||||
}
|
||||
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if (!par2World.isRemote) {
|
||||
par2World.spawnEntityInWorld(new EntityCloudInABottle(par2World,par3EntityPlayer));
|
||||
}
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
}
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.entity.EntityCloudInABottle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemCloudInABottle extends Item
|
||||
{
|
||||
|
||||
public ItemCloudInABottle()
|
||||
{
|
||||
super();
|
||||
setUnlocalizedName("cloudBottle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
if(!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
--par1ItemStack.stackSize;
|
||||
}
|
||||
|
||||
if(par2World.isRemote)
|
||||
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
if(!par2World.isRemote)
|
||||
{
|
||||
par2World.spawnEntityInWorld(new EntityCloudInABottle(par2World, par3EntityPlayer));
|
||||
}
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+120
-87
@@ -1,87 +1,120 @@
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.block.BlockMarbleSlab;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemMarbleSlab extends ItemCarvable {
|
||||
|
||||
public ItemMarbleSlab(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given ItemBlock can be placed on the given side of the given block position.
|
||||
*/
|
||||
@Override
|
||||
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack){
|
||||
BlockMarbleSlab block = (BlockMarbleSlab)Block.getBlockFromItem(this);
|
||||
|
||||
switch(side){
|
||||
case 0: --y; break;
|
||||
case 1: ++y; break;
|
||||
case 2: --z; break;
|
||||
case 3: ++z; break;
|
||||
case 4: --x; break;
|
||||
case 5: ++x; break;
|
||||
}
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta=world.getBlockMetadata(x, y, z);
|
||||
|
||||
if((targetBlock.equals(block) || targetBlock.equals(block.top)) && meta==stack.getItemDamage())
|
||||
return true;
|
||||
|
||||
return world.canPlaceEntityOnSide(block, x, y, z, false, side, (Entity)null, stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hx, float hy, float hz){
|
||||
BlockMarbleSlab block = (BlockMarbleSlab)Block.getBlockFromItem(this);
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta=world.getBlockMetadata(x, y, z);
|
||||
boolean metaMatches=meta==stack.getItemDamage();
|
||||
|
||||
if(metaMatches && side==0 && targetBlock.equals(block.top)){
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
} else if(metaMatches && side==1 && targetBlock.equals(block.bottom)){
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean result=super.onItemUse(stack,player,world,x,y,z,side,hz,hy,hz);
|
||||
|
||||
|
||||
switch(side){
|
||||
case 0: --y; break;
|
||||
case 1: ++y; break;
|
||||
case 2: --z; break;
|
||||
case 3: ++z; break;
|
||||
case 4: --x; break;
|
||||
case 5: ++x; break;
|
||||
}
|
||||
|
||||
targetBlock = world.getBlock(x, y, z);
|
||||
meta=world.getBlockMetadata(x, y, z);
|
||||
|
||||
if(!result && (targetBlock.equals(block.top) || targetBlock.equals(block.bottom)) && meta==stack.getItemDamage()){
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!result)
|
||||
return false;
|
||||
|
||||
if(side != 0 && (side == 1 || hy <= 0.5D))
|
||||
return true;
|
||||
|
||||
world.setBlock(x, y, z, block.top, meta, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package info.jbcs.minecraft.chisel.item;
|
||||
|
||||
import info.jbcs.minecraft.chisel.block.BlockMarbleSlab;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemMarbleSlab extends ItemCarvable
|
||||
{
|
||||
|
||||
public ItemMarbleSlab(Block block)
|
||||
{
|
||||
super(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given ItemBlock can be placed on the given side of the given block position.
|
||||
*/
|
||||
@Override
|
||||
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
BlockMarbleSlab block = (BlockMarbleSlab) Block.getBlockFromItem(this);
|
||||
|
||||
switch(side)
|
||||
{
|
||||
case 0:
|
||||
--y;
|
||||
break;
|
||||
case 1:
|
||||
++y;
|
||||
break;
|
||||
case 2:
|
||||
--z;
|
||||
break;
|
||||
case 3:
|
||||
++z;
|
||||
break;
|
||||
case 4:
|
||||
--x;
|
||||
break;
|
||||
case 5:
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if((targetBlock.equals(block) || targetBlock.equals(block.top)) && meta == stack.getItemDamage())
|
||||
return true;
|
||||
|
||||
return world.canPlaceEntityOnSide(block, x, y, z, false, side, (Entity) null, stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hx, float hy, float hz)
|
||||
{
|
||||
BlockMarbleSlab block = (BlockMarbleSlab) Block.getBlockFromItem(this);
|
||||
|
||||
Block targetBlock = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
boolean metaMatches = meta == stack.getItemDamage();
|
||||
|
||||
if(metaMatches && side == 0 && targetBlock.equals(block.top))
|
||||
{
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
} else if(metaMatches && side == 1 && targetBlock.equals(block.bottom))
|
||||
{
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean result = super.onItemUse(stack, player, world, x, y, z, side, hz, hy, hz);
|
||||
|
||||
|
||||
switch(side)
|
||||
{
|
||||
case 0:
|
||||
--y;
|
||||
break;
|
||||
case 1:
|
||||
++y;
|
||||
break;
|
||||
case 2:
|
||||
--z;
|
||||
break;
|
||||
case 3:
|
||||
++z;
|
||||
break;
|
||||
case 4:
|
||||
--x;
|
||||
break;
|
||||
case 5:
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
|
||||
targetBlock = world.getBlock(x, y, z);
|
||||
meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if(!result && (targetBlock.equals(block.top) || targetBlock.equals(block.bottom)) && meta == stack.getItemDamage())
|
||||
{
|
||||
world.setBlock(x, y, z, block.master, meta, 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!result)
|
||||
return false;
|
||||
|
||||
if(side != 0 && (side == 1 || hy <= 0.5D))
|
||||
return true;
|
||||
|
||||
world.setBlock(x, y, z, block.top, meta, 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user