mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-13 16:54:13 +00:00
Finish chisel modes
This commit is contained in:
1 parent
981982f918
commit
665ed94a99
5 files changed
+131
-8
No files matched your search
@@ -3,6 +3,7 @@ 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.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@@ -44,15 +45,44 @@ public enum ChiselMode {
|
||||
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
|
||||
int facing = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) {
|
||||
setVariation(player, world, x, y + i, z, block, meta, variation);
|
||||
} else {
|
||||
if (facing == 0 || facing == 2) {
|
||||
setVariation(player, world, x, y, z + i, block, meta, variation);
|
||||
} else {
|
||||
setVariation(player, world, x + i, y, z, block, meta, variation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}; // TODO SIDEWAYS
|
||||
},
|
||||
ROW {
|
||||
|
||||
@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);
|
||||
int facing = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
if (side != ForgeDirection.DOWN && side != ForgeDirection.UP) {
|
||||
if (side == ForgeDirection.EAST || side == ForgeDirection.WEST) {
|
||||
setVariation(player, world, x, y, z + i, block, meta, variation);
|
||||
} else {
|
||||
setVariation(player, world, x + i, y, z, block, meta, variation);
|
||||
}
|
||||
} else {
|
||||
if (facing == 0 || facing == 2) {
|
||||
setVariation(player, world, x + i, y, z, block, meta, variation);
|
||||
} else {
|
||||
setVariation(player, world, x, y, z + i, block, meta, variation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void chiselAll(EntityPlayer player, World world, int x, int y, int z, ForgeDirection side, ICarvingVariation variation);
|
||||
|
||||
@@ -73,4 +103,9 @@ public enum ChiselMode {
|
||||
world.setBlock(x, y, z, v.getBlock(), v.getBlockMeta(), 3);
|
||||
((IChiselItem) player.getCurrentEquippedItem().getItem()).onChisel(world, player.inventory, player.inventory.currentItem, player.getCurrentEquippedItem(), v);
|
||||
}
|
||||
|
||||
public ChiselMode next() {
|
||||
ChiselMode[] values = values();
|
||||
return values[(ordinal() + 1) % values.length];
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,29 @@
|
||||
package com.cricketcraft.chisel.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.inventory.ContainerChisel;
|
||||
import com.cricketcraft.chisel.inventory.InventoryChiselSelection;
|
||||
import com.cricketcraft.chisel.inventory.SlotChiselInput;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselMode;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
import com.cricketcraft.chisel.utils.GeneralClient;
|
||||
|
||||
public class GuiChisel extends GuiContainer {
|
||||
|
||||
public EntityPlayer player;
|
||||
public ContainerChisel container;
|
||||
private ChiselMode currentMode;
|
||||
|
||||
public GuiChisel(InventoryPlayer iinventory, InventoryChiselSelection menu) {
|
||||
super(new ContainerChisel(iinventory, menu));
|
||||
@@ -33,12 +40,30 @@ public class GuiChisel extends GuiContainer {
|
||||
inventorySlots.onContainerClosed(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
currentMode = General.getChiselMode(container.chisel);
|
||||
|
||||
int x = this.width / 2 - 120;
|
||||
int y = this.height / 2 - 6;
|
||||
buttonList.add(new GuiButton(0, x, y, 53, 20, ""));
|
||||
setButtonText();
|
||||
}
|
||||
|
||||
private void setButtonText() {
|
||||
((GuiButton) buttonList.get(0)).displayString = I18n.format(container.inventory.getInventoryName() + ".mode." + currentMode.name().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int j, int i) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
String line = I18n.format(this.container.inventory.getInventoryName() + ".title");
|
||||
fontRendererObj.drawSplitString(line, 50 - fontRendererObj.getStringWidth(line) / 2, 60, 40, 0x404040);
|
||||
line = I18n.format(this.container.inventory.getInventoryName() + ".mode");
|
||||
fontRendererObj.drawString(line, fontRendererObj.getStringWidth(line) / 2 + 6, 85, 0x404040);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,13 +81,23 @@ public class GuiChisel extends GuiContainer {
|
||||
|
||||
int x = (width - xSize) / 2;
|
||||
int y = (height - ySize) / 2;
|
||||
|
||||
|
||||
Slot main = (Slot) container.inventorySlots.get(InventoryChiselSelection.normalSlots);
|
||||
if (main.getStack() == null) {
|
||||
GuiAutoChisel.drawSlotOverlay(this, x + 14, y + 14, main, 0, ySize, 60);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
|
||||
currentMode = currentMode.next();
|
||||
setButtonText();
|
||||
}
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void func_146977_a(Slot slot) {
|
||||
if (slot instanceof SlotChiselInput) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.cricketcraft.chisel.network;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.network.message.MessageAutoChisel;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselMode;
|
||||
import com.cricketcraft.chisel.network.message.MessageChiselSound;
|
||||
import com.cricketcraft.chisel.network.message.MessageSlotUpdate;
|
||||
|
||||
@@ -18,5 +19,6 @@ public class PacketHandler {
|
||||
INSTANCE.registerMessage(MessageChiselSound.Handler.class, MessageChiselSound.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageSlotUpdate.Handler.class, MessageSlotUpdate.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageAutoChisel.Handler.class, MessageAutoChisel.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(MessageChiselMode.Handler.class, MessageChiselMode.class, id++, Side.SERVER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.cricketcraft.chisel.network.message;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.cricketcraft.chisel.api.ChiselMode;
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.utils.General;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
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(){
|
||||
}
|
||||
|
||||
private String mode;
|
||||
|
||||
public MessageChiselMode(ChiselMode current) {
|
||||
this.mode = current.next().name();
|
||||
}
|
||||
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.mode = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<MessageChiselMode, IMessage> {
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user