mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
[1.16] Allow blocks other than beds or respawn anchors to act as respawn points (#7824)
This commit is contained in:
1 parent
03a6dbb405
commit
96804fb4df
5 files changed
+146
-9
No files matched your search
@@ -230,6 +230,26 @@ public interface IForgeBlock
|
||||
return this.getBlock() instanceof BedBlock; //TODO: Forge: Keep isBed function?
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position that the entity is moved to upon
|
||||
* respawning at this block.
|
||||
*
|
||||
* @param state The current state
|
||||
* @param world The current world
|
||||
* @param pos Block position in world
|
||||
* @param orientation The angle the entity had when setting the respawn point
|
||||
* @param entity The entity respawning, often null
|
||||
* @return The spawn position or the empty optional if respawning here is not possible
|
||||
*/
|
||||
default Optional<Vector3d> getRespawnPosition(BlockState state, EntityType<?> type, IWorldReader world, BlockPos pos, float orientation, @Nullable LivingEntity entity)
|
||||
{
|
||||
if (isBed(state, world, pos, entity) && world instanceof World && BedBlock.canSetSpawn((World) world))
|
||||
{
|
||||
return getBedSpawnPosition(type, state, world, pos, orientation, entity);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a specified mob type can spawn on this block, returning false will
|
||||
* prevent any mob from spawning on the block.
|
||||
@@ -255,7 +275,9 @@ public interface IForgeBlock
|
||||
* @param orientation The direction the entity is facing while getting into bed.
|
||||
* @param sleeper The sleeper or camera entity, null in some cases.
|
||||
* @return The spawn position
|
||||
* @deprecated use {@link #getRespawnPosition(BlockState, EntityType, IWorldReader, BlockPos, float, LivingEntity)}
|
||||
*/
|
||||
@Deprecated
|
||||
default Optional<Vector3d> getBedSpawnPosition(EntityType<?> entityType, BlockState state, IWorldReader world, BlockPos pos, float orientation, @Nullable LivingEntity sleeper)
|
||||
{
|
||||
if (world instanceof World)
|
||||
|
||||
@@ -194,12 +194,29 @@ public interface IForgeBlockState
|
||||
* @param orientation The direction the entity is facing while getting into bed.
|
||||
* @param sleeper The sleeper or camera entity, null in some cases.
|
||||
* @return The spawn position
|
||||
* @deprecated use {@link #getRespawnPosition(EntityType, IWorldReader, BlockPos, float, LivingEntity)}
|
||||
*/
|
||||
@Deprecated
|
||||
default Optional<Vector3d> getBedSpawnPosition(EntityType<?> type, IWorldReader world, BlockPos pos, float orientation, @Nullable LivingEntity sleeper)
|
||||
{
|
||||
return getBlockState().getBlock().getBedSpawnPosition(type, getBlockState(), world, pos, orientation, sleeper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position that the entity is moved to upon
|
||||
* respawning at this block.
|
||||
*
|
||||
* @param world The current world
|
||||
* @param pos Block position in world
|
||||
* @param orientation The angle the entity had when setting the respawn point
|
||||
* @param entity The entity respawning, often null
|
||||
* @return The spawn position or the empty optional if respawning here is not possible
|
||||
*/
|
||||
default Optional<Vector3d> getRespawnPosition(EntityType<?> type, IWorldReader world, BlockPos pos, float orientation, @Nullable LivingEntity entity)
|
||||
{
|
||||
return getBlockState().getBlock().getRespawnPosition(getBlockState(), type, world, pos, orientation, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a user either starts or stops sleeping in the bed.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.RespawnAnchorBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod(CustomRespawnTest.MODID)
|
||||
public class CustomRespawnTest
|
||||
{
|
||||
public static final boolean ENABLE = true;
|
||||
public static final String MODID = "custom_respawn_test";
|
||||
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
public static final RegistryObject<Block> TEST_RESPAWN_BLOCK = BLOCKS.register("test_respawn_block", () -> new CustomRespawnBlock(Block.Properties.of(Material.WOOD)));
|
||||
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
public static final RegistryObject<Item> TEST_RESPAWN_BLOCK_ITEM = ITEMS.register("test_respawn_block", () -> new BlockItem(TEST_RESPAWN_BLOCK.get(), (new Item.Properties())));
|
||||
|
||||
public CustomRespawnTest()
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
final IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(eventBus);
|
||||
ITEMS.register(eventBus);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomRespawnBlock extends Block
|
||||
{
|
||||
|
||||
public CustomRespawnBlock(Properties propertiesIn)
|
||||
{
|
||||
super(propertiesIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType use(BlockState p_225533_1_, World world, BlockPos pos, PlayerEntity p_225533_4_, Hand p_225533_5_, BlockRayTraceResult p_225533_6_)
|
||||
{
|
||||
if (!world.isClientSide && p_225533_4_ instanceof ServerPlayerEntity)
|
||||
{
|
||||
((ServerPlayerEntity)p_225533_4_).setRespawnPosition(world.dimension(), pos, 0, false, true);
|
||||
}
|
||||
return ActionResultType.sidedSuccess(world.isClientSide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Vector3d> getRespawnPosition(BlockState state, EntityType<?> type, IWorldReader world, BlockPos pos, float orientation, @Nullable LivingEntity entity)
|
||||
{
|
||||
return RespawnAnchorBlock.findStandUpPosition(type, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,9 +124,12 @@ license="LGPL v2.1"
|
||||
modId="entity_teleport_event_test"
|
||||
[[mods]]
|
||||
modId="text_linear_filtering_test"
|
||||
[[mods]]
|
||||
modId="custom_respawn_test"
|
||||
[[mods]]
|
||||
modId="custom_tas_test"
|
||||
[[mods]]
|
||||
modId="dimension_settings_test"
|
||||
[[mods]]
|
||||
modId="player_attack_knockback_test"
|
||||
|
||||
Reference in new issue
Block a user