mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 00:07:37 +00:00
Begin chisel mode implementation
This commit is contained in:
1 parent
86713ab449
commit
89299f6e27
8 files changed
+141
-33
No files matched your search
@@ -1,6 +1,76 @@
|
||||
package com.cricketcraft.chisel.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselSound;
|
||||
|
||||
public enum ChiselMode {
|
||||
|
||||
SINGLE, CIRCLETHREE, COLLUM, SIDEWAYS
|
||||
SINGLE {
|
||||
|
||||
@Override
|
||||
public void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation) {
|
||||
setVariation(player, world, x, y, z, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z), variation);
|
||||
}
|
||||
},
|
||||
PANEL {
|
||||
|
||||
@Override
|
||||
public void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
if (side == ForgeDirection.UP || side == ForgeDirection.DOWN) {
|
||||
setVariation(player, world, x + dx, y, z + dy, block, meta, variation);
|
||||
} else if (side == ForgeDirection.EAST || side == ForgeDirection.WEST) {
|
||||
setVariation(player, world, x, y + dy, z + dx, block, meta, variation);
|
||||
} else {
|
||||
setVariation(player, world, x + dx, y + dy, z, block, meta, variation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
COLUMN {
|
||||
|
||||
@Override
|
||||
public void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) {
|
||||
setVariation(player, world, x, y, z, block, meta, variation);
|
||||
setVariation(player, world, x, y + 1, z, block, meta, variation);
|
||||
setVariation(player, world, x, y - 1, z, block, meta, variation);
|
||||
} else {
|
||||
// TODO top/bottom
|
||||
}
|
||||
}
|
||||
}; // TODO SIDEWAYS
|
||||
|
||||
public abstract void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation);
|
||||
|
||||
/**
|
||||
* Assumes that the player is holding a chisel
|
||||
*/
|
||||
private static void setVariation(EntityPlayer player, World world, int x, int y, int z, Block origBlock, int origMeta, ICarvingVariation v) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (block == v.getBlock() && meta == v.getBlockMeta()) {
|
||||
return; // don't chisel to the same thing
|
||||
}
|
||||
if (origBlock != block || origMeta != meta) {
|
||||
return; // don't chisel if this doesn't match the target block (for the AOE modes)
|
||||
}
|
||||
|
||||
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v), (EntityPlayerMP) player);
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), v);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CarvingUtils {
|
||||
|
||||
@@ -15,12 +15,14 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.CarvingUtils;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.client.GeneralChiselClient;
|
||||
import com.cricketcraft.chisel.init.ChiselItems;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessageAutoChisel;
|
||||
import com.cricketcraft.chisel.network.message.MessageSlotUpdate;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -207,7 +209,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
/** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */
|
||||
private void chiselItem(int chiseled) {
|
||||
if (!worldObj.isRemote) {
|
||||
((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], inventory[TARGET]);
|
||||
((IChiselItem) inventory[CHISEL].getItem()).onChisel(worldObj, this, CHISEL, inventory[CHISEL], General.getVariation(inventory[TARGET]));
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this, chiseled, true), worldObj.provider.dimensionId);
|
||||
} else {
|
||||
GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]);
|
||||
|
||||
@@ -24,6 +24,18 @@ public class Carving {
|
||||
private Carving() {
|
||||
}
|
||||
|
||||
public ICarvingVariation getVariation(Block block, int metadata) {
|
||||
ICarvingGroup g = getGroup(block, metadata);
|
||||
if (g != null) {
|
||||
for (ICarvingVariation v : g.getVariations()) {
|
||||
if (v.getBlock() == block && v.getBlockMeta() == metadata) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ICarvingVariation> getVariations(Block block, int metadata) {
|
||||
ICarvingGroup group = getGroup(block, metadata);
|
||||
if (group == null)
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
|
||||
public class SlotChiselSelection extends Slot {
|
||||
|
||||
@@ -55,7 +56,7 @@ public class SlotChiselSelection extends Slot {
|
||||
|
||||
selInventory.updateItems();
|
||||
|
||||
((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj, player.inventory, player.inventory.currentItem, container.chisel, crafted);
|
||||
((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj, player.inventory, player.inventory.currentItem, container.chisel, General.getVariation(crafted));
|
||||
|
||||
/*
|
||||
* ItemStack stack=player.inventory.getItemStack();
|
||||
|
||||
@@ -3,20 +3,18 @@ package com.cricketcraft.chisel.item.chisel;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselSound;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -24,6 +22,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
public final class ChiselController {
|
||||
|
||||
public static final ChiselController INSTANCE = new ChiselController();
|
||||
|
||||
private long lastTickClick = 0;
|
||||
|
||||
private ChiselController() {
|
||||
}
|
||||
@@ -60,11 +60,13 @@ public final class ChiselController {
|
||||
|
||||
if (chisel.canChiselBlock(event.world, x, y, z, block, metadata)) {
|
||||
ItemStack target = General.getChiselTarget(held);
|
||||
ChiselMode mode = General.getChiselMode(held);
|
||||
ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face];
|
||||
|
||||
if (target != null) {
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == Block.getBlockFromItem(target.getItem()) && v.getBlockMeta() == target.getItemDamage()) {
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, v, target);
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -77,13 +79,26 @@ public final class ChiselController {
|
||||
}
|
||||
|
||||
ICarvingVariation newVar = variations[idx];
|
||||
setVariation(event.entityPlayer, event.world, x, y, z, newVar, new ItemStack(newVar.getBlock(), 1, newVar.getItemMeta()));
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, newVar);
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
// Make sure we have not responded this tick
|
||||
if (event.world.getTotalWorldTime() == lastTickClick) {
|
||||
break;
|
||||
} else {
|
||||
lastTickClick = event.world.getTotalWorldTime();
|
||||
}
|
||||
|
||||
if (!event.world.isRemote && event.entityPlayer.isSneaking()) {
|
||||
ChiselMode mode = General.getChiselMode(held);
|
||||
General.setChiselMode(held, ChiselMode.values()[(mode.ordinal() + 1) % 3]);
|
||||
event.entityPlayer.addChatMessage(new ChatComponentText(General.getChiselMode(held).toString()));
|
||||
break;
|
||||
}
|
||||
if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held)) {
|
||||
event.entityPlayer.openGui(Chisel.instance, 0, event.world, 0, 0, 0);
|
||||
}
|
||||
@@ -91,18 +106,4 @@ public final class ChiselController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes that the player is holding a chisel
|
||||
*/
|
||||
private void setVariation(EntityPlayer player, World world, int x, int y, int z, ICarvingVariation v, ItemStack target) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (block == v.getBlock() && meta == v.getBlockMeta()) {
|
||||
return; // don't chisel to the same thing
|
||||
}
|
||||
|
||||
PacketHandler.INSTANCE.sendTo(new MessageChiselSound(x, y, z, v), (EntityPlayerMP) player);
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), target);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.config.Configurations;
|
||||
import com.cricketcraft.chisel.utils.GeneralClient;
|
||||
@@ -77,11 +78,6 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChiselMode getChiselMode(ItemStack itemStack) {
|
||||
return ChiselMode.SINGLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpenGui(World world, EntityPlayer player, ItemStack chisel) {
|
||||
return true;
|
||||
@@ -93,7 +89,7 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ItemStack target) {
|
||||
public void onChisel(World world, IInventory inv, int slot, ItemStack chisel, ICarvingVariation target) {
|
||||
if (Configurations.allowChiselDamage) {
|
||||
chisel.setItemDamage(chisel.getItemDamage() + 1);
|
||||
if (chisel.getItemDamage() >= chisel.getMaxDamage()) {
|
||||
@@ -102,7 +98,7 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
String sound = carving.getVariationSound(target.getItem(), target.getItemDamage());
|
||||
String sound = carving.getVariationSound(target.getBlock(), target.getItemMeta());
|
||||
EntityPlayer player = Chisel.proxy.getClientPlayer();
|
||||
GeneralClient.playChiselSound(world, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), sound);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.cricketcraft.chisel.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -14,6 +15,10 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
|
||||
public class General {
|
||||
|
||||
public static Random rand = new Random();
|
||||
@@ -98,8 +103,8 @@ public class General {
|
||||
public static final String[] sGNames = new String[] { "White", "Orange", "Magenta", "Light Blue", "Yellow", "Lime", "Pink", "Gray", "Light Gray", "Cyan", "Purple", "Blue", "Brown", "Green",
|
||||
"Red", "Black" };
|
||||
|
||||
public static final String[] featureColors = new String[] { "white", "orange", "magenta", "lightblue", "yellow", "lime", "pink", "darkgray", "lightgray", "cyan", "purple", "blue", "brown", "green",
|
||||
"red", "black" };
|
||||
public static final String[] featureColors = new String[] { "white", "orange", "magenta", "lightblue", "yellow", "lime", "pink", "darkgray", "lightgray", "cyan", "purple", "blue", "brown",
|
||||
"green", "red", "black" };
|
||||
|
||||
public static void setChiselTarget(ItemStack chisel, ItemStack target) {
|
||||
initTag(chisel);
|
||||
@@ -115,4 +120,23 @@ public class General {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
private static final String MODE_KEY = "chiselMode";
|
||||
public static ChiselMode getChiselMode(ItemStack chisel) {
|
||||
if (chisel.stackTagCompound == null || Strings.isNullOrEmpty(chisel.stackTagCompound.getString(MODE_KEY))) {
|
||||
initTag(chisel);
|
||||
chisel.stackTagCompound.setString(MODE_KEY, ChiselMode.SINGLE.name());
|
||||
}
|
||||
|
||||
return Enum.valueOf(ChiselMode.class, chisel.stackTagCompound.getString(MODE_KEY));
|
||||
}
|
||||
|
||||
public static void setChiselMode(ItemStack chisel, ChiselMode mode) {
|
||||
initTag(chisel);
|
||||
chisel.stackTagCompound.setString(MODE_KEY, mode.name());
|
||||
}
|
||||
|
||||
public static ICarvingVariation getVariation(ItemStack stack) {
|
||||
return Carving.chisel.getVariation(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user