generated from tilera/1710mod
230 lines
8.5 KiB
Java
230 lines
8.5 KiB
Java
|
package dev.tilera.classiccasting;
|
||
|
|
||
|
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||
|
import net.minecraft.block.Block;
|
||
|
import net.minecraft.entity.Entity;
|
||
|
import net.minecraft.entity.player.EntityPlayer;
|
||
|
import net.minecraft.init.Blocks;
|
||
|
import net.minecraft.item.ItemStack;
|
||
|
import net.minecraft.nbt.NBTTagShort;
|
||
|
import net.minecraft.util.ChatComponentText;
|
||
|
import net.minecraft.world.World;
|
||
|
import thaumcraft.api.IVisDiscountGear;
|
||
|
import thaumcraft.common.config.ConfigBlocks;
|
||
|
import thaumcraft.common.config.ConfigItems;
|
||
|
import thaumcraft.common.entities.EntitySpecialItem;
|
||
|
import thaumcraft.common.lib.network.PacketHandler;
|
||
|
import thaumcraft.common.lib.network.fx.PacketFXBlockSparkle;
|
||
|
|
||
|
public class WandManager {
|
||
|
public static int getTotalVisDiscount(final EntityPlayer player) {
|
||
|
int total = 0;
|
||
|
for (int a = 0; a < 4; ++a) {
|
||
|
if (player.inventory.armorItemInSlot(a) != null
|
||
|
&& player.inventory.armorItemInSlot(a).getItem()
|
||
|
instanceof IVisDiscountGear) {
|
||
|
total
|
||
|
+= ((IVisDiscountGear) player.inventory.armorItemInSlot(a).getItem())
|
||
|
.getVisDiscount(
|
||
|
player.inventory.armorItemInSlot(a), player, null
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
return total;
|
||
|
}
|
||
|
|
||
|
public static boolean spendCharge(
|
||
|
final World world,
|
||
|
final ItemStack itemstack,
|
||
|
final EntityPlayer player,
|
||
|
int amount
|
||
|
) {
|
||
|
final int discount = 100 - Math.min(50, getTotalVisDiscount(player));
|
||
|
amount = Math.round(amount * (discount / 100.0f));
|
||
|
if (itemstack.hasTagCompound() && itemstack.stackTagCompound.hasKey("vis")) {
|
||
|
final int charge = itemstack.stackTagCompound.getShort("vis");
|
||
|
if (world.isRemote) {
|
||
|
if (charge >= amount) {
|
||
|
player.swingItem();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
} else {
|
||
|
if (charge >= amount) {
|
||
|
if (!player.capabilities.isCreativeMode) {
|
||
|
itemstack.setTagInfo(
|
||
|
"vis", new NBTTagShort((short) (charge - amount))
|
||
|
);
|
||
|
}
|
||
|
world.playSoundAtEntity(
|
||
|
(Entity) player, "thaumcraft:wand", 0.5f, 1.0f
|
||
|
);
|
||
|
return true;
|
||
|
}
|
||
|
if (amount > 0) {
|
||
|
player.addChatMessage(new ChatComponentText(
|
||
|
LanguageRegistry.instance().getStringLocalization(
|
||
|
"tc.wandnocharge"
|
||
|
)
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static boolean
|
||
|
spendCharge(final ItemStack itemstack, final EntityPlayer player, int amount) {
|
||
|
final int discount = 100 - Math.min(50, getTotalVisDiscount(player));
|
||
|
amount = Math.round(amount * (discount / 100.0f));
|
||
|
if (itemstack.hasTagCompound() && itemstack.stackTagCompound.hasKey("vis")) {
|
||
|
final int charge = itemstack.stackTagCompound.getShort("vis");
|
||
|
if (charge >= amount) {
|
||
|
if (!player.capabilities.isCreativeMode) {
|
||
|
itemstack.setTagInfo(
|
||
|
"vis", new NBTTagShort((short) (charge - amount))
|
||
|
);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static boolean
|
||
|
createThaumonomicon(ItemStack is, EntityPlayer p, World w, int x, int y, int z) {
|
||
|
if (!spendCharge(is, p, 25) || w.isRemote)
|
||
|
return false;
|
||
|
|
||
|
w.setBlockToAir(x, y, z);
|
||
|
|
||
|
EntitySpecialItem entityItem = new EntitySpecialItem(
|
||
|
w,
|
||
|
(double) (x + 0.5D),
|
||
|
(double) (y + 0.3D),
|
||
|
(double) (z + 0.5D),
|
||
|
new ItemStack(ConfigItems.itemThaumonomicon)
|
||
|
);
|
||
|
|
||
|
entityItem.motionY = 0.0D;
|
||
|
entityItem.motionX = 0.0D;
|
||
|
entityItem.motionZ = 0.0D;
|
||
|
|
||
|
w.spawnEntityInWorld(entityItem);
|
||
|
PacketHandler.INSTANCE.sendToAllAround(
|
||
|
new PacketFXBlockSparkle(x, y, z, -9999),
|
||
|
new TargetPoint(w.provider.dimensionId, x, y, z, 32)
|
||
|
);
|
||
|
w.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "thaumcraft:wand", 1.0F, 1.0F);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static boolean
|
||
|
createCrucible(ItemStack is, EntityPlayer p, World w, int x, int y, int z) {
|
||
|
if (!spendCharge(is, p, 25) || w.isRemote)
|
||
|
return false;
|
||
|
|
||
|
w.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "thaumcraft:wand", 1.0F, 1.0F);
|
||
|
w.setBlock(x, y, z, ConfigBlocks.blockMetalDevice, 0, 3);
|
||
|
w.notifyBlocksOfNeighborChange(x, y, z, w.getBlock(x, y, z));
|
||
|
w.markBlockForUpdate(x, y, z);
|
||
|
w.addBlockEvent(x, y, z, ConfigBlocks.blockMetalDevice, 1, 1);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static boolean createArcaneFurnace(
|
||
|
final ItemStack itemstack,
|
||
|
final EntityPlayer player,
|
||
|
final World world,
|
||
|
final int x,
|
||
|
final int y,
|
||
|
final int z
|
||
|
) {
|
||
|
for (int xx = x - 2; xx <= x; ++xx) {
|
||
|
for (int yy = y - 2; yy <= y; ++yy) {
|
||
|
int zz = z - 2;
|
||
|
while (zz <= z) {
|
||
|
if (fitArcaneFurnace(world, xx, yy, zz)
|
||
|
&& spendCharge(world, itemstack, player, 100)) {
|
||
|
if (!world.isRemote) {
|
||
|
replaceArcaneFurnace(world, xx, yy, zz);
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
} else {
|
||
|
++zz;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static boolean
|
||
|
fitArcaneFurnace(final World world, final int x, final int y, final int z) {
|
||
|
final Block bo = Blocks.obsidian;
|
||
|
final Block bn = Blocks.nether_brick;
|
||
|
final Block bf = Blocks.iron_bars;
|
||
|
final Block bl = Blocks.lava;
|
||
|
final Block[][][] blueprint
|
||
|
= { { { bn, bo, bn }, { bo, Blocks.air, bo }, { bn, bo, bn } },
|
||
|
{ { bn, bo, bn }, { bo, bl, bo }, { bn, bo, bn } },
|
||
|
{ { bn, bo, bn }, { bo, bo, bo }, { bn, bo, bn } } };
|
||
|
boolean fencefound = false;
|
||
|
for (int yy = 0; yy < 3; ++yy) {
|
||
|
for (int xx = 0; xx < 3; ++xx) {
|
||
|
for (int zz = 0; zz < 3; ++zz) {
|
||
|
final Block block = world.getBlock(x + xx, y - yy + 2, z + zz);
|
||
|
if (block != blueprint[yy][xx][zz]) {
|
||
|
if (yy != 1 || fencefound || block != bf || xx == zz
|
||
|
|| (xx != 1 && zz != 1)) {
|
||
|
return false;
|
||
|
}
|
||
|
fencefound = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return fencefound;
|
||
|
}
|
||
|
|
||
|
public static boolean
|
||
|
replaceArcaneFurnace(final World world, final int x, final int y, final int z) {
|
||
|
final boolean fencefound = false;
|
||
|
for (int yy = 0; yy < 3; ++yy) {
|
||
|
int step = 1;
|
||
|
for (int zz = 0; zz < 3; ++zz) {
|
||
|
for (int xx = 0; xx < 3; ++xx) {
|
||
|
int md = step;
|
||
|
if (world.getBlock(x + xx, y + yy, z + zz) == Blocks.lava
|
||
|
|| world.getBlock(x + xx, y + yy, z + zz)
|
||
|
== Blocks.flowing_lava) {
|
||
|
md = 0;
|
||
|
}
|
||
|
if (world.getBlock(x + xx, y + yy, z + zz) == Blocks.iron_bars) {
|
||
|
md = 10;
|
||
|
}
|
||
|
if (!world.isAirBlock(x + xx, y + yy, z + zz)) {
|
||
|
world.setBlock(
|
||
|
x + xx, y + yy, z + zz, ConfigBlocks.blockArcaneFurnace, md, 0
|
||
|
);
|
||
|
world.addBlockEvent(
|
||
|
x + xx, y + yy, z + zz, ConfigBlocks.blockArcaneFurnace, 1, 4
|
||
|
);
|
||
|
}
|
||
|
++step;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for (int yy = 0; yy < 3; ++yy) {
|
||
|
for (int zz2 = 0; zz2 < 3; ++zz2) {
|
||
|
for (int xx2 = 0; xx2 < 3; ++xx2) {
|
||
|
world.markBlockForUpdate(x + xx2, y + yy, z + zz2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return fencefound;
|
||
|
}
|
||
|
}
|