-
Notifications
You must be signed in to change notification settings - Fork 53
/
BlockClientPlayerRightClick.java
76 lines (64 loc) · 2.55 KB
/
BlockClientPlayerRightClick.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.choonster.testmod3.block;
import com.choonster.testmod3.TestMod3;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
/**
* A block that forces a player to right click (from the client side) every 10 ticks (0.5 seconds) while standing on it.
* <p>
* Uses the pressure plate model, placement and piston movement behaviour; but doesn't depress when stood on.
* <p>
* Test for this thread:
* http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2512904-make-the-player-perform-a-right-click-on-non
*/
public class BlockClientPlayerRightClick extends Block {
public static final IProperty POWERED = PropertyBool.create("powered");
public BlockClientPlayerRightClick() {
super(Material.rock);
setCreativeTab(TestMod3.creativeTab);
setUnlocalizedName("clientPlayerRightClick");
}
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
return null;
}
public boolean isOpaqueCube() {
return false;
}
public boolean isFullCube() {
return false;
}
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
return true;
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return World.doesBlockHaveSolidTopSurface(worldIn, pos) || worldIn.getBlockState(pos).getBlock() instanceof BlockFence;
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.0625F, 0.9375F);
}
public void setBlockBoundsForItemRender() {
this.setBlockBounds(0.0F, 0.375F, 0.0F, 1.0F, 0.625F, 1.0F);
}
public int getMobilityFlag() {
return 1;
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
// If on the client side, the colliding Entity is the client player and the total world time is a multiple of 10
if (worldIn.isRemote && entityIn == TestMod3.proxy.getClientPlayer() && worldIn.getTotalWorldTime() % 10 == 0) {
// Make the player right click
entityIn.addChatMessage(new ChatComponentText("Right click!!"));
TestMod3.proxy.doClientRightClick();
}
}
}