mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-11 15:57:31 +00:00
Add ability for chisels to define their own chisel modes
This commit is contained in:
1 parent
aeebccf83e
commit
bef19466cf
7 files changed
+91
-17
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this on chisel items which require more control over chisel modes
|
||||
* (including adding new modes).
|
||||
*/
|
||||
public interface IAdvancedChisel {
|
||||
|
||||
/**
|
||||
* Gets the next mode the button in the GUI should switch to given the
|
||||
* current mode.
|
||||
*
|
||||
* @param stack
|
||||
* The {@link ItemStack} representing the chisel
|
||||
* @param current
|
||||
* The {@link IChiselMode} that is currently active
|
||||
* @return The next {@link IChiselMode} in the loop
|
||||
*/
|
||||
public IChiselMode getNextMode(ItemStack stack, IChiselMode current);
|
||||
|
||||
/**
|
||||
* Gets an {@link IChiselMode} instance from a String name
|
||||
*
|
||||
* @param chisel
|
||||
* The {@link ItemStack} representing the chisel
|
||||
* @param name
|
||||
* The name of the {@link IChiselMode mode}
|
||||
* @return An {@link IChiselMode} that has the name {@code name}
|
||||
*/
|
||||
public IChiselMode getMode(ItemStack chisel, String name);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IChiselMode {
|
||||
|
||||
void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation);
|
||||
|
||||
/**
|
||||
* Implemented implicitly by enums. If your IChiselMode is not an enum
|
||||
* constant, this needs to be implemented explicitly.
|
||||
*
|
||||
* @return The name of the mode.
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import net.minecraft.inventory.Slot;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.IAdvancedChisel;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.inventory.ContainerChisel;
|
||||
import com.cricketcraft.chisel.inventory.InventoryChiselSelection;
|
||||
import com.cricketcraft.chisel.inventory.SlotChiselInput;
|
||||
@@ -23,7 +25,7 @@ public class GuiChisel extends GuiContainer {
|
||||
|
||||
public EntityPlayer player;
|
||||
public ContainerChisel container;
|
||||
private ChiselMode currentMode;
|
||||
private IChiselMode currentMode;
|
||||
|
||||
public GuiChisel(InventoryPlayer iinventory, InventoryChiselSelection menu) {
|
||||
super(new ContainerChisel(iinventory, menu));
|
||||
@@ -103,9 +105,15 @@ public class GuiChisel extends GuiContainer {
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
|
||||
currentMode = currentMode.next();
|
||||
setButtonText();
|
||||
if (container.chisel != null && container.chisel.getItem() instanceof IAdvancedChisel) {
|
||||
IAdvancedChisel item = (IAdvancedChisel) container.chisel.getItem();
|
||||
currentMode = item.getNextMode(container.chisel, currentMode);
|
||||
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
|
||||
} else {
|
||||
currentMode = ChiselMode.next(currentMode);
|
||||
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
|
||||
setButtonText();
|
||||
}
|
||||
}
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
@@ -72,7 +73,7 @@ public final class ChiselController {
|
||||
|
||||
if (chisel.canChiselBlock(event.world, x, y, z, block, metadata)) {
|
||||
ItemStack target = General.getChiselTarget(held);
|
||||
ChiselMode mode = General.getChiselMode(held);
|
||||
IChiselMode mode = General.getChiselMode(held);
|
||||
ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face];
|
||||
|
||||
if (target != null) {
|
||||
|
||||
@@ -10,10 +10,11 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselSound;
|
||||
|
||||
public enum ChiselMode {
|
||||
public enum ChiselMode implements IChiselMode {
|
||||
|
||||
SINGLE {
|
||||
|
||||
@@ -86,8 +87,6 @@ public enum ChiselMode {
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
@@ -116,8 +115,11 @@ public enum ChiselMode {
|
||||
}
|
||||
}
|
||||
|
||||
public ChiselMode next() {
|
||||
ChiselMode[] values = values();
|
||||
return values[(ordinal() + 1) % values.length];
|
||||
public static ChiselMode next(IChiselMode currentMode) {
|
||||
if (currentMode instanceof ChiselMode) {
|
||||
ChiselMode[] values = values();
|
||||
return values[(((ChiselMode) currentMode).ordinal() + 1) % values.length];
|
||||
}
|
||||
return SINGLE;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.IAdvancedChisel;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.item.chisel.ChiselMode;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
|
||||
@@ -12,7 +14,6 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
|
||||
public class MessageChiselMode implements IMessage {
|
||||
|
||||
public MessageChiselMode(){
|
||||
@@ -20,8 +21,8 @@ public class MessageChiselMode implements IMessage {
|
||||
|
||||
private String mode;
|
||||
|
||||
public MessageChiselMode(ChiselMode current) {
|
||||
this.mode = current.next().name();
|
||||
public MessageChiselMode(IChiselMode iChiselMode) {
|
||||
this.mode = iChiselMode.name();
|
||||
}
|
||||
|
||||
public void toBytes(ByteBuf buf) {
|
||||
@@ -38,7 +39,11 @@ public class MessageChiselMode implements IMessage {
|
||||
public IMessage onMessage(MessageChiselMode message, MessageContext ctx) {
|
||||
ItemStack stack = ctx.getServerHandler().playerEntity.getCurrentEquippedItem();
|
||||
if (stack != null && stack.getItem() instanceof IChiselItem) {
|
||||
General.setChiselMode(stack, ChiselMode.valueOf(message.mode));
|
||||
if (stack.getItem() instanceof IAdvancedChisel) {
|
||||
General.setChiselMode(stack, ((IAdvancedChisel) stack.getItem()).getMode(stack, message.mode));
|
||||
} else {
|
||||
General.setChiselMode(stack, ChiselMode.valueOf(message.mode));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.IAdvancedChisel;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.carving.Carving;
|
||||
import com.cricketcraft.chisel.carving.CarvingVariation;
|
||||
import com.cricketcraft.chisel.item.chisel.ChiselMode;
|
||||
@@ -123,16 +125,21 @@ public class General {
|
||||
}
|
||||
|
||||
private static final String MODE_KEY = "chiselMode";
|
||||
public static ChiselMode getChiselMode(ItemStack chisel) {
|
||||
public static IChiselMode getChiselMode(ItemStack chisel) {
|
||||
if (chisel.stackTagCompound == null || Strings.isNullOrEmpty(chisel.stackTagCompound.getString(MODE_KEY))) {
|
||||
initTag(chisel);
|
||||
chisel.stackTagCompound.setString(MODE_KEY, ChiselMode.SINGLE.name());
|
||||
}
|
||||
|
||||
String name = chisel.stackTagCompound.getString(MODE_KEY);
|
||||
if (chisel.getItem() instanceof IAdvancedChisel) {
|
||||
return ((IAdvancedChisel)chisel.getItem()).getMode(chisel, name);
|
||||
}
|
||||
|
||||
return Enum.valueOf(ChiselMode.class, chisel.stackTagCompound.getString(MODE_KEY));
|
||||
}
|
||||
|
||||
public static void setChiselMode(ItemStack chisel, ChiselMode mode) {
|
||||
public static void setChiselMode(ItemStack chisel, IChiselMode mode) {
|
||||
initTag(chisel);
|
||||
chisel.stackTagCompound.setString(MODE_KEY, mode.name());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user