mirror of
https://github.com/GTNewHorizons/Electro-Magic-Tools.git
synced 2026-11-24 22:04:26 +00:00
Chainsaws now can shear ( Closes #23 ), fixed chainsaws sounds.
This commit is contained in:
1 parent
381896031b
commit
f2fb61feb0
8 files changed
+161
-105
No files matched your search
@@ -51,6 +51,7 @@ public class ElectroMagicTools {
|
||||
logger.info("Starting planning the world domination");
|
||||
EMTConfigHandler.init(event.getSuggestedConfigurationFile());
|
||||
FMLCommonHandler.instance().bus().register(new EMTEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(new EMTClientEventHandler());
|
||||
Registry.register();
|
||||
EMTEssentiasOutputs.addPrimalOutputs();
|
||||
EMTEssentiasOutputs.addOutputs();
|
||||
@@ -65,6 +66,7 @@ public class ElectroMagicTools {
|
||||
proxy.load();
|
||||
logger.info("Making mobs drop additional items");
|
||||
MinecraftForge.EVENT_BUS.register(new EMTEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new EMTClientEventHandler());
|
||||
logger.info("Adding dungeon loot");
|
||||
EMTDungeonChestGenerator.generateLoot();
|
||||
logger.info("Registering entities");
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package emt.client.renderer;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class RenderElectroBall extends Render {
|
||||
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float p1, float p2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,24 +10,34 @@ import ic2.api.item.IElectricItem;
|
||||
import ic2.core.IC2;
|
||||
import ic2.core.audio.AudioSource;
|
||||
import ic2.core.audio.PositionSpec;
|
||||
import ic2.core.util.StackUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTorch;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class ItemDiamondChainsaw extends ItemAxe implements IElectricItem {
|
||||
|
||||
@@ -35,8 +45,6 @@ public class ItemDiamondChainsaw extends ItemAxe implements IElectricItem {
|
||||
public int cost = 200;
|
||||
public int hitCost = 300;
|
||||
public int tier = 2;
|
||||
public static AudioSource audio;
|
||||
boolean dropped = false;
|
||||
|
||||
public ItemDiamondChainsaw() {
|
||||
super(ToolMaterial.EMERALD);
|
||||
@@ -102,13 +110,16 @@ public class ItemDiamondChainsaw extends ItemAxe implements IElectricItem {
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack torchStack = player.inventory.mainInventory[i];
|
||||
if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase(Locale.US).contains("torch")) {
|
||||
if (torchStack == null) {
|
||||
continue;
|
||||
}
|
||||
Item item = torchStack.getItem();
|
||||
if (!(item instanceof ItemBlock)) {
|
||||
continue;
|
||||
}
|
||||
if (!(Block.getBlockFromItem(item) instanceof BlockTorch)) {
|
||||
continue;
|
||||
}
|
||||
int oldMeta = torchStack.getItemDamage();
|
||||
int oldSize = torchStack.stackSize;
|
||||
boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
|
||||
@@ -129,37 +140,72 @@ public class ItemDiamondChainsaw extends ItemAxe implements IElectricItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player) {
|
||||
if (audio != null) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
dropped = true;
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if (!IC2.platform.isSimulating()) {
|
||||
return super.onItemRightClick(stack, world, player);
|
||||
}
|
||||
return true;
|
||||
if (IC2.keyboard.isModeSwitchKeyDown(player)) {
|
||||
NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
|
||||
if (!nbt.hasKey("shearsMode")) {
|
||||
nbt.setBoolean("shearsMode", true);
|
||||
}
|
||||
|
||||
if (!nbt.getBoolean("shearsMode")) {
|
||||
nbt.setBoolean("shearsMode", true);
|
||||
|
||||
IC2.platform.messagePlayer(player, "ic2.tooltip.mode", "ic2.tooltip.mode.normal");
|
||||
}
|
||||
else {
|
||||
nbt.setBoolean("shearsMode", false);
|
||||
IC2.platform.messagePlayer(player, "ic2.tooltip.mode", "ic2.tooltip.mode.noShear");
|
||||
}
|
||||
}
|
||||
return super.onItemRightClick(stack, world, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
if (IC2.platform.isRendering()) {
|
||||
if (flag && !dropped) {
|
||||
if (audio == null)
|
||||
audio = IC2.audioManager.createSource(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawIdle.ogg", true, false, IC2.audioManager.getDefaultVolume());
|
||||
if (audio != null) {
|
||||
audio.updatePosition();
|
||||
audio.play();
|
||||
}
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player) {
|
||||
NBTTagCompound nbt = StackUtil.getOrCreateNbtData(itemstack);
|
||||
if (!nbt.hasKey("shearsMode")) {
|
||||
nbt.setBoolean("shearsMode", true);
|
||||
}
|
||||
if (!nbt.getBoolean("shearsMode") || player.worldObj.isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block block = player.worldObj.getBlock(x, y, z);
|
||||
if (block instanceof IShearable) {
|
||||
IShearable target = (IShearable) block;
|
||||
if (target.isShearable(itemstack, player.worldObj, x, y, z)) {
|
||||
ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
|
||||
Random rand = new Random();
|
||||
|
||||
for (ItemStack stack : drops) {
|
||||
float f = 0.7F;
|
||||
double xOffset = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
double yOffset = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
double zOffset = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(player.worldObj, (double) x + xOffset, (double) y + yOffset, (double) z + zOffset, stack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
player.worldObj.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
else if (!flag && audio != null && ((((EntityPlayer) entity).inventory.getCurrentItem() != null && ((EntityPlayer) entity).inventory.getCurrentItem().getItem() != this) || (((EntityPlayer) entity).inventory.getCurrentItem() == null))) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
IC2.audioManager.playOnce(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawStop.ogg", true, IC2.audioManager.getDefaultVolume());
|
||||
}
|
||||
dropped = false;
|
||||
|
||||
player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean flag) {
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
|
||||
NBTTagCompound nbt = StackUtil.getOrCreateNbtData(stack);
|
||||
if (!nbt.hasKey("shearsMode")) {
|
||||
nbt.setBoolean("shearsMode", true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,6 @@ public class ItemStreamChainsaw extends ItemThaumiumChainsaw {
|
||||
boolean alternateServer;
|
||||
boolean alternateClient;
|
||||
public static ArrayList oreDictLogs = new ArrayList();
|
||||
public static AudioSource audio;
|
||||
|
||||
public ItemStreamChainsaw() {
|
||||
this.efficiencyOnProperMaterial = 25F;
|
||||
@@ -76,40 +75,6 @@ public class ItemStreamChainsaw extends ItemThaumiumChainsaw {
|
||||
return super.onItemUse(itemstack, player, world, x, y, z, par7, par8, par9, par10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
if (IC2.platform.isRendering()) {
|
||||
if (flag && !dropped) {
|
||||
if (audio == null)
|
||||
audio = IC2.audioManager.createSource(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawIdle.ogg", true, false, IC2.audioManager.getDefaultVolume());
|
||||
if (audio != null) {
|
||||
audio.updatePosition();
|
||||
audio.play();
|
||||
}
|
||||
}
|
||||
else if (!flag && audio != null && ((((EntityPlayer) entity).inventory.getCurrentItem() != null && ((EntityPlayer) entity).inventory.getCurrentItem().getItem() != this) || (((EntityPlayer) entity).inventory.getCurrentItem() == null))) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
IC2.audioManager.playOnce(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawStop.ogg", true, IC2.audioManager.getDefaultVolume());
|
||||
}
|
||||
dropped = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player) {
|
||||
if (audio != null) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
dropped = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player) {
|
||||
World world = player.worldObj;
|
||||
|
||||
@@ -18,7 +18,6 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemThaumiumChainsaw extends ItemDiamondChainsaw {
|
||||
public static AudioSource audio;
|
||||
|
||||
public ItemThaumiumChainsaw() {
|
||||
this.efficiencyOnProperMaterial = 21F;
|
||||
@@ -30,40 +29,6 @@ public class ItemThaumiumChainsaw extends ItemDiamondChainsaw {
|
||||
hitCost = 350;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag) {
|
||||
if (entity instanceof EntityLivingBase) {
|
||||
if (IC2.platform.isRendering()) {
|
||||
if (flag && !dropped) {
|
||||
if (audio == null)
|
||||
audio = IC2.audioManager.createSource(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawIdle.ogg", true, false, IC2.audioManager.getDefaultVolume());
|
||||
if (audio != null) {
|
||||
audio.updatePosition();
|
||||
audio.play();
|
||||
}
|
||||
}
|
||||
else if (!flag && audio != null && ((((EntityPlayer) entity).inventory.getCurrentItem() != null && ((EntityPlayer) entity).inventory.getCurrentItem().getItem() != this) || (((EntityPlayer) entity).inventory.getCurrentItem() == null))) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
IC2.audioManager.playOnce(entity, PositionSpec.Hand, "Tools/Chainsaw/ChainsawStop.ogg", true, IC2.audioManager.getDefaultVolume());
|
||||
}
|
||||
dropped = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player) {
|
||||
if (audio != null) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
dropped = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.client.settings.KeyBinding;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import emt.client.EMTKeys;
|
||||
import emt.client.renderer.RenderElectroBall;
|
||||
import emt.client.renderer.RenderLaser;
|
||||
import emt.client.renderer.RenderShield;
|
||||
import emt.entity.EntityArcher;
|
||||
@@ -27,6 +28,6 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityLaser.class, new RenderLaser());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityArcher.class, new RenderSnowMan());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityShield.class, new RenderShield());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityElectroBall.class, new RenderFireball(2));
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityElectroBall.class, new RenderElectroBall());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package emt.util;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import emt.ElectroMagicTools;
|
||||
import emt.client.EMTKeys;
|
||||
import emt.init.EMTItems;
|
||||
import emt.network.PacketEMTKeys;
|
||||
import ic2.api.item.IC2Items;
|
||||
import ic2.core.IC2;
|
||||
import ic2.core.Ic2Items;
|
||||
import ic2.core.audio.AudioSource;
|
||||
import ic2.core.audio.PositionSpec;
|
||||
import ic2.core.item.tool.ItemElectricToolChainsaw;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class EMTClientEventHandler {
|
||||
public AudioSource audio;
|
||||
public Item lastItem;
|
||||
|
||||
@SubscribeEvent
|
||||
public void clientTick(ClientTickEvent e) {
|
||||
if (EMTKeys.keyUnequip.getIsKeyPressed()) {
|
||||
ElectroMagicTools.INSTANCE.sendToServer(new PacketEMTKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerTick(TickEvent.PlayerTickEvent e) {
|
||||
if (e.side == Side.CLIENT) {
|
||||
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
Item curItem = player.inventory.getCurrentItem() == null ? null : player.inventory.getCurrentItem().getItem();
|
||||
|
||||
if (curItem == EMTItems.diamondChainsaw || curItem == EMTItems.streamChainsaw || curItem == EMTItems.thaumiumChainsaw) {
|
||||
if (audio == null)
|
||||
audio = IC2.audioManager.createSource(player, PositionSpec.Hand, "Tools/Chainsaw/ChainsawIdle.ogg", true, false, IC2.audioManager.getDefaultVolume());
|
||||
if (audio != null) {
|
||||
audio.updatePosition();
|
||||
audio.play();
|
||||
}
|
||||
}
|
||||
|
||||
if (audio != null && curItem != lastItem) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
IC2.audioManager.playOnce(player, PositionSpec.Hand, "Tools/Chainsaw/ChainsawStop.ogg", true, IC2.audioManager.getDefaultVolume());
|
||||
}
|
||||
|
||||
if (audio != null && curItem != lastItem) {
|
||||
audio.stop();
|
||||
audio.remove();
|
||||
audio = null;
|
||||
IC2.audioManager.playOnce(player, PositionSpec.Hand, "Tools/Chainsaw/ChainsawStop.ogg", true, IC2.audioManager.getDefaultVolume());
|
||||
}
|
||||
|
||||
lastItem = curItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,11 +43,4 @@ public class EMTEventHandler {
|
||||
ElectroMagicTools.logger.info("Refreshing configuration file.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void clientTick(ClientTickEvent e) {
|
||||
if (EMTKeys.keyUnequip.getIsKeyPressed()) {
|
||||
ElectroMagicTools.INSTANCE.sendToServer(new PacketEMTKeys());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user