Respawn obelisk (WIP)
This commit is contained in:
parent
24b4b722c2
commit
61460e6e6c
14 changed files with 384 additions and 0 deletions
174
src/main/java/ru/betterend/blocks/BlockRespawnObelisk.java
Normal file
174
src/main/java/ru/betterend/blocks/BlockRespawnObelisk.java
Normal file
|
@ -0,0 +1,174 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.BlockBase;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IColorProvider;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockRespawnObelisk extends BlockBase implements IColorProvider, IRenderTypeable {
|
||||
private static final VoxelShape VOXEL_SHAPE_BOTTOM = Block.createCuboidShape(1, 0, 1, 15, 16, 15);
|
||||
private static final VoxelShape VOXEL_SHAPE_MIDDLE_TOP = Block.createCuboidShape(2, 0, 2, 14, 16, 14);
|
||||
|
||||
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
|
||||
|
||||
public BlockRespawnObelisk() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.END_STONE).luminance((state) -> {
|
||||
return (state.get(SHAPE) == TripleShape.BOTTOM) ? 0 : 15;
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
return (state.get(SHAPE) == TripleShape.BOTTOM) ? VOXEL_SHAPE_BOTTOM : VOXEL_SHAPE_MIDDLE_TOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(SHAPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!world.getBlockState(pos.up(i)).getMaterial().isReplaceable()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
|
||||
state = this.getDefaultState();
|
||||
BlocksHelper.setWithUpdate(world, pos, state.with(SHAPE, TripleShape.BOTTOM));
|
||||
BlocksHelper.setWithUpdate(world, pos.up(), state.with(SHAPE, TripleShape.MIDDLE));
|
||||
BlocksHelper.setWithUpdate(world, pos.up(2), state.with(SHAPE, TripleShape.TOP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
TripleShape shape = state.get(SHAPE);
|
||||
if (shape == TripleShape.BOTTOM) {
|
||||
if (world.getBlockState(pos.up()).isOf(this)) {
|
||||
return state;
|
||||
}
|
||||
else {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
else if (shape == TripleShape.MIDDLE) {
|
||||
if (world.getBlockState(pos.up()).isOf(this) && world.getBlockState(pos.down()).isOf(this)) {
|
||||
return state;
|
||||
}
|
||||
else {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (world.getBlockState(pos.down()).isOf(this)) {
|
||||
return state;
|
||||
}
|
||||
else {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
if (player.isCreative()) {
|
||||
TripleShape shape = state.get(SHAPE);
|
||||
if (shape == TripleShape.MIDDLE) {
|
||||
BlocksHelper.setWithUpdate(world, pos.down(), Blocks.AIR);
|
||||
}
|
||||
else if (shape == TripleShape.TOP) {
|
||||
BlocksHelper.setWithUpdate(world, pos.down(2), Blocks.AIR);
|
||||
}
|
||||
}
|
||||
super.onBreak(world, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
if (state.get(SHAPE) == TripleShape.BOTTOM) {
|
||||
return Lists.newArrayList(new ItemStack(this));
|
||||
}
|
||||
else {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.TRANSLUCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockColorProvider getProvider() {
|
||||
return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemColorProvider getItemProvider() {
|
||||
return (stack, tintIndex) -> {
|
||||
return MHelper.color(255, 255, 255);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
ItemStack itemStack = player.getStackInHand(hand);
|
||||
boolean canActivate = itemStack.getItem() == EndItems.AMBER_GEM && itemStack.getCount() > 3;
|
||||
if (hand != Hand.MAIN_HAND || !canActivate) {
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if (!world.isClient) {
|
||||
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) player;
|
||||
serverPlayerEntity.setSpawnPoint(world.getRegistryKey(), pos, 0.0F, false, true);
|
||||
serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.set_spawn"), true);
|
||||
world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
if (!player.isCreative()) {
|
||||
itemStack.decrement(4);
|
||||
}
|
||||
}
|
||||
return player.isCreative() ? ActionResult.PASS : ActionResult.success(world.isClient);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
@Mixin(PlayerEntity.class)
|
||||
public abstract class PlayerEntityMixin {
|
||||
private static Direction[] HORIZONTAL;
|
||||
|
||||
@Inject(method = "findRespawnPosition", at = @At(value = "HEAD"), cancellable = true)
|
||||
private static void statueRespawn(ServerWorld world, BlockPos pos, float f, boolean bl, boolean bl2, CallbackInfoReturnable<Optional<Vec3d>> info) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.isOf(EndBlocks.RESPAWN_OBELISK)) {
|
||||
info.setReturnValue(beObeliskRespawnPosition(world, pos, blockState));
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<Vec3d> beObeliskRespawnPosition(ServerWorld world, BlockPos pos, BlockState state) {
|
||||
if (state.get(BlockProperties.TRIPLE_SHAPE) == TripleShape.TOP) {
|
||||
pos = pos.down(2);
|
||||
}
|
||||
else if (state.get(BlockProperties.TRIPLE_SHAPE) == TripleShape.MIDDLE) {
|
||||
pos = pos.down();
|
||||
}
|
||||
if (HORIZONTAL == null) {
|
||||
HORIZONTAL = BlocksHelper.makeHorizontal();
|
||||
}
|
||||
MHelper.shuffle(HORIZONTAL, world.getRandom());
|
||||
for (Direction dir: HORIZONTAL) {
|
||||
BlockPos p = pos.offset(dir);
|
||||
BlockState state2 = world.getBlockState(p);
|
||||
if (!state2.getMaterial().blocksMovement() && state2.getCollisionShape(world, pos).isEmpty()) {
|
||||
return Optional.of(Vec3d.of(p).add(0.5, 0, 0.5));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
|
@ -54,6 +54,7 @@ import ru.betterend.blocks.BlockMurkweed;
|
|||
import ru.betterend.blocks.BlockNeedlegrass;
|
||||
import ru.betterend.blocks.BlockPath;
|
||||
import ru.betterend.blocks.BlockPythadendronSapling;
|
||||
import ru.betterend.blocks.BlockRespawnObelisk;
|
||||
import ru.betterend.blocks.BlockShadowBerry;
|
||||
import ru.betterend.blocks.BlockShadowGrass;
|
||||
import ru.betterend.blocks.BlockSulphurCrystal;
|
||||
|
@ -245,6 +246,8 @@ public class EndBlocks {
|
|||
public static final Block AURORA_CRYSTAL = registerBlock("aurora_crystal", new AuroraCrystalBlock());
|
||||
public static final Block AMBER_BLOCK = registerBlock("amber_block", new BlockAmber());
|
||||
|
||||
public static final Block RESPAWN_OBELISK = registerBlock("respawn_obelisk", new BlockRespawnObelisk());
|
||||
|
||||
// Lanterns
|
||||
public static final Block ANDESITE_LANTERN = registerBlock("andesite_lantern", new BlockStoneLantern(Blocks.ANDESITE));
|
||||
public static final Block DIORITE_LANTERN = registerBlock("diorite_lantern", new BlockStoneLantern(Blocks.DIORITE));
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"shape=top": { "model": "betterend:block/respawn_obelisk_top" },
|
||||
"shape=middle": { "model": "betterend:block/respawn_obelisk_middle" },
|
||||
"shape=bottom": { "model": "betterend:block/respawn_obelisk_bottom" }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"defaultMap": {
|
||||
"spriteMap": [
|
||||
{
|
||||
"sprite": "betterend:block/aurora_crystal",
|
||||
"material": "betterend:glow_all"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio",
|
||||
"textures": {
|
||||
"particle": "betterend:block/amber_block",
|
||||
"texture": "betterend:block/amber_block",
|
||||
"side": "betterend:block/respawn_obelisk_bottom_side"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 1, 0, 1 ],
|
||||
"to": [ 15, 4, 15 ],
|
||||
"faces": {
|
||||
"down": { "uv": [ 1, 1, 15, 15 ], "texture": "#texture", "cullface": "down" },
|
||||
"up": { "uv": [ 1, 1, 15, 15 ], "texture": "#texture" },
|
||||
"north": { "uv": [ 1, 12, 15, 16 ], "texture": "#side" },
|
||||
"south": { "uv": [ 1, 12, 15, 16 ], "texture": "#side" },
|
||||
"west": { "uv": [ 1, 12, 15, 16 ], "texture": "#side" },
|
||||
"east": { "uv": [ 1, 12, 15, 16 ], "texture": "#side" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 2, 4, 2 ],
|
||||
"to": [ 14, 14, 14 ],
|
||||
"faces": {
|
||||
"north": { "uv": [ 2, 2, 14, 12 ], "texture": "#side" },
|
||||
"south": { "uv": [ 2, 2, 14, 12 ], "texture": "#side" },
|
||||
"west": { "uv": [ 2, 2, 14, 12 ], "texture": "#side" },
|
||||
"east": { "uv": [ 2, 2, 14, 12 ], "texture": "#side" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 1, 14, 1 ],
|
||||
"to": [ 15, 16, 15 ],
|
||||
"faces": {
|
||||
"down": { "uv": [ 1, 1, 15, 15 ], "texture": "#texture" },
|
||||
"up": { "uv": [ 1, 1, 15, 15 ], "texture": "#texture" },
|
||||
"north": { "uv": [ 1, 0, 15, 2 ], "texture": "#side" },
|
||||
"south": { "uv": [ 1, 0, 15, 2 ], "texture": "#side" },
|
||||
"west": { "uv": [ 1, 0, 15, 2 ], "texture": "#side" },
|
||||
"east": { "uv": [ 1, 0, 15, 2 ], "texture": "#side" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio",
|
||||
"textures": {
|
||||
"particle": "betterend:block/amber_block",
|
||||
"texture": "betterend:block/respawn_obelisk_top_and_side",
|
||||
"crystal": "betterend:block/aurora_crystal"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 2, 0, 2 ],
|
||||
"to": [ 14, 2, 14 ],
|
||||
"faces": {
|
||||
"up": { "uv": [ 2, 2, 14, 14 ], "texture": "#texture" },
|
||||
"north": { "uv": [ 2, 14, 14, 16 ], "texture": "#texture" },
|
||||
"south": { "uv": [ 2, 14, 14, 16 ], "texture": "#texture" },
|
||||
"west": { "uv": [ 2, 14, 14, 16 ], "texture": "#texture" },
|
||||
"east": { "uv": [ 2, 14, 14, 16 ], "texture": "#texture" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 3, 2, 3 ],
|
||||
"to": [ 13, 16, 13 ],
|
||||
"shade": false,
|
||||
"faces": {
|
||||
"north": { "uv": [ 3, 0, 13, 14 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"south": { "uv": [ 3, 0, 13, 14 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"west": { "uv": [ 3, 0, 13, 14 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"east": { "uv": [ 3, 0, 13, 14 ], "texture": "#crystal", "tintindex": 0 }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio",
|
||||
"textures": {
|
||||
"particle": "betterend:block/amber_block",
|
||||
"texture": "betterend:block/respawn_obelisk_top_and_side",
|
||||
"crystal": "betterend:block/aurora_crystal"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 2, 12, 2 ],
|
||||
"to": [ 14, 14, 14 ],
|
||||
"faces": {
|
||||
"down": { "uv": [ 2, 2, 14, 14 ], "texture": "#texture" },
|
||||
"up": { "uv": [ 2, 2, 14, 14 ], "texture": "#texture" },
|
||||
"north": { "uv": [ 2, 0, 14, 2 ], "texture": "#texture" },
|
||||
"south": { "uv": [ 2, 0, 14, 2 ], "texture": "#texture" },
|
||||
"west": { "uv": [ 2, 0, 14, 2 ], "texture": "#texture" },
|
||||
"east": { "uv": [ 2, 0, 14, 2 ], "texture": "#texture" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 3, 0, 3 ],
|
||||
"to": [ 13, 12, 13 ],
|
||||
"shade": false,
|
||||
"faces": {
|
||||
"north": { "uv": [ 3, 4, 13, 16 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"south": { "uv": [ 3, 4, 13, 16 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"west": { "uv": [ 3, 4, 13, 16 ], "texture": "#crystal", "tintindex": 0 },
|
||||
"east": { "uv": [ 3, 4, 13, 16 ], "texture": "#crystal", "tintindex": 0 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"__comment": "Box1",
|
||||
"from": [ 3, 14, 3 ],
|
||||
"to": [ 13, 16, 13 ],
|
||||
"faces": {
|
||||
"up": { "uv": [ 3, 3, 13, 13 ], "texture": "#texture", "cullface": "up" },
|
||||
"north": { "uv": [ 3, 0, 13, 2 ], "texture": "#texture" },
|
||||
"south": { "uv": [ 3, 0, 13, 2 ], "texture": "#texture" },
|
||||
"west": { "uv": [ 3, 0, 13, 2 ], "texture": "#texture" },
|
||||
"east": { "uv": [ 3, 0, 13, 2 ], "texture": "#texture" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "betterend:item/respawn_obelisk"
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 285 B After Width: | Height: | Size: 384 B |
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -24,6 +24,7 @@
|
|||
"HostileEntityMixin",
|
||||
"LivingEntityMixin",
|
||||
"BoneMealItemMixin",
|
||||
"PlayerEntityMixin",
|
||||
"SlimeEntityMixin",
|
||||
"BrewingAccessor",
|
||||
"EntityMixin"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue