feat: fortune cookies

This commit is contained in:
LordMZTE 2024-05-05 16:54:56 +02:00
parent 422982d8a5
commit 3b503a631c
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
12 changed files with 231 additions and 10 deletions

View file

@ -0,0 +1,48 @@
package ley.modding.dartcraft.client.gui;
import org.lwjgl.opengl.GL11;
import ley.modding.dartcraft.Dartcraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
public class GuiFortune extends GuiScreen {
private String text;
private int xSize = 236;
private int ySize = 69;
private int posX;
private int posY;
public GuiFortune(ItemStack stack) {
this.text
= stack.hasTagCompound() ? stack.getTagCompound().getString("fortune") : "";
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public void drawScreen(int par1, int par2, float par3) {
this.drawDefaultBackground();
GL11.glColor4f((float) 1.0f, (float) 1.0f, (float) 1.0f, (float) 1.0f);
Dartcraft.proxy.bindTexture("fortuneGui.png");
this.posX = (this.width - this.xSize) / 2;
this.posY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(this.posX, this.posY, 0, 0, this.xSize, this.ySize);
int rows = this.fontRendererObj.getStringWidth(this.text) / 203;
GL11.glColor4f((float) 0.0f, (float) 0.0f, (float) 0.0f, (float) 1.0f);
if (rows == 0) {
this.posX = (this.width - this.fontRendererObj.getStringWidth(this.text)) / 2;
this.posY = (this.height - this.fontRendererObj.FONT_HEIGHT) / 2;
this.fontRendererObj.drawString(this.text, this.posX, this.posY, 0x404040);
} else {
this.posY
= this.height / 2 - this.fontRendererObj.FONT_HEIGHT * (rows + 1) / 2;
this.fontRendererObj.drawSplitString(
this.text, this.posX + 15, this.posY, 203, 0x404040
);
}
}
}

View file

@ -2,6 +2,7 @@ package ley.modding.dartcraft.client.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import ley.modding.dartcraft.item.ItemClipboard;
import ley.modding.dartcraft.item.ItemFortune;
import ley.modding.dartcraft.tile.TileEntityForceEngine;
import ley.modding.dartcraft.tile.TileEntityInfuser;
import ley.modding.dartcraft.util.EntityUtils;
@ -40,6 +41,9 @@ public class GuiHandler implements IGuiHandler {
return new ContainerInfuser(player.inventory, (TileEntityInfuser) te);
}
} break;
default:
break;
}
return null;
}
@ -72,6 +76,12 @@ public class GuiHandler implements IGuiHandler {
);
}
} break;
case FORTUNE: {
ItemStack stack = player.getHeldItem();
if (stack.getItem() instanceof ItemFortune)
return new GuiFortune(stack);
} break;
}
return null;
}

View file

@ -3,5 +3,6 @@ package ley.modding.dartcraft.client.gui;
public enum GuiType {
CLIPBOARD,
ENGINE,
INFUSER;
INFUSER,
FORTUNE;
}

View file

@ -24,9 +24,9 @@ public class DartItems {
public static Item forcestick;
public static Item forcetome;
// Useless Items
public static Item claw;
public static Item fortune;
public static Item fortunecookie;
public static Item goldenpower;
public static Item resource;
public static Item soulwafer;
@ -48,7 +48,8 @@ public class DartItems {
claw = reg.registerItem(new BaseItem("claw"));
clipboard = reg.registerItem(new ItemClipboard());
fortune = reg.registerItem(new BaseItem("fortune"));
fortune = reg.registerItem(new ItemFortune());
fortunecookie = reg.registerItem(new ItemFortuneCookie());
goldenpower = reg.registerItem(new BaseItem("goldenpower"));
resource = reg.registerItem(new BaseItem("resource"));
soulwafer = reg.registerItem(new BaseItem("soulwafer"));

View file

@ -0,0 +1,24 @@
package ley.modding.dartcraft.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemFood;
public class ItemDartFood extends ItemFood {
public String iconName;
public ItemDartFood(int hunger, float sat, boolean wolves) {
super(hunger, sat, wolves);
}
public ItemDartFood setUnlocalizedName(String name) {
this.iconName = name;
return (ItemDartFood) super.setUnlocalizedName(name);
}
@SideOnly(value = Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister) {
this.itemIcon = par1IconRegister.registerIcon("dartcraft:" + this.iconName);
}
}

View file

@ -0,0 +1,64 @@
package ley.modding.dartcraft.item;
import java.util.List;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.client.gui.GuiType;
import ley.modding.dartcraft.plugin.DartPluginFortunes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ItemFortune extends BaseItem {
public ItemFortune() {
super("fortune");
}
public ItemStack createNewStack() {
ItemStack stack = new ItemStack(this);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("fortune", DartPluginFortunes.getFortune());
stack.setTagCompound(nbt);
return stack;
}
@SideOnly(value = Side.CLIENT)
@Override
@SuppressWarnings({ "rawtypes", "unchecked", "ALEC" })
public void
addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
list.add("Read me.");
if (Keyboard.isKeyDown((int) 42) || Keyboard.isKeyDown((int) 54)) {
list.add("Right-click, genius");
} else if (list.size() > 2) {
list.remove(2);
}
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (player.isSneaking()) {
int size = stack.stackSize;
player.destroyCurrentEquippedItem();
player.inventory.addItemStackToInventory(new ItemStack(Items.paper, size));
return stack;
}
if (!Dartcraft.proxy.isSimulating(world)) {
player.openGui(
(Object) Dartcraft.instance,
GuiType.FORTUNE.ordinal(),
world,
(int) player.posX,
(int) player.posY,
(int) player.posZ
);
}
return stack;
}
}

View file

@ -0,0 +1,37 @@
package ley.modding.dartcraft.item;
import java.util.List;
import ley.modding.dartcraft.util.DartUtils;
import ley.modding.dartcraft.util.Util;
import net.anvilcraft.anvillib.vector.WorldVec;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemFortuneCookie extends ItemDartFood {
public ItemFortuneCookie() {
super(2, 0.25f, false);
this.setMaxStackSize(16);
this.setAlwaysEdible();
Util.configureItem(this, "fortunecookie");
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes", "ALEC" })
public void
addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
list.add("Eat me.");
}
@Override
public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) {
ItemStack fortuneStack = ((ItemFortune)DartItems.fortune).createNewStack();
if (!player.inventory.addItemStackToInventory(fortuneStack)) {
DartUtils.dropItem(
fortuneStack,
new WorldVec(player)
);
}
}
}

View file

@ -7,6 +7,10 @@ import java.util.Random;
public class DartPluginFortunes {
private static Random rand;
private static List<String> fortunes = new ArrayList<>();
static {
load();
}
public static void addFortune(String fortune) {
if (fortunes != null && fortune != null) {

View file

@ -13,6 +13,7 @@ import ley.modding.dartcraft.network.PacketFX;
import ley.modding.dartcraft.network.PacketFX.Type;
import ley.modding.dartcraft.proxy.CommonProxy;
import net.anvilcraft.anvillib.vector.WorldVec;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
@ -199,13 +200,8 @@ public class DartUtils {
life
);
// TODO: WTF
//if (stack.itemID == DartItem.forceTome.itemID) {
// droppedItem.delayBeforeCanPickup = 100;
//} else {
// droppedItem.delayBeforeCanPickup = 10;
//}
droppedItem.delayBeforeCanPickup = 10;
droppedItem.delayBeforeCanPickup
= stack.getItem() == DartItems.forcetome ? 100 : 10;
if (stack.hasTagCompound()) {
droppedItem.getEntityItem().setTagCompound(
@ -223,4 +219,38 @@ public class DartUtils {
world.spawnEntityInWorld(droppedItem);
}
}
public static void dropItem(ItemStack stack, WorldVec pos) {
if (Dartcraft.proxy.isSimulating(pos.world)) {
float xRand = CommonProxy.rand.nextFloat() * 0.2f + 0.1f;
float yRand = CommonProxy.rand.nextFloat() * 0.8f + 0.1f;
float zRand = CommonProxy.rand.nextFloat() * 0.2f + 0.1f;
while (stack.stackSize > 0) {
int randInt = CommonProxy.rand.nextInt(21) + 10;
if (randInt > stack.stackSize) {
randInt = stack.stackSize;
}
stack.stackSize -= randInt;
EntityItem droppedItem = new EntityItem(
pos.world,
(double) ((float) pos.x + xRand),
(double) ((float) pos.y + yRand),
(double) ((float) pos.z + zRand),
new ItemStack(stack.getItem(), randInt, stack.getItemDamage())
);
if (stack.hasTagCompound()) {
droppedItem.getEntityItem().setTagCompound(
(NBTTagCompound) stack.getTagCompound().copy()
);
}
float modifier = 0.025f;
droppedItem.motionX = (float) CommonProxy.rand.nextGaussian() * modifier;
droppedItem.motionY
= (float) CommonProxy.rand.nextGaussian() * modifier + 0.2f;
droppedItem.motionZ = (float) CommonProxy.rand.nextGaussian() * modifier;
droppedItem.delayBeforeCanPickup = 10;
pos.world.spawnEntityInWorld((Entity) droppedItem);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -18,6 +18,8 @@ item.clipboard.name=Clipboard
item.forcetome_upgrade.name=Upgrade Tome
item.forcetome_experience.name=Experience Tome
item.claw.name=Claw
item.fortune.name=Fortune
item.fortunecookie.name=Fortune Cookie
tile.powerore0.name=Power Ore
tile.powerore1.name=Nether Power Ore

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB