本文整理汇总了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock类的典型用法代码示例。如果您正苦于以下问题:Java RightClickBlock类的具体用法?Java RightClickBlock怎么用?Java RightClickBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RightClickBlock类属于net.minecraftforge.event.entity.player.PlayerInteractEvent包,在下文中一共展示了RightClickBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemUseFirst
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isRemote) {
//If its client side we have to return pass so this method is called on server, where we need to perform the op
return EnumActionResult.PASS;
}
final IBlockState blockState = world.getBlockState(pos);
IBlockState bs = blockState;
Block block = bs.getBlock();
boolean ret = false;
if (block != null) {
RightClickBlock e = new RightClickBlock(player, hand, pos,side, new Vec3d(hitX, hitY, hitZ));
if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
return EnumActionResult.PASS;
}
if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
ret = true;
}
}
if (ret) {
player.swingArm(hand);
}
return (ret && !world.isRemote) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
示例2: onRightClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
if(!(event.getWorld().getBlockState(event.getPos()).getBlock() instanceof XPBlock) || event.getHand() != EnumHand.MAIN_HAND)
return;
if(!event.getWorld().isRemote)
{
if(event.getEntityPlayer().isSneaking()) //sneaking = add all player XP to the block
{
((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos())).addXP(event.getEntityPlayer().experienceTotal);
event.getEntityPlayer().addExperienceLevel(-event.getEntityPlayer().experienceLevel - 1); // set player XP to 0
}
else //not sneaking = remove exactly enough XP from the block to get player to the next level
{
TileEntityXPBlock te = ((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos()));
EntityPlayer player = event.getEntityPlayer();
int neededXP = player.xpBarCap() - (int)player.experience;
int availableXP = te.removeXP(neededXP);
player.addExperience(availableXP);
}
}
}
示例3: onRightClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
if (event.getWorld().isRemote) { return; }
if (Main.isPlayerInteractionAllowed()) { return; } // Not my business
Main.console("[TERRITORIAL DEALINGS] Block at x " + event.getPos().getX() + " / y " + event.getPos().getY() + " / z " + event.getPos().getZ() + " touched by player " + event.getEntityPlayer().getName() + ".");
Chunk chunk = event.getEntityPlayer().worldObj.getChunkFromBlockCoords(event.getPos());
if (TerritoryHandler.canPlayerEditChunk(event.getEntityPlayer(), chunk)) // Checks out
{
Main.console("[TERRITORIAL DEALINGS] Player is allowed to interact with this chunk. Doing nothing.");
}
else
{
Main.console("[TERRITORIAL DEALINGS] Player is not allowed to interact with this chunk. Cancelling.");
event.setCanceled(true); // Not having it
}
}
示例4: onRightClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
if (event.getWorld().isRemote) { return; } // Not doing this on client side
if (!Main.shouldCheckInteraction()) { return; } // Not my business
Main.console("Block at x" + event.getPos().getX() + " y" + event.getPos().getY() + " z" + event.getPos().getZ() + " touched by player " + event.getEntityPlayer().getName() +
" (ID " + event.getEntityPlayer().getGameProfile().getId() + ").");
Chunk chunk = event.getEntityPlayer().worldObj.getChunkFromBlockCoords(event.getPos());
if (TerritoryHandler.canPlayerEditChunk(event.getEntityPlayer().worldObj, event.getEntityPlayer(), chunk)) // Checks out
{
Main.console("Player is allowed to interact with this chunk. Doing nothing.");
}
else
{
Main.console("Player is not allowed to interact with this chunk. Cancelling.");
event.setCanceled(true); // Not having it
}
}
示例5: checkBlockBannedEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void checkBlockBannedEvent(RightClickBlock event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack currentStack = event.getItemStack();
if (player.dimension == AetherConfig.getAetherDimensionID())
{
if (currentStack != null && (currentStack.getItem() == Items.FLINT_AND_STEEL || currentStack.getItem() == Item.getItemFromBlock(Blocks.TORCH) || currentStack.getItem() == Items.FIRE_CHARGE))
{
for (int i = 0; i < 10; ++i)
{
event.getWorld().spawnParticle(EnumParticleTypes.SMOKE_LARGE, event.getHitVec().xCoord, event.getHitVec().yCoord, event.getHitVec().zCoord, 0.0D, 0.0D, 0.0D, new int [] {});
}
event.setCanceled(true);
}
else if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.BED)
{
event.setCanceled(true);
}
}
}
示例6: rightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
/** Makes portals if config. */
@SubscribeEvent
public void rightClick(RightClickBlock event) {
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
ItemStack stack = event.getItemStack();
Item item = stack.getItem();
BlockPos pos = event.getPos();
if (GeoConfig.compatibility.portals && item == GeoItems.FIREOPAL &&
world instanceof WorldServer) {
new Teleporter((WorldServer) world).makePortal(player);
stack.shrink(1);
}
if (GeoConfig.compatibility.portals && item == GeoItems.AMETHYST) {
Items.ENDER_EYE.onItemUse(player, world, pos,
event.getHand(), event.getFace(), 0, 0, 0);
}
}
示例7: poisonousPotatoRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void poisonousPotatoRightClick(RightClickBlock event)
{
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
if((event.getEntityPlayer().getHeldItemMainhand()!=null)
&&(player.getHeldItemMainhand().getItem()==Items.POISONOUS_POTATO)
&&(event.getFace()==EnumFacing.UP)
&&world.getBlockState(event.getPos()).getBlock().canSustainPlant(world.getBlockState(event.getPos()), world, event.getPos(), EnumFacing.UP, (IPlantable) Items.POTATO))
{
if(!world.isRemote)
{
if(!player.capabilities.isCreativeMode)
{
player.inventory.clearMatchingItems(Items.POISONOUS_POTATO, -1, 1, null);
}
if(world.getBlockState(event.getPos().up(+1)).getBlock()==Blocks.AIR)
{
world.setBlockState(event.getPos().up(+1),Blocks.POTATOES.getDefaultState());
}
}
}
}
示例8: rightClickBlock
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void rightClickBlock(RightClickBlock event) {
if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera") && event.getItemStack() == null
&& event.getSide().isClient() && event.getHand().equals(EnumHand.MAIN_HAND)) {
System.out.println("RightClickBlock,HandType=" + event.getHand());
ActiveTripod(Minecraft.getMinecraft().thePlayer.getName(),
((EntityTripod) event.getWorld()
.getEntityByID(event.getEntityPlayer().getEntityData().getInteger("renderViewCamera")))
.getDelay());
event.setCanceled(true);
}
}
示例9: onRightClick
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@HarshenEvent
public void onRightClick(PlayerInteractEvent event)
{
if(event.getEntityPlayer().world.isRemote && HarshenUtils.toArray(RightClickBlock.class, RightClickEmpty.class).contains(event.getClass()) &&
event.getEntityPlayer().getHeldItemMainhand().isEmpty() && event.getEntityPlayer().isElytraFlying())
{
HarshenNetwork.sendToServer(new MessagePacketSummonFirework());
Vec3d vec3d = event.getEntityPlayer().getLookVec();
event.getEntityPlayer().motionX += vec3d.x * 0.1D + (vec3d.x * 2.5D - event.getEntityPlayer().motionX) * 0.5D;
event.getEntityPlayer().motionY += vec3d.y * 0.1D + (vec3d.y * 2.5D - event.getEntityPlayer().motionY) * 0.5D;
event.getEntityPlayer().motionZ += vec3d.z * 0.1D + (vec3d.z * 2.5D - event.getEntityPlayer().motionZ) * 0.5D;
}
}
示例10: registerEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void registerEvent(RightClickBlock event)
{
try
{
IBlockState state = event.getWorld().getBlockState(event.getPos());
if (state.getBlock() == Geolosys.getInstance().ORE_SAMPLE || state.getBlock() == Geolosys.getInstance().ORE_SAMPLE_VANILLA)
{
if (event.getEntityPlayer().isSneaking() && event.getWorld().isRemote)
{
if (jmAPI.playerAccepts(Lib.MODID, DisplayType.Waypoint))
{
String name = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)).getDisplayName();
try
{
jmAPI.show(new Waypoint(Lib.MODID, name, event.getWorld().provider.getDimension(), event.getPos()));
}
catch (Throwable t)
{
Geolosys.getInstance().LOGGER.info(t.getMessage());
}
}
}
}
}
catch (NullPointerException ignored)
{
}
}
示例11: test_rightclick
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@Test
public void test_rightclick() {
// Given:
mc().player().setPosition(playerPos);
ItemStack item = mc().getItemStack(Blocks.SAND);
mc().player().setMainHandItem(item);
mc().setBlock(clickPos, Blocks.OBSIDIAN);
EnumHand hand = EnumHand.MAIN_HAND;
EnumFacing facing = EnumFacing.WEST;
Vec3d hitvec = new Vec3d(clickPos);
String expected = hand.name();
mc().executeCommand("/lua q=Events.connect('SwingArmEvent'); e=q:pop(); print(e.hand)");
// When:
mc().player().rightclick(clickPos, facing, hitvec, hand);
// Then:
RightClickBlock act1 = mc().waitFor(RightClickBlock.class);
assertThat(act1.getPos()).isEqualTo(clickPos);
ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
assertThat(act.getMessage()).isEqualTo(expected);
}
示例12: test_can_receive_RightClickBlock_Event
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@Test
public void test_can_receive_RightClickBlock_Event() {
// Given:
BlockPos pos = BlockPos.ORIGIN;
// When:
mc().post(newRightClickBlockEvent(mc().player().getDelegate(), pos));
// Then:
RightClickBlock act = mc().waitFor(RightClickBlock.class);
assertThat(act.getPos()).isEqualTo(pos);
}
示例13: test_player_can_rightclick_on_blockpos
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@Test
public void test_player_can_rightclick_on_blockpos() {
// Given:
mc().player().setPosition(playerPos);
mc().player().setRotationYaw(0);
ItemStack item = mc().getItemStack(Blocks.PLANKS);
mc().player().setMainHandItem(item);
mc().setBlock(clickPos, Blocks.OBSIDIAN);
EnumHand hand = EnumHand.MAIN_HAND;
EnumFacing facing = EnumFacing.WEST;
Vec3d hitvec = new Vec3d(clickPos);
// When:
mc().player().rightclick(clickPos, facing, hitvec, hand);
// Then:
RightClickBlock act = mc().waitFor(RightClickBlock.class);
assertThat(act.getPos()).isEqualTo(clickPos);
}
示例14: onEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SubscribeEvent
public void onEvent(RightClickBlock evt) {
// TODO can we remove this check?
if (evt.getWorld().isRemote) {
return;
}
addEvent(evt);
}
示例15: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@SubscribeEvent(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
if(event.getEntityPlayer() !=null && event.getWorld() !=null && event instanceof RightClickBlock){
BlockPos pos = EntityUtil.getEntityLookedBlock(event.getEntityPlayer(), (float)CrystalMod.proxy.getReachDistanceForPlayer(event.getEntityPlayer()));
if(pos !=null){
if(event.getWorld().isBlockLoaded(pos)){
IBlockState state = event.getWorld().getBlockState(pos);
if(state.getBlock() == Blocks.WOOL && ItemStackTools.isValid(event.getEntityPlayer().getHeldItem(event.getHand())) && ItemUtil.itemStackMatchesOredict(event.getEntityPlayer().getHeldItem(event.getHand()), "slimeball")){
int waterCt = 0;
for(EnumFacing face : EnumFacing.VALUES){
IBlockState state2 = event.getWorld().getBlockState(pos.offset(face));
if(state2 !=null && state2.getBlock().getMaterial(state2) == Material.WATER){
waterCt++;
}
}
if(waterCt >= 4){
event.getWorld().setBlockState(pos, Blocks.SPONGE.getDefaultState());
event.getEntityPlayer().swingArm(event.getHand());
if (!event.getWorld().isRemote)
{
event.getWorld().playEvent(2001, pos, Block.getStateId(state));
}
if(!event.getEntityPlayer().capabilities.isCreativeMode)
event.getEntityPlayer().setHeldItem(event.getHand(), ItemUtil.consumeItem(event.getEntityPlayer().getHeldItem(event.getHand())));
}
}
}
}
}
}