Added bed support while aboard ships to set spawn in any dimension
This replaces a plugin feature that disappeared when moving past 1.7.10
This commit is contained in:
parent
8c3b1a3285
commit
759be5fb73
1 changed files with 42 additions and 0 deletions
|
@ -16,10 +16,14 @@ import javax.annotation.Nonnull;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBed;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
@ -87,6 +91,44 @@ public class PlayerHandler {
|
|||
// check for maintenance and member access
|
||||
final IBlockState blockState = event.getWorld().getBlockState(blockPos);
|
||||
doCancelEventForNonMembers(event, blockPos, blockState);
|
||||
|
||||
// check for bed usage while aboard ships, allowing players to set their spawn point with the bed
|
||||
if ( event.getEntityPlayer() != null
|
||||
&& event.getEntityPlayer().inventory != null
|
||||
&& blockState.getBlock().equals(Blocks.BED)
|
||||
&& !event.getWorld().isRemote
|
||||
&& (blockPos.getX() != 0 || blockPos.getY() != 0 || blockPos.getZ() != 0) ) {
|
||||
final ArrayList<GlobalRegion> globalRegions = GlobalRegionManager.getContainers(EnumGlobalRegionType.SHIP, event.getWorld(), blockPos);
|
||||
if (!globalRegions.isEmpty()) {// (aboard a ship)
|
||||
// get the head location
|
||||
BlockPos blockPosBed = blockPos;
|
||||
if (blockState.getValue(BlockBed.PART) != BlockBed.EnumPartType.HEAD) {
|
||||
blockPosBed = blockPos.offset(blockState.getValue(BlockHorizontal.FACING));
|
||||
final IBlockState blockStateHead = event.getWorld().getBlockState(blockPosBed);
|
||||
if (blockState.getBlock() != blockStateHead.getBlock()) {
|
||||
blockPosBed = blockPos;
|
||||
}
|
||||
}
|
||||
|
||||
final BlockPos blockPosBedOriginal = event.getEntityPlayer().getBedLocation(event.getWorld().provider.getDimension());
|
||||
event.getEntityPlayer().setSpawnChunk(blockPosBed.toImmutable(), false, event.getWorld().provider.getDimension());
|
||||
final BlockPos blockPosBedUpdated = event.getEntityPlayer().getBedLocation(event.getWorld().provider.getDimension());
|
||||
if ( blockPosBedOriginal == null
|
||||
|| ( blockPosBedUpdated != null
|
||||
&& !blockPosBedUpdated.equals(blockPosBedOriginal) ) ) {
|
||||
Commons.addChatMessage(event.getEntityPlayer(),
|
||||
new TextComponentTranslation("commands.spawnpoint.success",
|
||||
event.getEntityPlayer().getDisplayName(),
|
||||
blockPosBedUpdated.getX(),
|
||||
blockPosBedUpdated.getY(),
|
||||
blockPosBedUpdated.getZ() ));
|
||||
}
|
||||
// cancel the event outside the overworld to prevent an explosion
|
||||
if (event.getWorld().provider.getDimension() != 0) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doCancelEventForNonMembers(@Nonnull final PlayerEvent event,
|
||||
|
|
Loading…
Reference in a new issue