-
Notifications
You must be signed in to change notification settings - Fork 81
/
BlockRespawnObelisk.java
155 lines (129 loc) · 4.62 KB
/
BlockRespawnObelisk.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.progwml6.natura.nether.block.obelisk;
import java.util.Locale;
import java.util.Random;
import javax.annotation.Nonnull;
import com.progwml6.natura.library.NaturaRegistry;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import slimeknights.mantle.block.EnumBlock;
public class BlockRespawnObelisk extends EnumBlock<BlockRespawnObelisk.ObeliskType>
{
public static PropertyEnum<ObeliskType> TYPE = PropertyEnum.create("type", ObeliskType.class);
public BlockRespawnObelisk()
{
super(Material.WOOD, TYPE, ObeliskType.class);
this.setCreativeTab(NaturaRegistry.tabWorld);
this.setHardness(2.0f);
this.setResistance(1000000F);
this.setSoundType(SoundType.WOOD);
}
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
{
for (ObeliskType type : ObeliskType.values())
{
if (type == ObeliskType.ACTIVE)
{
continue;
}
list.add(new ItemStack(this, 1, type.getMeta()));
}
}
@Override
public BlockPos getBedSpawnPosition(IBlockState state, IBlockAccess world, BlockPos pos, EntityPlayer player)
{
return pos.up();
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
Random rand = new Random();
rand.setSeed(2 ^ 16 + 2 ^ 8 + (4 * 3 * 271));
if (playerIn.isSneaking())
{
return false;
}
playerIn.setSpawnChunk(pos, false, worldIn.provider.getDimension());
if (!worldIn.isRemote)
{
playerIn.sendMessage(playerIn.getDisplayName().appendText(": Spawn point set!"));
}
worldIn.setBlockState(pos, this.getDefaultState().withProperty(TYPE, ObeliskType.ACTIVE), 3);
worldIn.playSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, rand.nextFloat() * 0.4F + 0.8F, false);
return true;
}
@Override
public boolean isBed(IBlockState state, IBlockAccess world, BlockPos pos, Entity player)
{
return state.getValue(TYPE) == ObeliskType.ACTIVE;
}
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
{
if (state.getValue(TYPE) == ObeliskType.ACTIVE)
{
return 7;
}
return super.getLightValue(state, world, pos);
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if (stateIn.getValue(TYPE) == ObeliskType.ACTIVE)
{
for (int i = 0; i < 2; i++)
{
double x = pos.getX() + rand.nextFloat() * 3 - 1;
double y = pos.getY() + rand.nextFloat() * 2;
double z = pos.getZ() + rand.nextFloat() * 3 - 1;
worldIn.spawnParticle(EnumParticleTypes.PORTAL, x, y, z, 0.0D, 0.0D, 0.0D, new int[0]);
worldIn.spawnParticle(EnumParticleTypes.SPELL_WITCH, x, y, z, 0.0D, 0.0D, 0.0D, new int[0]);
}
}
}
@Override
public int damageDropped(IBlockState state)
{
return 0;
}
public enum ObeliskType implements IStringSerializable, EnumBlock.IEnumMeta
{
INACTIVE, ACTIVE;
public final int meta;
ObeliskType()
{
this.meta = this.ordinal();
}
@Override
public String getName()
{
return this.toString().toLowerCase(Locale.US);
}
@Override
public int getMeta()
{
return this.meta;
}
}
}