use of net.minecraft.util.math.RayTraceResult in project MinecraftForge by MinecraftForge.
the class UniversalBucket method onItemRightClick.
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
ItemStack itemstack = player.getHeldItem(hand);
FluidStack fluidStack = getFluid(itemstack);
// empty bucket shouldn't exist, do nothing since it should be handled by the bucket event
if (fluidStack == null) {
return ActionResult.newResult(EnumActionResult.PASS, itemstack);
}
// clicked on a block?
RayTraceResult mop = this.rayTrace(world, player, false);
if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) {
return ActionResult.newResult(EnumActionResult.PASS, itemstack);
}
BlockPos clickPos = mop.getBlockPos();
// can we place liquid there?
if (world.isBlockModifiable(player, clickPos)) {
// the block adjacent to the side we clicked on
BlockPos targetPos = clickPos.offset(mop.sideHit);
// can the player place there?
if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack)) {
// try placing liquid
FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, itemstack, fluidStack);
if (result.isSuccess() && !player.capabilities.isCreativeMode) {
// success!
player.addStat(StatList.getObjectUseStats(this));
itemstack.shrink(1);
ItemStack drained = result.getResult();
ItemStack emptyStack = !drained.isEmpty() ? drained.copy() : new ItemStack(this);
// check whether we replace the item or add the empty one to the inventory
if (itemstack.isEmpty()) {
return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack);
} else {
// add empty bucket to player inventory
ItemHandlerHelper.giveItemToPlayer(player, emptyStack);
return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
}
}
}
}
// couldn't place liquid there2
return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
use of net.minecraft.util.math.RayTraceResult in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method leftClickEmpty.
// Registering only on client side
@SubscribeEvent(priority = EventPriority.LOWEST)
@SideOnly(Side.CLIENT)
public void leftClickEmpty(@Nonnull PlayerInteractEvent.LeftClickEmpty event) {
if (event.getSide() == Side.SERVER || event.getEntityPlayer() != Minecraft.getMinecraft().player)
return;
ItemStack stack = event.getItemStack();
if (stack.getItem().equals(this)) {
EntityPlayer entityLiving = event.getEntityPlayer();
RayTraceResult result = entityLiving.rayTrace(OverloadedConfig.multiToolConfig.reach, 0);
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
leftClickOnBlockClient(result.getBlockPos(), result.hitVec);
}
}
}
use of net.minecraft.util.math.RayTraceResult in project ImmersiveEngineering by BluSunrize.
the class ItemDrill method onBlockStartBreak.
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos iPos, EntityPlayer player) {
World world = player.worldObj;
if (player.isSneaking() || world.isRemote || !(player instanceof EntityPlayerMP))
return false;
RayTraceResult mop = this.rayTrace(world, player, true);
ItemStack head = getHead(stack);
if (mop == null || head == null || this.isDrillBroken(stack))
return false;
// EnumFacing side = mop.sideHit;
// int diameter = ((IDrillHead)head.getItem()).getMiningSize(head)+getUpgrades(stack).getInteger("size");
// int depth = ((IDrillHead)head.getItem()).getMiningDepth(head)+getUpgrades(stack).getInteger("depth");
//
// BlockPos startPos=iPos;
// if(diameter%2==0)//even numbers
// {
// float hx = (float)mop.hitVec.xCoord-iPos.getX();
// float hy = (float)mop.hitVec.yCoord-iPos.getY();
// float hz = (float)mop.hitVec.zCoord-iPos.getZ();
// if((side.getAxis()==Axis.Y&&hx<.5)||(side.getAxis()==Axis.Z&&hx<.5))
// startPos.add(-diameter/2,0,0);
// if(side.getAxis()!=Axis.Y&&hy<.5)
// startPos.add(0,-diameter/2,0);
// if((side.getAxis()==Axis.Y&&hz<.5)||(side.getAxis()==Axis.X&&hz<.5))
// startPos.add(0,0,-diameter/2);
// }
// else//odd numbers
// {
// startPos.add(-(side.getAxis()==Axis.X?0: diameter/2), -(side.getAxis()==Axis.Y?0: diameter/2), -(side.getAxis()==Axis.Z?0: diameter/2));
// }
//
// for(int dd=0; dd<depth; dd++)
// for(int dw=0; dw<diameter; dw++)
// for(int dh=0; dh<diameter; dh++)
// {
// BlockPos pos = startPos.add((side.getAxis()==Axis.X?dd: dw), (side.getAxis()==Axis.Y?dd: dh), (side.getAxis()==Axis.Y?dh: side.getAxis()==Axis.X?dw: dd));
// if(pos.equals(iPos))
// continue;
ImmutableList<BlockPos> additional = ((IDrillHead) head.getItem()).getExtraBlocksDug(head, world, player, mop);
for (BlockPos pos : additional) {
if (!world.isBlockLoaded(pos))
continue;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block != null && !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) != 0) {
if (!this.canBreakExtraBlock(world, block, pos, state, player, stack, head, true))
continue;
int xpDropEvent = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
if (xpDropEvent < 0)
continue;
if (player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, pos, state, player);
if (block.removedByPlayer(state, world, pos, player, false))
block.onBlockDestroyedByPlayer(world, pos, state);
} else {
block.onBlockHarvested(world, pos, state, player);
TileEntity te = world.getTileEntity(pos);
//implicitly damages head
stack.onBlockDestroyed(world, state, pos, player);
if (block.removedByPlayer(state, world, pos, player, true)) {
block.onBlockDestroyedByPlayer(world, pos, state);
block.harvestBlock(world, player, pos, state, te, stack);
block.dropXpOnBlockBreak(world, pos, xpDropEvent);
}
}
world.playEvent(2001, pos, Block.getStateId(state));
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
}
}
return false;
}
use of net.minecraft.util.math.RayTraceResult in project ImmersiveEngineering by BluSunrize.
the class ThermalFoundationHelper method init.
@Override
public void init() {
ChemthrowerHandler.registerEffect("coal", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 0));
ChemthrowerHandler.registerFlammable("coal");
ChemthrowerHandler.registerEffect("crude_oil", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(IEPotions.flammable, 140, 0), new PotionEffect(MobEffects.BLINDNESS, 80, 1)));
ChemthrowerHandler.registerFlammable("crude_oil");
ChemthrowerHandler.registerEffect("refined_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 1));
ChemthrowerHandler.registerFlammable("refined_oil");
ChemthrowerHandler.registerEffect("resin", new ChemthrowerEffect_Potion(null, 0, IEPotions.sticky, 100, 1));
ChemthrowerHandler.registerEffect("tree_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 120, 0));
ChemthrowerHandler.registerFlammable("tree_oil");
ChemthrowerHandler.registerEffect("redstone", new ChemthrowerEffect_Potion(null, 0, IEPotions.conductive, 100, 1));
ChemthrowerHandler.registerEffect("glowstone", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.GLOWING, 120, 0), new PotionEffect(MobEffects.SPEED, 120, 0), new PotionEffect(MobEffects.JUMP_BOOST, 120, 0)));
ChemthrowerHandler.registerEffect("ender", new ChemthrowerEffect_RandomTeleport(null, 0, 1));
try {
Class c_DamageHelper = Class.forName("cofh.lib.util.helpers.DamageHelper");
DamageSource pyrotheum = (DamageSource) c_DamageHelper.getDeclaredField("pyrotheum").get(null);
Field f_explodeCreepers = Class.forName("cofh.thermalfoundation.fluid.BlockFluidPyrotheum").getDeclaredField("effect");
f_explodeCreepers.setAccessible(true);
if ((boolean) f_explodeCreepers.get(null))
ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3) {
@Override
public void applyToEntity(EntityLivingBase target, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
super.applyToEntity(target, shooter, thrower, fluid);
if (target instanceof EntityCreeper) {
target.getEntityWorld().createExplosion(target, target.posX, target.posY, target.posZ, 6.0F, target.getEntityWorld().getGameRules().getBoolean("mobGriefing"));
target.setDead();
}
}
});
else
ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3));
DamageSource cryotheum = (DamageSource) c_DamageHelper.getDeclaredField("cryotheum").get(null);
ChemthrowerHandler.registerEffect("cryotheum", new ChemthrowerEffect_Potion(cryotheum, 2, MobEffects.SLOWNESS, 50, 3));
} catch (Exception e) {
}
ChemthrowerHandler.registerEffect("aerotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.INVISIBILITY, 60, 0), new PotionEffect(MobEffects.WATER_BREATHING, 300, 0)));
ChemthrowerHandler.registerEffect("petrotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.HASTE, 300, 2), new PotionEffect(MobEffects.NIGHT_VISION, 300, 0), new PotionEffect(MobEffects.RESISTANCE, 300, 1)) {
@Override
public void applyToBlock(World worldObj, RayTraceResult mop, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
IBlockState state = worldObj.getBlockState(mop.getBlockPos());
if (state.getBlock() == Blocks.STONE || state.getBlock() == Blocks.COBBLESTONE || state.getBlock() == Blocks.STONEBRICK || state.getBlock() == Blocks.MOSSY_COBBLESTONE)
worldObj.setBlockState(mop.getBlockPos(), Blocks.GRAVEL.getDefaultState());
}
});
ChemthrowerHandler.registerEffect("mana", new ChemthrowerEffect_RandomTeleport(null, 0, .01f));
}
use of net.minecraft.util.math.RayTraceResult in project ImmersiveEngineering by BluSunrize.
the class ClientEventHandler method onRenderOverlayPost.
@SubscribeEvent()
public void onRenderOverlayPost(RenderGameOverlayEvent.Post event) {
if (ClientUtils.mc().thePlayer != null && event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
EntityPlayer player = ClientUtils.mc().thePlayer;
for (EnumHand hand : EnumHand.values()) if (player.getHeldItem(hand) != null) {
ItemStack equipped = player.getHeldItem(hand);
if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, false) || equipped.getItem() instanceof IWireCoil) {
if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
if (link != null && link.length > 3) {
String s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
int col = WireType.ELECTRUM.getColour(null);
if (equipped.getItem() instanceof IWireCoil) {
RayTraceResult rtr = ClientUtils.mc().objectMouseOver;
double d = rtr != null && rtr.getBlockPos() != null ? rtr.getBlockPos().distanceSq(link[1], link[2], link[3]) : player.getDistanceSq(link[1], link[2], link[3]);
int max = ((IWireCoil) equipped.getItem()).getWireType(equipped).getMaxLength();
if (d > max * max)
col = 0xdd3333;
}
ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, col, true);
}
}
} else if (OreDictionary.itemMatches(equipped, new ItemStack(IEContent.itemFluorescentTube), false)) {
String s = I18n.format("desc.ImmersiveEngineering.info.colour", "#" + ItemFluorescentTube.hexColorString(equipped));
ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, ItemFluorescentTube.getRGBInt(equipped), true);
} else if (equipped.getItem() instanceof ItemRevolver && equipped.getItemDamage() != 2) {
ClientUtils.bindTexture("immersiveengineering:textures/gui/revolver.png");
ItemStack[] bullets = ((ItemRevolver) equipped.getItem()).getBullets(equipped);
int bulletAmount = bullets.length;
EnumHandSide side = hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
float dx = side == EnumHandSide.RIGHT ? event.getResolution().getScaledWidth() - 32 - 48 : 48;
float dy = event.getResolution().getScaledHeight() - 64;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.translate(dx, dy, 0);
GlStateManager.scale(.5f, .5f, 1);
GlStateManager.color(1, 1, 1, 1);
ClientUtils.drawTexturedRect(0, 1, 74, 74, 0 / 256f, 74 / 256f, 51 / 256f, 125 / 256f);
if (bulletAmount >= 18)
ClientUtils.drawTexturedRect(47, 1, 103, 74, 74 / 256f, 177 / 256f, 51 / 256f, 125 / 256f);
else if (bulletAmount > 8)
ClientUtils.drawTexturedRect(57, 1, 79, 39, 57 / 256f, 136 / 256f, 12 / 256f, 51 / 256f);
RenderItem ir = ClientUtils.mc().getRenderItem();
int[][] slots = ContainerRevolver.slotPositions[bulletAmount >= 18 ? 2 : bulletAmount > 8 ? 1 : 0];
for (int i = 0; i < bulletAmount; i++) {
if (bullets[i] != null) {
int x = 0;
int y = 0;
if (i == 0) {
x = 29;
y = 3;
} else if (i - 1 < slots.length) {
x = slots[i - 1][0];
y = slots[i - 1][1];
} else {
int ii = i - (slots.length + 1);
x = ii == 0 ? 48 : ii == 1 ? 29 : ii == 3 ? 2 : 10;
y = ii == 1 ? 57 : ii == 3 ? 30 : ii == 4 ? 11 : 49;
}
ir.renderItemIntoGUI(bullets[i], x, y);
}
}
RenderHelper.disableStandardItemLighting();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
} else if (equipped.getItem() instanceof ItemRailgun) {
int duration = 72000 - player.getItemInUseCount();
int chargeTime = ((ItemRailgun) equipped.getItem()).getChargeTime(equipped);
int chargeLevel = duration < 72000 ? Math.min(99, (int) (duration / (float) chargeTime * 100)) : 0;
float scale = 2f;
GlStateManager.pushMatrix();
GlStateManager.translate(event.getResolution().getScaledWidth() - 80, event.getResolution().getScaledHeight() - 30, 0);
GlStateManager.scale(scale, scale, 1);
ClientProxy.nixieFont.drawString((chargeLevel < 10 ? "0" : "") + chargeLevel, 0, 0, Lib.colour_nixieTubeText, false);
GlStateManager.scale(1 / scale, 1 / scale, 1);
GlStateManager.popMatrix();
} else if ((equipped.getItem() instanceof ItemDrill && equipped.getItemDamage() == 0) || equipped.getItem() instanceof ItemChemthrower) {
boolean drill = equipped.getItem() instanceof ItemDrill;
ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
GL11.glColor4f(1, 1, 1, 1);
float dx = event.getResolution().getScaledWidth() - 16;
float dy = event.getResolution().getScaledHeight();
GL11.glPushMatrix();
GL11.glTranslated(dx, dy, 0);
int w = 31;
int h = 62;
double uMin = 179 / 256f;
double uMax = 210 / 256f;
double vMin = 9 / 256f;
double vMax = 71 / 256f;
ClientUtils.drawTexturedRect(-24, -68, w, h, uMin, uMax, vMin, vMax);
GL11.glTranslated(-23, -37, 0);
IFluidHandler handler = FluidUtil.getFluidHandler(equipped);
int capacity = -1;
if (handler != null) {
IFluidTankProperties[] props = handler.getTankProperties();
if (props != null && props.length > 0)
capacity = props[0].getCapacity();
}
if (capacity > -1) {
FluidStack fuel = FluidUtil.getFluidContained(equipped);
int amount = fuel != null ? fuel.amount : 0;
if (!drill && player.isHandActive()) {
int use = player.getItemInUseMaxCount();
amount -= use * IEConfig.Tools.chemthrower_consumption;
}
float cap = (float) capacity;
float angle = 83 - (166 * amount / cap);
GL11.glRotatef(angle, 0, 0, 1);
ClientUtils.drawTexturedRect(6, -2, 24, 4, 91 / 256f, 123 / 256f, 80 / 256f, 87 / 256f);
GL11.glRotatef(-angle, 0, 0, 1);
// for(int i=0; i<=8; i++)
// {
// float angle = 83-(166/8f)*i;
// GL11.glRotatef(angle, 0, 0, 1);
// ClientUtils.drawTexturedRect(6,-2, 24,4, 91/256f,123/256f, 80/96f,87/96f);
// GL11.glRotatef(-angle, 0, 0, 1);
// }
GL11.glTranslated(23, 37, 0);
if (drill) {
ClientUtils.drawTexturedRect(-54, -73, 66, 72, 108 / 256f, 174 / 256f, 4 / 256f, 76 / 256f);
RenderItem ir = ClientUtils.mc().getRenderItem();
ItemStack head = ((ItemDrill) equipped.getItem()).getHead(equipped);
if (head != null) {
ir.renderItemIntoGUI(head, -51, -45);
ir.renderItemOverlayIntoGUI(head.getItem().getFontRenderer(head), head, -51, -45, null);
RenderHelper.disableStandardItemLighting();
}
} else {
ClientUtils.drawTexturedRect(-41, -73, 53, 72, 8 / 256f, 61 / 256f, 4 / 256f, 76 / 256f);
boolean ignite = ItemNBTHelper.getBoolean(equipped, "ignite");
ClientUtils.drawTexturedRect(-32, -43, 12, 12, 66 / 256f, 78 / 256f, (ignite ? 21 : 9) / 256f, (ignite ? 33 : 21) / 256f);
}
GL11.glPopMatrix();
}
}
// else if(equipped.getItem() instanceof ItemRailgun)
// {
// float dx = event.getResolution().getScaledWidth()-32-48;
// float dy = event.getResolution().getScaledHeight()-40;
// ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
// GL11.glColor4f(1, 1, 1, 1);
// GL11.glPushMatrix();
// GL11.glEnable(GL11.GL_BLEND);
// GL11.glTranslated(dx, dy, 0);
//
// int duration = player.getItemInUseDuration();
// int chargeTime = ((ItemRailgun)equipped.getItem()).getChargeTime(equipped);
// int chargeLevel = Math.min(99, (int)(duration/(float)chargeTime*100));
// // ClientUtils.drawTexturedRect(0,0, 64,32, 0/256f,64/256f, 96/256f,128/256f);
//
// GL11.glScalef(1.5f,1.5f,1.5f);
// int col = Config.getBoolean("nixietubeFont")?Lib.colour_nixieTubeText:0xffffff;
// ClientProxy.nixieFont.setDrawTubeFlag(false);
// // ClientProxy.nixieFont.drawString((chargeLevel<10?"0"+chargeLevel:""+chargeLevel), 19,3, col);
// ClientProxy.nixieFont.setDrawTubeFlag(true);
//
// GL11.glPopMatrix();
// }
RayTraceResult mop = ClientUtils.mc().objectMouseOver;
if (mop != null && mop.getBlockPos() != null) {
TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, true)) {
int col = IEConfig.nixietubeFont ? Lib.colour_nixieTubeText : 0xffffff;
String[] text = null;
if (tileEntity instanceof IFluxReceiver) {
int maxStorage = ((IFluxReceiver) tileEntity).getMaxEnergyStored(mop.sideHit);
int storage = ((IFluxReceiver) tileEntity).getEnergyStored(mop.sideHit);
if (maxStorage > 0)
text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
} else // }
if (mop.entityHit instanceof IFluxReceiver) {
int maxStorage = ((IFluxReceiver) mop.entityHit).getMaxEnergyStored(null);
int storage = ((IFluxReceiver) mop.entityHit).getEnergyStored(null);
if (maxStorage > 0)
text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
}
if (text != null) {
if (player.worldObj.getTotalWorldTime() % 20 == 0) {
ImmersiveEngineering.packetHandler.sendToServer(new MessageRequestBlockUpdate(player.dimension, mop.getBlockPos()));
}
int i = 0;
for (String s : text) if (s != null) {
int w = ClientProxy.nixieFontOptional.getStringWidth(s);
ClientProxy.nixieFontOptional.drawString(s, event.getResolution().getScaledWidth() / 2 - w / 2, event.getResolution().getScaledHeight() / 2 - 4 - text.length * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2) + (i++) * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2), col, true);
}
}
}
}
}
if (ClientUtils.mc().objectMouseOver != null) {
boolean hammer = player.getHeldItem(EnumHand.MAIN_HAND) != null && Utils.isHammer(player.getHeldItem(EnumHand.MAIN_HAND));
RayTraceResult mop = ClientUtils.mc().objectMouseOver;
if (mop != null && mop.getBlockPos() != null) {
TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
if (tileEntity instanceof IBlockOverlayText) {
IBlockOverlayText overlayBlock = (IBlockOverlayText) tileEntity;
String[] text = overlayBlock.getOverlayText(ClientUtils.mc().thePlayer, mop, hammer);
boolean useNixie = overlayBlock.useNixieFont(ClientUtils.mc().thePlayer, mop);
if (text != null && text.length > 0) {
FontRenderer font = useNixie ? ClientProxy.nixieFontOptional : ClientUtils.font();
int col = (useNixie && IEConfig.nixietubeFont) ? Lib.colour_nixieTubeText : 0xffffff;
int i = 0;
for (String s : text) if (s != null)
font.drawString(s, event.getResolution().getScaledWidth() / 2 + 8, event.getResolution().getScaledHeight() / 2 + 8 + (i++) * font.FONT_HEIGHT, col, true);
}
}
}
}
}
}
Aggregations