Merge remote-tracking branch 'origin/master'

This commit is contained in:
TheCricket committed 2014-12-01 09:12:55 -05:00
commit 594ea146dd
2 files changed
+271 -232

No files matched your search

@@ -1,192 +1,209 @@
package info.jbcs.minecraft.chisel;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import info.jbcs.minecraft.chisel.api.ChiselMode;
import info.jbcs.minecraft.chisel.carving.CarvingVariation;
import info.jbcs.minecraft.chisel.client.GeneralChiselClient;
import info.jbcs.minecraft.chisel.init.ModBlocks;
import info.jbcs.minecraft.chisel.init.ModItems;
import info.jbcs.minecraft.chisel.item.ItemChisel;
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.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import java.util.HashMap;
import java.util.Random;
public class ChiselLeftClick
{
HashMap<String, Long> chiselUseTime = new HashMap<String, Long>();
HashMap<String, String> chiselUseLocation = new HashMap<String, String>();
Random random = new Random();
@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event)
{
if(event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
if(!Configurations.enableChiseling) return;
EntityPlayer player = event.entityPlayer;
ItemStack stack = player.getHeldItem();
if(stack == null || stack.getItem() != ModItems.chisel) return;
World world = event.world;
int x = event.x;
int y = event.y;
int z = event.z;
Block block = world.getBlock(x, y, z);
int blockMeta = world.getBlockMetadata(x, y, z);
ItemStack chiselTarget = null;
if(stack.stackTagCompound != null)
{
chiselTarget = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("chiselTarget"));
}
boolean chiselHasBlockInside = true;
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) return; //noReplace = true;
}
CarvingVariation[] variations = ItemChisel.carving.getVariations(block, blockMeta);
if(variations == null || variations.length < 2) return; //noReplace = true;
else
{
int index = blockMeta + 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;
Item target = chiselTarget.getItem();
targetMeta = chiselTarget.getItemDamage();
boolean match = ItemChisel.carving.isVariationOfSameClass(Block.getBlockFromItem(target), targetMeta, block, blockMeta);
result = target;
/* special case: stone can be carved to cobble and bricks */
if(Configurations.chiselStoneToCobbleBricks)
{
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ModBlocks.cobblestone))
match = true;
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ModBlocks.stoneBrick))
match = true;
}
if(!match)
return; //noReplace = true;
int updateValue = 1;
if(!world.isRemote || chiselHasBlockInside)
{
world.setBlock(x, y, z, Block.getBlockFromItem(result), targetMeta, updateValue);
world.markBlockForUpdate(x, y, z);
}
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 = ItemChisel.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;
}
}
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event)
{
if(!Configurations.enableChiseling) return;
EntityPlayer player = event.getPlayer();
ItemStack stack = player.getHeldItem();
if(stack == null || stack.getItem() != ModItems.chisel) return;
event.setCanceled(true);
}
public static void setBlock(World world, int x, int y, int z, ChiselMode chiselMode, Block previousBlock, int previousMetadata, Block newBlock, int newMetadata, ForgeDirection direction)
{
if(chiselMode == ChiselMode.SINGLE)
{
world.setBlock(x, y, z, newBlock, newMetadata, 2);
} else if(chiselMode == ChiselMode.CIRCLETHREE)
{
int radius = 1;
for(int i = -radius; i <= radius; i++)
for(int j = -radius; j <= radius; j++)
{
//TODO facing stuff so this can be anywhere
if(world.getBlock(x + i, y, z + j) != null)
{
if(world.getBlock(x + i, y, z + j) == previousBlock && world.getBlockMetadata(x + i, y, z + j) == previousMetadata)
{
int shiftedX = x;
int shiftedY = y;
int shiftedZ = z;
world.setBlock(shiftedX, shiftedY, shiftedZ, newBlock, newMetadata, 2);
}
}
}
}
}
}
package info.jbcs.minecraft.chisel;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import info.jbcs.minecraft.chisel.api.ChiselMode;
import info.jbcs.minecraft.chisel.carving.CarvingVariation;
import info.jbcs.minecraft.chisel.client.GeneralChiselClient;
import info.jbcs.minecraft.chisel.init.ModBlocks;
import info.jbcs.minecraft.chisel.init.ModItems;
import info.jbcs.minecraft.chisel.item.ItemChisel;
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.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import java.util.HashMap;
import java.util.Random;
public class ChiselLeftClick
{
HashMap<String, Long> chiselUseTime = new HashMap<String, Long>();
HashMap<String, String> chiselUseLocation = new HashMap<String, String>();
Random random = new Random();
@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event)
{
if(event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
if(!Configurations.enableChiseling) return;
EntityPlayer player = event.entityPlayer;
ItemStack stack = player.getHeldItem();
if(stack == null || stack.getItem() != ModItems.chisel) return;
World world = event.world;
int x = event.x;
int y = event.y;
int z = event.z;
Block block = world.getBlock(x, y, z);
int blockMeta = world.getBlockMetadata(x, y, z);
ItemStack chiselTarget = null;
if(stack.stackTagCompound != null)
{
chiselTarget = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("chiselTarget"));
}
boolean chiselHasBlockInside = true;
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) return; //noReplace = true;
}
CarvingVariation[] variations = ItemChisel.carving.getVariations(block, blockMeta);
if(variations == null || variations.length < 2) return; //noReplace = true;
else
{
int index = -1;
//Find the index of the next block in the variation list
for (int i = 0; i < variations.length; ++i)
{
CarvingVariation currVariation = variations[i];
//If the metadata matches, then we are interested in the block AFTER this one
if (currVariation.block.equals(block) && currVariation.meta == blockMeta)
{
index = i + 1;
}
}
//If no index was found, something is wrong. Return.
if (index < 0)
{
return;
}
//If the the current block is the last in the list, loop back to the first
else if (index >= variations.length)
{
index = 0;
}
CarvingVariation var = variations[index];
chiselTarget = new ItemStack(var.block, 1, var.damage);
}
}
Item result = null;
int targetMeta = 0;
Item target = chiselTarget.getItem();
targetMeta = chiselTarget.getItemDamage();
boolean match = ItemChisel.carving.isVariationOfSameClass(Block.getBlockFromItem(target), targetMeta, block, blockMeta);
result = target;
/* special case: stone can be carved to cobble and bricks */
if(Configurations.chiselStoneToCobbleBricks)
{
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ModBlocks.cobblestone))
match = true;
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ModBlocks.stoneBrick))
match = true;
}
if(!match)
return; //noReplace = true;
int updateValue = 1;
if(!world.isRemote || chiselHasBlockInside)
{
world.setBlock(x, y, z, Block.getBlockFromItem(result), targetMeta, updateValue);
world.markBlockForUpdate(x, y, z);
}
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 = ItemChisel.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;
}
}
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event)
{
if(!Configurations.enableChiseling) return;
EntityPlayer player = event.getPlayer();
ItemStack stack = player.getHeldItem();
if(stack == null || stack.getItem() != ModItems.chisel) return;
event.setCanceled(true);
}
public static void setBlock(World world, int x, int y, int z, ChiselMode chiselMode, Block previousBlock, int previousMetadata, Block newBlock, int newMetadata, ForgeDirection direction)
{
if(chiselMode == ChiselMode.SINGLE)
{
world.setBlock(x, y, z, newBlock, newMetadata, 2);
} else if(chiselMode == ChiselMode.CIRCLETHREE)
{
int radius = 1;
for(int i = -radius; i <= radius; i++)
for(int j = -radius; j <= radius; j++)
{
//TODO facing stuff so this can be anywhere
if(world.getBlock(x + i, y, z + j) != null)
{
if(world.getBlock(x + i, y, z + j) == previousBlock && world.getBlockMetadata(x + i, y, z + j) == previousMetadata)
{
int shiftedX = x;
int shiftedY = y;
int shiftedZ = z;
world.setBlock(shiftedX, shiftedY, shiftedZ, newBlock, newMetadata, 2);
}
}
}
}
}
}
@@ -4,13 +4,25 @@
item.chisel.name=凿子
item.ballMoss.name=苔藓球
item.cloudBottle.name=瓶装云朵
item.smashingRock.name=碎石块
# Block localizations
# Have fun! ~zombiepig333
#Chisel 2
#Auto Chisel
tile.autoChisel.name=自动雕凿机
#Leaves
tile.leaves.6.desc=枯树叶
tile.leaves.7.desc=精致修剪的树叶
tile.leaves.8.desc=粉色叶瓣
tile.leaves.9.desc=红色玫瑰花瓣
tile.leaves.10.desc=白色玫瑰花瓣
tile.leaves.11.desc=圣诞树挂饰
tile.leaves.12.desc=圣诞树灯饰
#Void Stone Blocks
tile.voidstone.name=虚空石
tile.voidstone.0.desc=金属镶板虚空石
@@ -26,6 +38,16 @@ tile.voidstone.15.desc=斜纹镶板虚空石
tile.voidstonePillar.name=虚空石柱
tile.voidstonePillar.0.desc=竖纹虚空石柱
#Waterstone
tile.waterstone.name=水石
tile.waterstone.0.desc=水石砖
tile.waterstone.1.desc=黑色水石
tile.waterstone.2.desc=水石花砖
tile.waterstone.3.desc=无序砌成的水石砖
tile.waterstone.4.desc=爬行者雕纹水石
tile.waterstone.5.desc=镶板水石
tile.waterstone.6.desc=精致镶板水石
#Chisel 1
#Cobblestone Blocks
@@ -261,22 +283,22 @@ tile.limestoneStairs.15.desc=深色镶板灰岩楼梯
#Factory Blocks
tile.factoryblock.name=工厂方块
tile.blockFactory.0.desc=生锈金属块&点状图案
tile.blockFactory.1.desc=生锈金属块
tile.blockFactory.2.desc=锈蚀金属块
tile.blockFactory.3.desc=略锈的金属块
tile.blockFactory.4.desc=格栅块
tile.blockFactory.5.desc=紫影格栅块
tile.blockFactory.6.desc=黄黑相间的警示方块
tile.blockFactory.7.desc=橙白相间的警示方块
tile.blockFactory.8.desc=精密电路方块
tile.blockFactory.9.desc=精致金属盒
tile.blockFactory.10.desc=镀金精密电路方块
tile.blockFactory.11.desc=镀金紫色生锈方块
tile.blockFactory.12.desc=磨光金属建筑方块
tile.blockFactory.13.desc=磨损金属墙体&通风口
tile.blockFactory.14.desc=生锈金属块
tile.blockFactory.15.desc=磨损金属壳
tile.factory.0.desc=生锈金属块&点状图案
tile.factory.1.desc=生锈金属块
tile.factory.2.desc=锈蚀金属块
tile.factory.3.desc=略锈的金属块
tile.factory.4.desc=格栅块
tile.factory.5.desc=紫影格栅块
tile.factory.6.desc=黄黑相间的警示方块
tile.factory.7.desc=橙白相间的警示方块
tile.factory.8.desc=精密电路方块
tile.factory.9.desc=精致金属盒
tile.factory.10.desc=镀金精密电路方块
tile.factory.11.desc=镀金紫色生锈方块
tile.factory.12.desc=磨光金属建筑方块
tile.factory.13.desc=磨损金属墙体&通风口
tile.factory.14.desc=生锈金属块
tile.factory.15.desc=磨损金属壳
#Diamond blocks
tile.diamond_block.name=钻石块
@@ -338,17 +360,17 @@ tile.sandstoneScribbles.desc=刻文沙石
#Concrete
tile.concrete.name=混凝土
tile.blockConcrete.0.desc=混凝土
tile.blockConcrete.1.desc=混凝土块
tile.blockConcrete.2.desc=双层混凝土台阶
tile.blockConcrete.3.desc=混凝土方砖
tile.blockConcrete.4.desc=风化混凝土
tile.blockConcrete.5.desc=风化混凝土块
tile.blockConcrete.6.desc=风化双层混凝土台阶
tile.blockConcrete.7.desc=风化混凝土方砖
tile.blockConcrete.8.desc=局部风化的混凝土
tile.blockConcrete.9.desc=局部风化的混凝土块
tile.blockConcrete.10.desc=沥青
tile.concrete.0.desc=混凝土
tile.concrete.1.desc=混凝土块
tile.concrete.2.desc=双层混凝土台阶
tile.concrete.3.desc=混凝土方砖
tile.concrete.4.desc=风化混凝土
tile.concrete.5.desc=风化混凝土块
tile.concrete.6.desc=风化双层混凝土台阶
tile.concrete.7.desc=风化混凝土方砖
tile.concrete.8.desc=局部风化的混凝土
tile.concrete.9.desc=局部风化的混凝土块
tile.concrete.10.desc=沥青
#Road Line
tile.roadLine.name=道路标线
@@ -501,19 +523,19 @@ tile.stoneBrick.15.desc=罪恶的石砖
#Dirt
tile.dirt.name=泥土
tile.blockDirt.0.desc=杂乱堆叠的泥砖
tile.blockDirt.1.desc=模仿地狱砖设计的泥砖
tile.blockDirt.2.desc=泥砖
tile.blockDirt.3.desc=圆石状泥砖
tile.blockDirt.4.desc=加固圆石状泥砖
tile.blockDirt.5.desc=加固泥土
tile.blockDirt.6.desc=快乐灵魂泥土
tile.blockDirt.7.desc=大块錾制泥土
tile.blockDirt.8.desc=覆盖着泥土的大块錾制泥土
tile.blockDirt.9.desc=水平花纹泥土
tile.blockDirt.10.desc=垂直花纹泥土
tile.blockDirt.11.desc=页状泥土
tile.blockDirt.12.desc=破碎的泥土
tile.dirt.0.desc=杂乱堆叠的泥砖
tile.dirt.1.desc=模仿地狱砖设计的泥砖
tile.dirt.2.desc=泥砖
tile.dirt.3.desc=圆石状泥砖
tile.dirt.4.desc=加固圆石状泥砖
tile.dirt.5.desc=加固泥土
tile.dirt.6.desc=快乐灵魂泥土
tile.dirt.7.desc=大块錾制泥土
tile.dirt.8.desc=覆盖着泥土的大块錾制泥土
tile.dirt.9.desc=水平花纹泥土
tile.dirt.10.desc=垂直花纹泥土
tile.dirt.11.desc=页状泥土
tile.dirt.12.desc=破碎的泥土
#Ice
tile.ice.name=冰