use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class RenderThrownTomahawk method doRender.
@Override
public void doRender(EntityThrownTomahawk entity, double x, double y, double z, float entityYaw, float partialTicks) {
if (entity == null)
return;
ItemStack stack = entity.getThrownStack();
if (stack == null || stack.getItem() == null || StackHelper.isEmpty(stack))
return;
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
EntityItem entityitem = new EntityItem(entity.world, entity.posX, entity.posY, entity.posZ, stack);
StackHelper.setCount(entityitem.getItem(), 1);
entityitem.hoverStart = 0.0F;
GlStateManager.pushMatrix();
GlStateManager.disableLighting();
Vec3d vec = new Vec3d(0.0, 0.25, 0.0);
GlStateManager.translate(x, y, z);
GlStateManager.rotate(90 - entity.throwYaw, 0, 1, 0);
float rotation = entity.spin + (entity.inAir ? entity.SPIN_RATE * partialTicks : 0);
GlStateManager.rotate(rotation, 0, 0, 1);
GlStateManager.pushAttrib();
RenderHelper.enableStandardItemLighting();
itemRenderer.renderItem(entityitem.getItem(), ItemCameraTransforms.TransformType.FIXED);
RenderHelper.disableStandardItemLighting();
GlStateManager.popAttrib();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class ItemDrawingCompass method spawnParticles.
public boolean spawnParticles(ItemStack stack, EntityPlayer player, World world) {
BlockPos pos1 = getBlock1(stack);
BlockPos pos2 = getBlock2(stack);
if (pos1.getY() <= 0 || pos2.getY() <= 0 || pos1.equals(pos2)) {
return false;
}
Color color = getColor(stack);
// Spawn circle.
BlockPos center = new BlockPos(pos1.getX(), pos2.getY(), pos1.getZ());
float radius = (float) Math.sqrt(center.distanceSq(pos2));
int count = (int) (5 * radius);
float increment = (float) (2 * Math.PI / count);
float start = increment * (world.getTotalWorldTime() % 30) / 30f;
Vec3d vec;
for (float angle = start; angle < 2 * Math.PI + start; angle += increment) {
vec = new Vec3d(radius, 0, 0).rotateYaw(angle);
particle(player, world, color, center.getX() + 0.5 + vec.x, center.getY() + 0.5 + vec.y, center.getZ() + 0.5 + vec.z);
}
// Spawn line.
double distance = Math.sqrt(pos1.distanceSq(pos2));
count = (int) (2 * distance);
double dx = (double) (pos2.getX() - pos1.getX()) / count;
double dy = (double) (pos2.getY() - pos1.getY()) / count;
double dz = (double) (pos2.getZ() - pos1.getZ()) / count;
for (int i = 0; i < count; ++i) {
vec = new Vec3d(pos1.getX() + 0.5 + i * dx, pos1.getY() + 0.5 + i * dy, pos1.getZ() + 0.5 + i * dz);
particle(player, world, color, vec.x, vec.y, vec.z);
}
return true;
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class TrackCombiner method onLeftClickBlock.
@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
if (event.getEntityPlayer().isSneaking()) {
IBlockState state = world.getBlockState(pos);
if (transformInv.containsKey(state)) {
Pair<ItemStack, IBlockState> pair = transformInv.get(state);
if (!world.isRemote) {
ItemUtils.spawnItemEntity(world, new Vec3d(pos).addVector(0.5, 0.125, 0.5), pair.getLeft().copy(), 0.02f, 0.05f, 0.02f, 1.0f);
}
world.setBlockState(pos, pair.getRight());
event.setCanceled(true);
}
}
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class ItemChisel method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (hand == EnumHand.OFF_HAND) {
return EnumActionResult.PASS;
}
if (!worldIn.isRemote) {
IBlockState state = worldIn.getBlockState(pos);
if (!state.getBlock().isAir(state, worldIn, pos)) {
ItemStack inputStack = state.getBlock().getPickBlock(state, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos), worldIn, pos, playerIn);
if (!inputStack.isEmpty() && inputStack.getCount() == 1) {
ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
ItemStack[] inputStacks = new ItemStack[9];
int inputMask = getBlockMask(heldItem);
int inputCount = 0;
for (int i = 0; i < 9; i++) {
if ((inputMask & (1 << i)) != 0) {
inputStacks[i] = inputStack;
inputCount++;
}
}
ItemStack result = FastRecipeLookup.getCraftingResult(RecipeUtils.getCraftingInventory(3, 3, RecipeUtils.defaultContainer(playerIn), inputStacks), worldIn);
if (result != null && !result.isEmpty() && !(result.getItem() instanceof ItemBlock && ((ItemBlock) result.getItem()).getBlock() instanceof BlockButton)) {
if (result.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) result.getItem()).getBlock();
if (block instanceof BlockButton) {
return EnumActionResult.FAIL;
}
if (block instanceof BlockStairs && (inputCount == 6 && result.getCount() >= 4 && result.getCount() <= 8)) {
result.setCount(inputCount);
}
}
if ((result.getCount() % inputCount) == 0) {
ItemStack resultCopy = result.copy();
resultCopy.setCount(1);
ActionResult<ItemStack> placeResult = ToolsUtils.placeBlockOrRollback(resultCopy, playerIn, worldIn, pos);
if (placeResult.getType() == EnumActionResult.FAIL) {
return EnumActionResult.FAIL;
}
if (result.getCount() > inputCount) {
ItemStack resultCopyRemainder = result.copy();
resultCopyRemainder.setCount((result.getCount() / inputCount) - 1);
Block.spawnAsEntity(worldIn, pos, resultCopyRemainder);
}
}
}
}
}
}
return EnumActionResult.SUCCESS;
}
use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.
the class TileShelf method onActivated.
protected boolean onActivated(float hitX, float hitY, float hitZ, ItemStack stack, EntityPlayer player) {
int slotId = getSlotId(hitX, hitY, hitZ);
if (slotId < 0)
return false;
if (stack.isEmpty()) {
if (handler.getStackInSlot(slotId).isEmpty()) {
slotId = toNonBookSlotId(slotId);
}
if (!handler.getStackInSlot(slotId).isEmpty()) {
final int sentSlotId = slotId;
new Notice(new Vec3d(pos).addVector(hitX, hitY, hitZ), msg -> msg.withItem(handler.getStackInSlot(sentSlotId)).setMessage(new TextComponentString("{ITEM_NAME}{ITEM_INFOS_NEWLINE}"))).sendTo(player);
return true;
} else {
return false;
}
} else {
if (!isBook(stack))
slotId = toNonBookSlotId(slotId);
if (isSlotTaken(slotId))
return false;
stack = stack.splitStack(1);
handler.setStackInSlot(slotId, stack);
markBlockForUpdate();
return true;
}
}
Aggregations