mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Seats, part I
This commit is contained in:
parent
5ebb44f50b
commit
d3e7b23d6e
3 changed files with 133 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.simibubi.create;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.actors.SeatEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity;
|
||||
|
@ -24,6 +25,8 @@ public class AllEntityTypes {
|
|||
register("stationary_contraption", ContraptionEntity::new, EntityClassification.MISC, 20, 40, false, ContraptionEntity::build);
|
||||
public static final RegistryEntry<EntityType<SuperGlueEntity>> SUPER_GLUE =
|
||||
register("super_glue", SuperGlueEntity::new, EntityClassification.MISC, 10, Integer.MAX_VALUE, false, SuperGlueEntity::build);
|
||||
public static final RegistryEntry<EntityType<SeatEntity>> SEAT =
|
||||
register("seat", SeatEntity::new, EntityClassification.MISC, 0, Integer.MAX_VALUE, false, SeatEntity::build);
|
||||
|
||||
private static <T extends Entity> RegistryEntry<EntityType<T>> register(String name, IFactory<T> factory,
|
||||
EntityClassification group, int range, int updateFrequency, boolean sendVelocity,
|
||||
|
@ -45,5 +48,6 @@ public class AllEntityTypes {
|
|||
RenderingRegistry.registerEntityRenderingHandler(STATIONARY_CONTRAPTION.get(), ContraptionEntityRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler(CONTRAPTION.get(), ContraptionEntityRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler(SUPER_GLUE.get(), SuperGlueRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler(SEAT.get(), SeatEntity.Render::new);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,20 @@ import com.simibubi.create.AllShapes;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SeatBlock extends Block {
|
||||
|
||||
|
@ -27,11 +34,35 @@ public class SeatBlock extends Block {
|
|||
return;
|
||||
super.fillItemGroup(group, p_149666_2_);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFallenUpon(World p_180658_1_, BlockPos p_180658_2_, Entity p_180658_3_, float p_180658_4_) {
|
||||
super.onFallenUpon(p_180658_1_, p_180658_2_, p_180658_3_, p_180658_4_ * 0.5F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLanded(IBlockReader p_176216_1_, Entity p_176216_2_) {
|
||||
Blocks.PINK_BED.onLanded(p_176216_1_, p_176216_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_,
|
||||
ISelectionContext p_220053_4_) {
|
||||
return AllShapes.SEAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onUse(BlockState p_225533_1_, World world, BlockPos pos, PlayerEntity player, Hand p_225533_5_, BlockRayTraceResult p_225533_6_) {
|
||||
if (SeatEntity.TAKEN.containsKey(pos))
|
||||
return ActionResultType.FAIL;
|
||||
|
||||
if (world.isRemote)
|
||||
return ActionResultType.SUCCESS;
|
||||
|
||||
SeatEntity seat = new SeatEntity(world, pos);
|
||||
world.addEntity(seat);
|
||||
player.startRiding(seat);
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package com.simibubi.create.content.contraptions.components.actors;
|
||||
|
||||
import com.simibubi.create.AllEntityTypes;
|
||||
import net.minecraft.client.renderer.culling.ClippingHelperImpl;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SeatEntity extends Entity {
|
||||
|
||||
public static final Map<BlockPos, SeatEntity> TAKEN = new HashMap<>();
|
||||
|
||||
public SeatEntity(EntityType<?> p_i48580_1_, World p_i48580_2_) {
|
||||
super(p_i48580_1_, p_i48580_2_);
|
||||
}
|
||||
|
||||
public SeatEntity(World world, BlockPos pos) {
|
||||
this(AllEntityTypes.SEAT.get(), world);
|
||||
this.setPos(pos.getX() + 0.5, pos.getY() + 0.30, pos.getZ() + 0.5);
|
||||
noClip = true;
|
||||
TAKEN.put(pos, this);
|
||||
|
||||
}
|
||||
|
||||
public static EntityType.Builder<?> build(EntityType.Builder<?> builder) {
|
||||
@SuppressWarnings("unchecked")
|
||||
EntityType.Builder<SeatEntity> entityBuilder = (EntityType.Builder<SeatEntity>) builder;
|
||||
return entityBuilder.size(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.isRemote)
|
||||
return;
|
||||
|
||||
BlockPos blockPos = new BlockPos(getX(), getY(), getZ());
|
||||
if (isBeingRidden() && world.getBlockState(blockPos).getBlock() instanceof SeatBlock)
|
||||
return;
|
||||
|
||||
TAKEN.remove(blockPos);
|
||||
this.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canBeRidden(Entity p_184228_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removePassenger(Entity entity) {
|
||||
super.removePassenger(entity);
|
||||
Vec3d pos = entity.getPositionVec();
|
||||
entity.setPosition(pos.x, pos.y + 0.7, pos.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerData() {}
|
||||
|
||||
@Override
|
||||
protected void readAdditional(CompoundNBT p_70037_1_) {}
|
||||
|
||||
@Override
|
||||
protected void writeAdditional(CompoundNBT p_213281_1_) {}
|
||||
|
||||
@Override
|
||||
public IPacket<?> createSpawnPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
}
|
||||
|
||||
public static class Render extends EntityRenderer<SeatEntity> {
|
||||
|
||||
public Render(EntityRendererManager p_i46179_1_) {
|
||||
super(p_i46179_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(SeatEntity p_225626_1_, ClippingHelperImpl p_225626_2_, double p_225626_3_, double p_225626_5_, double p_225626_7_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getEntityTexture(SeatEntity p_110775_1_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue