mirror of
https://github.com/GTNewHorizons/BetterBuildersWands.git
synced 2026-10-26 14:24:03 +00:00
Implement undo feature.
This commit is contained in:
1 parent
a143a171f4
commit
96eb173612
5 files changed
+131
-4
No files matched your search
@@ -7,6 +7,7 @@ import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
@@ -23,6 +24,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.simple.SimpleLogger;
|
||||
import org.apache.logging.log4j.util.PropertiesUtil;
|
||||
import portablejim.bbw.core.BlockEvents;
|
||||
import portablejim.bbw.core.OopsCommand;
|
||||
import portablejim.bbw.core.items.ItemRestrictedWandAdvanced;
|
||||
import portablejim.bbw.core.items.ItemRestrictedWandBasic;
|
||||
import portablejim.bbw.core.items.ItemUnrestrictedWand;
|
||||
@@ -112,6 +114,11 @@ public class BetterBuildersWandsMod {
|
||||
GameRegistry.addRecipe(new ShapelessRecipes(newWand(14), Arrays.asList(newWand(13), newWand(13))));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
event.registerServerCommand(new OopsCommand());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void keypress(InputEvent event) {
|
||||
//FMLClientHandler.instance().
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package portablejim.bbw.core;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import portablejim.bbw.BetterBuildersWandsMod;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.core.items.IWandItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* /wandOops command.
|
||||
*/
|
||||
public class OopsCommand extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "wandOops";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/wandOops";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] arguments) {
|
||||
if(sender instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
ItemStack currentItemstack = player.getCurrentEquippedItem();
|
||||
if(currentItemstack != null && currentItemstack.getItem() != null
|
||||
&& currentItemstack.getItem() instanceof IWandItem) {
|
||||
NBTTagCompound tagComponent = currentItemstack.getTagCompound();
|
||||
|
||||
NBTTagCompound bbwCompound;
|
||||
if(tagComponent != null && tagComponent.hasKey("bbw", Constants.NBT.TAG_COMPOUND) && tagComponent.getCompoundTag("bbw").hasKey("lastPlaced", Constants.NBT.TAG_INT_ARRAY)) {
|
||||
bbwCompound = tagComponent.getCompoundTag("bbw");
|
||||
ArrayList<Point3d> pointList = unpackNbt(bbwCompound.getIntArray("lastPlaced"));
|
||||
for (Point3d point : pointList) {
|
||||
player.getEntityWorld().setBlockToAir(point.x, point.y, point.z);
|
||||
}
|
||||
if(bbwCompound.hasKey("lastBlock", Constants.NBT.TAG_STRING) && bbwCompound.hasKey("lastPerBlock", Constants.NBT.TAG_INT)) {
|
||||
GameRegistry.UniqueIdentifier lastBlock = new GameRegistry.UniqueIdentifier(bbwCompound.getString("lastBlock"));
|
||||
ItemStack itemStack = GameRegistry.findItemStack(lastBlock.modId, lastBlock.name, 1);
|
||||
int count = bbwCompound.getInteger("lastPerBlock") * pointList.size();
|
||||
int stackSize = itemStack.getMaxStackSize();
|
||||
int fullStacks = count / stackSize;
|
||||
for(int i = 0; i < fullStacks; i++) {
|
||||
ItemStack newStack = itemStack.copy();
|
||||
newStack.stackSize = stackSize;
|
||||
player.worldObj.spawnEntityInWorld(new EntityItem(player.getEntityWorld(), player.posX, player.posY, player.posZ, newStack));
|
||||
}
|
||||
ItemStack finalStack = itemStack.copy();
|
||||
finalStack.stackSize = count % stackSize;
|
||||
player.worldObj.spawnEntityInWorld(new EntityItem(player.getEntityWorld(), player.posX, player.posY, player.posZ, finalStack));
|
||||
|
||||
bbwCompound.removeTag("lastPlaced");
|
||||
bbwCompound.removeTag("lastBlock");
|
||||
bbwCompound.removeTag("lastPerBlock");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new WrongUsageException(BetterBuildersWandsMod.LANGID + ".chat.error.noundo");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new WrongUsageException(BetterBuildersWandsMod.LANGID + ".chat.error.nowand");
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new WrongUsageException(BetterBuildersWandsMod.LANGID + ".chat.error.bot");
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList<Point3d> unpackNbt(int[] placedBlocks) {
|
||||
ArrayList<Point3d> output = new ArrayList<Point3d>();
|
||||
int countPoints = placedBlocks.length / 3;
|
||||
for(int i = 0; i < countPoints * 3; i += 3) {
|
||||
output.add(new Point3d(placedBlocks[i], placedBlocks[i+1], placedBlocks[i+2]));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,17 @@ package portablejim.bbw.core;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import portablejim.bbw.core.wands.IWand;
|
||||
import portablejim.bbw.basics.EnumLock;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -146,7 +145,8 @@ public class WandWorker {
|
||||
return toPlace;
|
||||
}
|
||||
|
||||
public void placeBlocks(ItemStack itemStack, LinkedList<Point3d> blockPosList, Point3d originalBlock) {
|
||||
public ArrayList<Point3d> placeBlocks(ItemStack itemStack, LinkedList<Point3d> blockPosList, Point3d originalBlock) {
|
||||
ArrayList<Point3d> placedBlocks = new ArrayList<Point3d>();
|
||||
for(Point3d blockPos : blockPosList) {
|
||||
/*if(player.countItems(getEquivalentItemStack(originalBlock)) < 1) {
|
||||
break;
|
||||
@@ -156,6 +156,7 @@ public class WandWorker {
|
||||
|
||||
if(blockPlaceSuccess) {
|
||||
world.playPlaceAtBlock(blockPos, world.getBlock(originalBlock));
|
||||
placedBlocks.add(blockPos);
|
||||
if (!player.isCreative()) {
|
||||
wand.placeBlock(itemStack, player.getPlayer());
|
||||
}
|
||||
@@ -163,8 +164,11 @@ public class WandWorker {
|
||||
if(!takeFromInventory) {
|
||||
FMLLog.info("BBW takeback: %s", blockPos.toString());
|
||||
world.setBlockToAir(blockPos);
|
||||
placedBlocks.remove(placedBlocks.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return placedBlocks;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package portablejim.bbw.core.items;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -24,6 +25,7 @@ import portablejim.bbw.shims.CreativePlayerShim;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -62,7 +64,21 @@ public abstract class ItemBasicWand extends Item implements IWandItem{
|
||||
if (targetItemstack != null) {
|
||||
LinkedList<Point3d> blocks = worker.getBlockPositionList(clickedPos, ForgeDirection.getOrientation(side), numBlocks, getMode(itemstack), getFaceLock(itemstack));
|
||||
|
||||
worker.placeBlocks(itemstack, blocks, clickedPos);
|
||||
ArrayList<Point3d> placedBlocks = worker.placeBlocks(itemstack, blocks, clickedPos);
|
||||
if(placedBlocks.size() > 0) {
|
||||
int[] placedIntArray = new int[placedBlocks.size() * 3];
|
||||
for (int i = 0; i < placedBlocks.size(); i++) {
|
||||
Point3d currentPoint = placedBlocks.get(i);
|
||||
placedIntArray[i * 3] = currentPoint.x;
|
||||
placedIntArray[i * 3 + 1] = currentPoint.y;
|
||||
placedIntArray[i * 3 + 2] = currentPoint.z;
|
||||
}
|
||||
NBTTagCompound placedNBT = new NBTTagCompound();
|
||||
placedNBT.setIntArray("lastPlaced", placedIntArray);
|
||||
placedNBT.setString("lastBlock", GameRegistry.findUniqueIdentifierFor(targetItemstack.getItem()).toString());
|
||||
placedNBT.setInteger("lastPerBlock", 1);
|
||||
itemstack.setTagInfo("bbw", placedNBT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,3 +21,7 @@ bbw.chat.mode.verticaleastwest=Mode: East-West (+ Vertical) - Extend east, west,
|
||||
bbw.chat.mode.horizontal=Mode: Horizontal - Extend left and right from the original block. No building on top/bottom face.
|
||||
bbw.chat.mode.vertical= Mode: Vertical - Extend up and down from the original block. No building on top/bottom face
|
||||
bbw.chat.mode.nolock=Mode: No Lock - Extend left, right, up and down from the original block.
|
||||
|
||||
bbw.chat.error.noundo=I can't remember what this wand last built.
|
||||
bbw.chat.error.nowand=You need to run this with a wand from Better Builders Wands in your hand.
|
||||
bbw.chat.error.bot=AI can detect Non-players. Please don't do that again.
|
||||
Reference in new issue
Block a user