移除屎山

This commit is contained in:
17146 2024-11-28 18:24:12 +08:00
parent 0b1c0efe82
commit 20bedc1159
5 changed files with 159 additions and 258 deletions

View file

@ -1,61 +1,38 @@
package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
@SuppressWarnings("deprecation")
public class ContainerBlock extends BaseEntityBlock implements SimpleWaterloggedBlock, EntityBlock {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty OPENED = BooleanProperty.create("opened");
public ContainerBlock() {
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(-1, 3600000).noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(3.0f).noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPENED, false));
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return switch (state.getValue(FACING)) {
default -> box(0, 0, 0, 16, 1, 16);
case NORTH -> box(0, 0, 0, 16, 1, 16);
case EAST -> box(0, 0, 0, 16, 1, 16);
case WEST -> box(0, 0, 0, 16, 1, 16);
};
return state.getValue(OPENED) ? box(0, 0, 0, 16, 1, 16) : box(0, 0, 0, 16, 16, 16);
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
@ -64,79 +41,17 @@ public class ContainerBlock extends BaseEntityBlock implements SimpleWaterlogged
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return ModBlockEntities.CONTAINER.get().create(blockPos, blockState);
}
@Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) {
return state.getFluidState().isEmpty();
}
@Override
public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
return 0;
return new ContainerBlockEntity(blockPos, blockState);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED);
builder.add(FACING).add(OPENED);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
boolean flag = context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER;
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, flag);
}
public BlockState rotate(BlockState state, Rotation rot) {
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
}
public BlockState mirror(BlockState state, Mirror mirrorIn) {
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
}
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}
@Override
public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor world, BlockPos currentPos, BlockPos facingPos) {
if (state.getValue(WATERLOGGED)) {
world.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
return super.updateShape(state, facing, facingState, world, currentPos, facingPos);
}
@Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
List<ItemStack> dropsOriginal = super.getDrops(state, builder);
if (!dropsOriginal.isEmpty())
return dropsOriginal;
return Collections.singletonList(new ItemStack(this, 1));
}
@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState blockstate, LivingEntity entity, ItemStack itemstack) {
super.setPlacedBy(level, pos, blockstate, entity, itemstack);
ModUtils.queueServerWork(18, () -> {
if (!level.isClientSide())
level.explode(null, pos.getX(), pos.getY() + 1, pos.getZ(), 0, Level.ExplosionInteraction.NONE);
if (level instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.EXPLOSION, pos.getX(), pos.getY() + 1, pos.getZ(), 40, 1.5, 1.5, 1.5, 1, false);
}
});
ModUtils.queueServerWork(20, () -> {
level.setBlock(BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), Blocks.AIR.defaultBlockState(), 3);
if (level instanceof ServerLevel _level) {
Entity entityToSpawn = ModEntities.MK_42.get().spawn(_level, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), MobSpawnType.MOB_SUMMONED);
if (entityToSpawn != null) {
entityToSpawn.setYRot(level.getRandom().nextFloat() * 360F);
}
}
});
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false);
}
}

View file

@ -1,19 +0,0 @@
package com.atsuishio.superbwarfare.block.listener;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockEntityRenderer;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(modid = ModUtils.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ClientListener {
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(ModBlockEntities.CONTAINER.get(), context -> new ContainerBlockEntityRenderer());
}
}

View file

@ -1,8 +1,11 @@
package com.atsuishio.superbwarfare.client;
import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockEntityRenderer;
import com.atsuishio.superbwarfare.client.tooltip.*;
import com.atsuishio.superbwarfare.client.tooltip.component.*;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@ -19,4 +22,9 @@ public class ClientRenderHandler {
event.register(SentinelImageComponent.class, ClientSentinelImageTooltip::new);
}
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(ModBlockEntities.CONTAINER.get(), context -> new ContainerBlockEntityRenderer());
}
}

View file

@ -1,124 +0,0 @@
{
"credit": "Made with Blockbench",
"parent": "builtin/entity",
"texture_size": [
128,
128
],
"display": {
"thirdperson_righthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"thirdperson_lefthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_righthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_lefthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"ground": {
"translation": [
0,
-1.75,
0
],
"scale": [
0.5,
0.5,
0.5
]
},
"gui": {
"rotation": [
-155,
-45,
180
],
"translation": [
0,
-4.5,
0
],
"scale": [
0.65,
0.65,
0.65
]
},
"head": {
"translation": [
0,
-7,
0
]
},
"fixed": {
"translation": [
0,
-7.75,
1
]
}
},
"textures": {
"particle": "item/container"
}
}

View file

@ -1,3 +1,124 @@
{
"parent": "superbwarfare:displaysettings/container.item"
"credit": "Made with Blockbench",
"parent": "builtin/entity",
"texture_size": [
128,
128
],
"display": {
"thirdperson_righthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"thirdperson_lefthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_righthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_lefthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"ground": {
"translation": [
0,
-1.75,
0
],
"scale": [
0.5,
0.5,
0.5
]
},
"gui": {
"rotation": [
-155,
-45,
180
],
"translation": [
0,
-4.5,
0
],
"scale": [
0.65,
0.65,
0.65
]
},
"head": {
"translation": [
0,
-7,
0
]
},
"fixed": {
"translation": [
0,
-7.75,
1
]
}
},
"textures": {
"particle": "superbwarfare:block/container"
}
}