use of net.minecraft.util.EnumHand in project Bewitchment by Um-Mitternacht.
the class ItemBoxSealedEvil method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) {
Random rand = itemRand;
if (!player.isSneaking() && !worldIn.isRemote) {
switch(rand.nextInt(26)) {
case 0:
LootTable table = worldIn.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_DESERT_PYRAMID);
LootContext ctx = new LootContext.Builder((WorldServer) worldIn).withLuck(player.getLuck()).build();
List<ItemStack> stacks = table.generateLootForPools(rand, ctx);
for (ItemStack stack : stacks) Util.giveItem(player, stack);
break;
case 1:
ItemStack bauble = getRandomBauble(rand);
Util.giveItem(player, bauble);
break;
case 2:
player.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 24000, 1));
player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 24000, 0));
break;
case 3:
player.addPotionEffect(new PotionEffect(MobEffects.SPEED, 24000, 1));
player.addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 24000, 0));
break;
case 4:
List<Block> ores = ForgeRegistries.BLOCKS.getValuesCollection().stream().filter(b -> b instanceof BlockOre).collect(Collectors.toList());
for (Block ore : ores) InventoryHelper.spawnItemStack(worldIn, player.posX, player.posY + 0.5, player.posZ, new ItemStack(ore));
break;
case 5:
Util.giveItem(player, new ItemStack(Items.NETHER_STAR));
break;
case 6:
int amount = rand.nextInt(10) + 10;
for (int i = 0; i < amount; i++) {
Entity bat = ForgeRegistries.ENTITIES.getValue(new ResourceLocation("minecraft", "bat")).newInstance(worldIn);
bat.setPosition(player.posX + rand.nextGaussian(), player.posY + 1, player.posZ + rand.nextGaussian());
worldIn.spawnEntity(bat);
}
for (int i = 0; i < amount - 10; i++) {
Entity raven = ModEntities.raven.newInstance(worldIn);
raven.setPosition(player.posX + rand.nextGaussian(), player.posY + 1, player.posZ + rand.nextGaussian());
worldIn.spawnEntity(raven);
}
break;
case 7:
Util.giveItem(player, new ItemStack(ModObjects.bottle_of_blood));
Util.giveItem(player, new ItemStack(ModObjects.heart));
Util.giveItem(player, Util.getRandomContract(rand));
Util.giveItem(player, new ItemStack(Items.SKULL, 1, rand.nextInt(6)));
break;
case 8:
final String[] demons = { "leonard", "baphomet", "lilith", "herne", "moloch" };
String demon = demons[rand.nextInt(demons.length)];
String mat = rand.nextBoolean() ? "nether_brick" : "scorned_brick";
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Bewitchment.MODID, mat + "_" + demon + "_statue"));
if (item != null)
Util.giveItem(player, new ItemStack(item));
else
Util.giveItem(player, new ItemStack(ModObjects.nether_brick_leonard_statue));
break;
case 9:
Util.giveItem(player, new ItemStack(ModObjects.stew_of_the_grotesque));
Util.giveItem(player, new ItemStack(Items.CHICKEN, rand.nextInt(64) + 1));
Util.giveItem(player, new ItemStack(Items.MUTTON, rand.nextInt(64) + 1));
break;
case 10:
Util.giveItem(player, new ItemStack(ModObjects.embergrass));
Util.giveItem(player, new ItemStack(ModObjects.blue_ink_cap));
Util.giveItem(player, new ItemStack(ModObjects.spanish_moss));
String[] type = { "allium", "azure_bluet", "blue_orchid", "dandelion", "oxeye_daisy", "poppy", "tulip_orange", "tulip_pink", "tulip_red", "tulip_white" };
Block flower = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Bewitchment.MODID, "flower_siphoning_" + type[rand.nextInt(10)]));
if (flower != null)
Util.giveItem(player, new ItemStack(flower));
else
Util.giveItem(player, new ItemStack(ModObjects.flower_siphoning_poppy));
Util.giveItem(player, new ItemStack(ModObjects.dragons_blood_sapling));
break;
case 11:
Util.giveItem(player, new ItemStack(Items.GHAST_TEAR, rand.nextInt(2) + 1));
Util.giveItem(player, new ItemStack(Items.BLAZE_ROD, rand.nextInt(2) + 1));
Util.giveItem(player, new ItemStack(ModObjects.hellhound_horn, rand.nextInt(2) + 1));
Util.giveItem(player, new ItemStack(ModObjects.demon_heart, rand.nextInt(2) + 1));
break;
case 12:
int random0 = rand.nextInt(3) + 1;
for (int i = 0; i < random0; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.feuerwurm.newInstance(worldIn);
temp.getDataManager().set(ModEntityMob.SPECTRAL, true);
temp.lifeTimeTicks = 1200;
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 13:
int random1 = rand.nextInt(3) + 1;
for (int i = 0; i < random1; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.hellhound.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 14:
WorldInfo info = worldIn.getWorldInfo();
int weatherTime = (300 + (new Random()).nextInt(600)) * 20;
info.setCleanWeatherTime(0);
info.setRainTime(weatherTime);
info.setThunderTime(weatherTime);
info.setRaining(true);
info.setThundering(true);
break;
case 15:
worldIn.setWorldTime(worldIn.getWorldTime() + (41600 - (worldIn.getWorldTime() % 24000)) % 24000);
break;
case 16:
int random2 = rand.nextInt(3) + 1;
for (int i = 0; i < random2; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.shadow_person.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 17:
int random3 = rand.nextInt(3) + 1;
for (int i = 0; i < random3; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.ghost.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 18:
int random4 = rand.nextInt(2) + 1;
for (int i = 0; i < random4; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.druden.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 19:
player.addPotionEffect(new PotionEffect(MobEffects.POISON, 1200));
player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 24000));
break;
case 20:
player.addPotionEffect(new PotionEffect(MobEffects.WITHER, 800));
break;
case 21:
player.addPotionEffect(new PotionEffect(ModPotions.hellfire, 24000));
// add insanity here
break;
case 22:
worldIn.addWeatherEffect(new EntityLightningBolt(player.world, player.posX, player.posY, player.posZ, true));
break;
case 23:
int random6 = rand.nextInt(2) + 1;
for (int i = 0; i < random6; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.bafometyr.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
case 24:
int random7 = rand.nextInt(2) + 1;
for (int i = 0; i < random7; i++) {
ModEntityMob temp = (ModEntityMob) ModEntities.cleaver.newInstance(worldIn);
temp.setAttackTarget(player);
temp.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(temp);
}
break;
default:
for (BlockPos pos1 : BlockPos.getAllInBoxMutable(player.getPosition().add(-1, 0, -1), player.getPosition().add(1, 2, 1))) {
if (worldIn.getBlockState(pos1).getBlock().isReplaceable(worldIn, pos1)) {
worldIn.setBlockState(pos1, Blocks.WEB.getDefaultState());
}
}
int random5 = rand.nextInt(4) + 1;
for (int i = 0; i < random5; i++) {
Entity spider = ForgeRegistries.ENTITIES.getValue(new ResourceLocation("minecraft", "cave_spider")).newInstance(worldIn);
spider.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(spider);
}
for (int i = 0; i < random5; i++) {
Entity silver_fish = ForgeRegistries.ENTITIES.getValue(new ResourceLocation("minecraft", "silverfish")).newInstance(worldIn);
silver_fish.setPosition(player.posX + rand.nextGaussian() * 2, player.posY + 0.5, player.posZ + rand.nextGaussian() * 2);
worldIn.spawnEntity(silver_fish);
}
break;
}
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
if (worldIn.isRemote)
worldIn.playSound(player, player.getPosition(), SoundEvents.ENTITY_ILLAGER_CAST_SPELL, SoundCategory.PLAYERS, 5, 1);
return super.onItemRightClick(worldIn, player, handIn);
}
use of net.minecraft.util.EnumHand in project Bewitchment by Um-Mitternacht.
the class ItemPoppet method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
EnumHand otherHand = hand == EnumHand.MAIN_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
if (!player.getHeldItem(hand).hasTagCompound() && player.getHeldItem(otherHand).getItem() instanceof ItemTaglock && player.getHeldItem(otherHand).hasTagCompound() && player.getHeldItem(otherHand).getTagCompound().hasKey("boundId") && player.getHeldItem(otherHand).getTagCompound().hasKey("boundName")) {
ItemStack result = player.getHeldItem(hand);
ItemStack taglock = player.getHeldItem(otherHand);
result.setTagCompound(new NBTTagCompound());
result.getTagCompound().setString("boundId", taglock.getTagCompound().getString("boundId"));
result.getTagCompound().setString("boundName", taglock.getTagCompound().getString("boundName"));
player.setHeldItem(hand, result);
player.getHeldItem(otherHand).shrink(1);
if (world.isRemote)
world.playSound(player, player.getPosition(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 10.0F, 1.0F);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
return super.onItemRightClick(world, player, hand);
}
use of net.minecraft.util.EnumHand in project RecurrentComplex by Ivorforce.
the class SelectionRenderer method renderSelection.
public static void renderSelection(EntityLivingBase entity, int ticks, float partialTicks) {
Minecraft mc = Minecraft.getMinecraft();
BlockPos selPoint1 = null;
BlockPos selPoint2 = null;
SelectionOwner owner = SelectionOwner.getOwner(entity, null);
if (owner != null) {
selPoint1 = owner.getSelectedPoint1();
selPoint2 = owner.getSelectedPoint2();
}
GL11.glLineWidth(3.0f);
if (selPoint1 != null) {
GlStateManager.color(0.6f, 0.8f, 0.95f);
AreaRenderer.renderAreaLined(new BlockArea(selPoint1, selPoint1), 0.03f);
}
if (selPoint2 != null) {
GlStateManager.color(0.2f, 0.45f, 0.65f);
AreaRenderer.renderAreaLined(new BlockArea(selPoint2, selPoint2), 0.04f);
}
for (EnumHand enumHand : EnumHand.values()) {
ItemStack heldItem = entity.getHeldItem(enumHand);
if (heldItem != null && heldItem.getItem() instanceof ItemBlockSelector) {
ItemBlockSelector selector = (ItemBlockSelector) heldItem.getItem();
BlockPos hoverPoint = selector.hoveredBlock(heldItem, entity);
GlStateManager.color(0.6f, 0.6f, 1.0f);
AreaRenderer.renderAreaLined(new BlockArea(hoverPoint, hoverPoint), 0.05f);
}
}
if (selPoint1 != null && selPoint2 != null) {
BlockArea selArea = new BlockArea(selPoint1, selPoint2);
GlStateManager.color(0.4f, 0.65f, 0.8f);
AreaRenderer.renderAreaLined(selArea, 0.02f);
GlStateManager.enableBlend();
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.0001f);
ResourceLocation curTex = TEXTURE[MathHelper.floor((ticks + partialTicks) * 0.75f) % TEXTURE.length];
mc.renderEngine.bindTexture(curTex);
GlStateManager.color(0.2f, 0.5f, 0.6f, 0.5f);
AreaRenderer.renderArea(selArea, false, true, 0.01f);
GlStateManager.color(0.4f, 0.65f, 0.8f, 0.75f);
AreaRenderer.renderArea(selArea, false, false, 0.01f);
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.002f);
GlStateManager.disableBlend();
}
}
use of net.minecraft.util.EnumHand in project SpongeForge by SpongePowered.
the class SpongeToForgeEventFactory method createAndPostPlayerInteractBlockEvent.
private static boolean createAndPostPlayerInteractBlockEvent(final SpongeToForgeEventData eventData) {
final InteractBlockEvent spongeEvent = (InteractBlockEvent) eventData.getSpongeEvent();
PlayerInteractEvent forgeEvent = (PlayerInteractEvent) eventData.getForgeEvent();
if (forgeEvent == null) {
final Player player = spongeEvent.getCause().first(Player.class).orElse(null);
// Forge doesn't support left-click AIR
if (player == null || (spongeEvent instanceof InteractBlockEvent.Primary && spongeEvent.getTargetBlock() == BlockSnapshot.NONE)) {
return false;
}
final BlockPos pos = VecHelper.toBlockPos(spongeEvent.getTargetBlock().getPosition());
final EnumFacing face = DirectionFacingProvider.getInstance().get(spongeEvent.getTargetSide()).orElse(null);
Vec3d hitVec = null;
final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
if (spongeEvent.getInteractionPoint().isPresent()) {
hitVec = VecHelper.toVec3d(spongeEvent.getInteractionPoint().get());
}
if (spongeEvent instanceof InteractBlockEvent.Primary) {
forgeEvent = new PlayerInteractEvent.LeftClickBlock(entityPlayerMP, pos, face, hitVec);
} else if (spongeEvent instanceof InteractBlockEvent.Secondary) {
final EnumHand hand = spongeEvent instanceof InteractBlockEvent.Secondary.MainHand ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
forgeEvent = new PlayerInteractEvent.RightClickBlock(entityPlayerMP, hand, pos, face, hitVec);
}
if (forgeEvent == null) {
return false;
}
eventData.setForgeEvent(forgeEvent);
}
forgeEvent.setCanceled(spongeEvent.isCancelled());
forgeEventBus.forgeBridge$post(eventData);
if (forgeEvent instanceof PlayerInteractEvent.RightClickBlock) {
final PlayerInteractEvent.RightClickBlock event = (PlayerInteractEvent.RightClickBlock) forgeEvent;
// Mods have higher priority
if (event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseItemResult(getTristateFromResult(event.getUseItem()));
}
if (event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseBlockResult(getTristateFromResult(event.getUseBlock()));
}
}
return true;
}
use of net.minecraft.util.EnumHand in project SpongeForge by SpongePowered.
the class SpongeToForgeEventFactory method createAndPostEntityInteractEvent.
private static boolean createAndPostEntityInteractEvent(final SpongeToForgeEventData eventData) {
final InteractEntityEvent.Secondary spongeEvent = (InteractEntityEvent.Secondary) eventData.getSpongeEvent();
PlayerInteractEvent forgeEvent = (PlayerInteractEvent) eventData.getForgeEvent();
if (forgeEvent == null) {
final Optional<Player> player = spongeEvent.getCause().first(Player.class);
if (!player.isPresent()) {
return false;
}
final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player.get();
final EnumHand hand = entityPlayerMP.getActiveHand();
final EntityPlayer entityPlayer = (EntityPlayer) player.get();
final Entity entity = (Entity) spongeEvent.getTargetEntity();
final Vector3d hitVec = spongeEvent.getInteractionPoint().orElse(null);
if (hitVec != null) {
forgeEvent = new PlayerInteractEvent.EntityInteractSpecific(entityPlayer, hand, entity, VecHelper.toVec3d(hitVec));
} else {
forgeEvent = new PlayerInteractEvent.EntityInteract(entityPlayer, hand, entity);
}
eventData.setForgeEvent(forgeEvent);
}
forgeEvent.setCanceled(spongeEvent.isCancelled());
forgeEventBus.forgeBridge$post(eventData);
return true;
}
Aggregations