mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 00:07:37 +00:00
Merge remote-tracking branch 'origin/master'
Conflicts: src/main/java/info/jbcs/minecraft/chisel/Chisel.java
This commit is contained in:
commit
1dd65fd97a
2 files changed
+159
-19
No files matched your search
@@ -1,9 +1,13 @@
|
||||
package info.jbcs.minecraft.chisel;
|
||||
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.*;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.*;
|
||||
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -79,40 +83,43 @@ public class Chisel
|
||||
}
|
||||
|
||||
// Fix mapping of snakestoneSand, snakestoneStone, limestoneStairs, marbleStairs when loading an old (1.5.4) save
|
||||
else if(m.type == Type.BLOCK)
|
||||
else if (m.type == Type.BLOCK)
|
||||
{
|
||||
Block block = null;
|
||||
|
||||
if(General.cleanTags(m.name).equals("sandSnakestone"))
|
||||
if (General.cleanTags(m.name).equals("sandSnakestone"))
|
||||
block = GameRegistry.findBlock(Chisel.MOD_ID, "tile.snakestoneSand");
|
||||
else if(General.cleanTags(m.name).equals("snakestone"))
|
||||
else if (General.cleanTags(m.name).equals("snakestone"))
|
||||
block = GameRegistry.findBlock(Chisel.MOD_ID, "tile.snakestoneStone");
|
||||
else
|
||||
block = GameRegistry.findBlock(Chisel.MOD_ID, General.cleanTags(m.name));
|
||||
|
||||
if(block != null)
|
||||
if (block != null)
|
||||
{
|
||||
m.remap(block);
|
||||
FMLLog.getLogger().info("Remapping block " + m.name + " to " + General.getName(block));
|
||||
} else
|
||||
}
|
||||
else
|
||||
FMLLog.getLogger().warn("Block " + m.name + " could not get remapped.");
|
||||
} else if(m.type == Type.ITEM)
|
||||
}
|
||||
else if (m.type == Type.ITEM)
|
||||
{
|
||||
Item item = null;
|
||||
|
||||
if(General.cleanTags(m.name).equals("sandSnakestone"))
|
||||
if (General.cleanTags(m.name).equals("sandSnakestone"))
|
||||
item = GameRegistry.findItem(Chisel.MOD_ID, "tile.snakestoneSand");
|
||||
else if(General.cleanTags(m.name).equals("snakestone"))
|
||||
else if (General.cleanTags(m.name).equals("snakestone"))
|
||||
item = GameRegistry.findItem(Chisel.MOD_ID, "tile.snakestoneStone");
|
||||
else
|
||||
item = GameRegistry.findItem(Chisel.MOD_ID, General.cleanTags(m.name));
|
||||
|
||||
if(item != null)
|
||||
if (item != null)
|
||||
{
|
||||
m.remap(item);
|
||||
FMLLog.getLogger().info("Remapping item " + m.name + " to " + General.getName(item));
|
||||
|
||||
} else
|
||||
}
|
||||
else
|
||||
FMLLog.getLogger().warn("Item " + m.name + " could not get remapped.");
|
||||
}
|
||||
}
|
||||
@@ -211,5 +218,137 @@ public class Chisel
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
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() != 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(ChiselBlocks.blockCobblestone))
|
||||
match = true;
|
||||
if(!match && block.equals(Blocks.stone) && Block.getBlockFromItem(target).equals(ChiselBlocks.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() != chisel) return;
|
||||
>>>>>>> origin/master
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package info.jbcs.minecraft.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -11,8 +14,6 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class General
|
||||
{
|
||||
public static Random rand = new Random();
|
||||
@@ -65,7 +66,12 @@ public class General
|
||||
public static String getName(Block block)
|
||||
{
|
||||
String res = block.getUnlocalizedName();
|
||||
return res.substring(5);
|
||||
return cleanTags(res);
|
||||
}
|
||||
|
||||
public static String cleanTags(String tag)
|
||||
{
|
||||
return tag.replaceAll("[Cc]hisel\\p{Punct}", "").replaceFirst("^tile\\.", "").replaceFirst("^item\\.", "");
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +102,4 @@ public class General
|
||||
return par1World.rayTraceBlocks(var13, var23, par3);
|
||||
}
|
||||
|
||||
public static String cleanTags(String tag)
|
||||
{
|
||||
return tag.replaceAll("[Cc]hisel\\p{Punct}", "").replaceFirst("^tile\\.", "").replaceFirst("^item\\.", "");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user