Cleanup
This commit is contained in:
parent
b334e6987e
commit
17a5a8d6ee
|
@ -9,9 +9,9 @@ import net.minecraft.world.loot.context.LootContextType;
|
||||||
import net.minecraft.world.loot.context.LootContextTypes;
|
import net.minecraft.world.loot.context.LootContextTypes;
|
||||||
import net.minecraft.world.loot.context.Parameter;
|
import net.minecraft.world.loot.context.Parameter;
|
||||||
import net.minecraft.world.loot.context.Parameters;
|
import net.minecraft.world.loot.context.Parameters;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerEventHandler;
|
import net.shadowfacts.simplemultipart.container.ContainerBlockEntity;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlock;
|
import net.shadowfacts.simplemultipart.container.ContainerEventHandler;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.container.ContainerBlock;
|
||||||
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
|
|
||||||
|
@ -30,14 +30,14 @@ public class SimpleMultipart implements ModInitializer {
|
||||||
public static final Parameter<MultipartState> MULTIPART_STATE_PARAMETER = new Parameter<>(new Identifier(MODID, "multipart_state"));
|
public static final Parameter<MultipartState> MULTIPART_STATE_PARAMETER = new Parameter<>(new Identifier(MODID, "multipart_state"));
|
||||||
public static final LootContextType MULTIPART_LOOT_CONTEXT = createMultipartLootContextType();
|
public static final LootContextType MULTIPART_LOOT_CONTEXT = createMultipartLootContextType();
|
||||||
|
|
||||||
public static final MultipartContainerBlock containerBlock = new MultipartContainerBlock();
|
public static final ContainerBlock containerBlock = new ContainerBlock();
|
||||||
public static final BlockEntityType<MultipartContainerBlockEntity> containerBlockEntity = createBlockEntityType();
|
public static final BlockEntityType<ContainerBlockEntity> containerBlockEntity = createBlockEntityType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
Registry.register(Registry.BLOCK, new Identifier(MODID, "container"), containerBlock);
|
Registry.register(Registry.BLOCK, new Identifier(MODID, "container"), containerBlock);
|
||||||
|
|
||||||
MultipartContainerEventHandler.register();
|
ContainerEventHandler.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Registry<Multipart> createMultipartRegistry() {
|
private static Registry<Multipart> createMultipartRegistry() {
|
||||||
|
@ -46,8 +46,8 @@ public class SimpleMultipart implements ModInitializer {
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BlockEntityType<MultipartContainerBlockEntity> createBlockEntityType() {
|
private static BlockEntityType<ContainerBlockEntity> createBlockEntityType() {
|
||||||
BlockEntityType.Builder<MultipartContainerBlockEntity> builder = BlockEntityType.Builder.create(MultipartContainerBlockEntity::new);
|
BlockEntityType.Builder<ContainerBlockEntity> builder = BlockEntityType.Builder.create(ContainerBlockEntity::new);
|
||||||
return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, "container"), builder.method_11034(null));
|
return Registry.register(Registry.BLOCK_ENTITY, new Identifier(MODID, "container"), builder.method_11034(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,4 +19,6 @@ public interface MultipartContainer {
|
||||||
|
|
||||||
boolean breakPart(MultipartState state);
|
boolean breakPart(MultipartState state);
|
||||||
|
|
||||||
|
void schedulePartSave();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockState;
|
import net.shadowfacts.simplemultipart.container.ContainerBlockState;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -25,10 +25,10 @@ public class MultipartContainerBakedModel implements BakedModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads(BlockState state, Direction side, Random random) {
|
public List<BakedQuad> getQuads(BlockState state, Direction side, Random random) {
|
||||||
if (!(state instanceof MultipartContainerBlockState)) {
|
if (!(state instanceof ContainerBlockState)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MultipartContainerBlockState containerState = (MultipartContainerBlockState)state;
|
ContainerBlockState containerState = (ContainerBlockState)state;
|
||||||
// TODO: would manually building the list be more efficient?
|
// TODO: would manually building the list be more efficient?
|
||||||
return containerState.getParts().stream()
|
return containerState.getParts().stream()
|
||||||
.flatMap(view -> {
|
.flatMap(view -> {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.util.shape.VoxelShapes;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.ExtendedBlockView;
|
import net.minecraft.world.ExtendedBlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
||||||
|
@ -21,15 +22,15 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public class MultipartContainerBlock extends Block implements BlockEntityProvider, RenderStateProvider {
|
public class ContainerBlock extends Block implements BlockEntityProvider, RenderStateProvider {
|
||||||
|
|
||||||
public MultipartContainerBlock() {
|
public ContainerBlock() {
|
||||||
super(FabricBlockSettings.of(Material.STONE).build());
|
super(FabricBlockSettings.of(Material.STONE).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
|
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
|
||||||
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -44,18 +45,19 @@ public class MultipartContainerBlock extends Block implements BlockEntityProvide
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForRendering(BlockState state, BlockPos pos, ExtendedBlockView world) {
|
public BlockState getStateForRendering(BlockState state, BlockPos pos, ExtendedBlockView world) {
|
||||||
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<MultipartView> parts = container.getParts();
|
Set<MultipartView> parts = container.getParts();
|
||||||
return new MultipartContainerBlockState(state, parts);
|
return new ContainerBlockState(state, parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public VoxelShape getBoundingShape(BlockState state, BlockView world, BlockPos pos) {
|
public VoxelShape getBoundingShape(BlockState state, BlockView world, BlockPos pos) {
|
||||||
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
return VoxelShapes.empty();
|
return VoxelShapes.empty();
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,7 @@ public class MultipartContainerBlock extends Block implements BlockEntityProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultipartContainerBlockEntity createBlockEntity(BlockView world) {
|
public ContainerBlockEntity createBlockEntity(BlockView world) {
|
||||||
return new MultipartContainerBlockEntity();
|
return new ContainerBlockEntity();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,11 +30,11 @@ import java.util.*;
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public class MultipartContainerBlockEntity extends BlockEntity implements MultipartContainer, ClientSerializable {
|
public class ContainerBlockEntity extends BlockEntity implements MultipartContainer, ClientSerializable {
|
||||||
|
|
||||||
private Set<Entry> parts = new HashSet<>();
|
private Set<Entry> parts = new HashSet<>();
|
||||||
|
|
||||||
public MultipartContainerBlockEntity() {
|
public ContainerBlockEntity() {
|
||||||
super(SimpleMultipart.containerBlockEntity);
|
super(SimpleMultipart.containerBlockEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,12 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Multip
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemStack> getDroppedStacks(MultipartContainerBlockEntity.Entry e, ServerWorld world, BlockPos pos) {
|
@Override
|
||||||
|
public void schedulePartSave() {
|
||||||
|
markDirty(); // see yarn #360
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> getDroppedStacks(ContainerBlockEntity.Entry e, ServerWorld world, BlockPos pos) {
|
||||||
LootContext.Builder builder = new LootContext.Builder(world);
|
LootContext.Builder builder = new LootContext.Builder(world);
|
||||||
builder.setRandom(world.random);
|
builder.setRandom(world.random);
|
||||||
builder.put(SimpleMultipart.MULTIPART_STATE_PARAMETER, e.state);
|
builder.put(SimpleMultipart.MULTIPART_STATE_PARAMETER, e.state);
|
||||||
|
@ -174,8 +179,8 @@ public class MultipartContainerBlockEntity extends BlockEntity implements Multip
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultipartContainerBlockEntity getContainer() {
|
public ContainerBlockEntity getContainer() {
|
||||||
return MultipartContainerBlockEntity.this; // TODO: is this bad?
|
return ContainerBlockEntity.this; // TODO: is this bad?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -8,11 +8,11 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public class MultipartContainerBlockState extends BlockState {
|
public class ContainerBlockState extends BlockState {
|
||||||
|
|
||||||
private Set<MultipartView> parts;
|
private Set<MultipartView> parts;
|
||||||
|
|
||||||
public MultipartContainerBlockState(BlockState delegate, Set<MultipartView> parts) {
|
public ContainerBlockState(BlockState delegate, Set<MultipartView> parts) {
|
||||||
super(delegate.getBlock(), delegate.getEntries());
|
super(delegate.getBlock(), delegate.getEntries());
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
||||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||||
|
@ -14,10 +15,10 @@ import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public class MultipartContainerEventHandler {
|
public class ContainerEventHandler {
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
PlayerInteractionEvent.ATTACK_BLOCK.register(MultipartContainerEventHandler::handleBlockAttack);
|
PlayerInteractionEvent.ATTACK_BLOCK.register(ContainerEventHandler::handleBlockAttack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ActionResult handleBlockAttack(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
private static ActionResult handleBlockAttack(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||||
|
@ -25,7 +26,7 @@ public class MultipartContainerEventHandler {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
return ActionResult.FAILURE;
|
return ActionResult.FAILURE;
|
||||||
}
|
}
|
|
@ -4,10 +4,9 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.item.ItemUsageContext;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
|
import net.shadowfacts.simplemultipart.container.ContainerBlockEntity;
|
||||||
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
import net.shadowfacts.simplemultipart.util.MultipartPlacementContext;
|
import net.shadowfacts.simplemultipart.util.MultipartPlacementContext;
|
||||||
|
@ -31,14 +30,14 @@ public class ItemMultipart extends Item {
|
||||||
|
|
||||||
protected ActionResult tryPlace(ItemUsageContext context) {
|
protected ActionResult tryPlace(ItemUsageContext context) {
|
||||||
// If a multipart inside an existing container was clicked, try inserting into that
|
// If a multipart inside an existing container was clicked, try inserting into that
|
||||||
MultipartContainerBlockEntity hitContainer = getContainer(context);
|
MultipartContainer hitContainer = getContainer(context);
|
||||||
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, context))) {
|
if (hitContainer != null && tryPlace(new MultipartPlacementContext(hitContainer, context))) {
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, get or create a new container and try inserting into that
|
// Otherwise, get or create a new container and try inserting into that
|
||||||
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), context.getPos().offset(context.getFacing()), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
ItemUsageContext offsetContext = new ItemUsageContext(context.getPlayer(), context.getItemStack(), context.getPos().offset(context.getFacing()), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
||||||
MultipartContainerBlockEntity offsetContainer = getOrCreateContainer(offsetContext);
|
MultipartContainer offsetContainer = getOrCreateContainer(offsetContext);
|
||||||
if (offsetContainer != null && tryPlace(new MultipartPlacementContext(offsetContainer, offsetContext))) {
|
if (offsetContainer != null && tryPlace(new MultipartPlacementContext(offsetContainer, offsetContext))) {
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -46,22 +45,22 @@ public class ItemMultipart extends Item {
|
||||||
return ActionResult.FAILURE;
|
return ActionResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MultipartContainerBlockEntity getContainer(ItemUsageContext context) {
|
protected MultipartContainer getContainer(ItemUsageContext context) {
|
||||||
BlockState state = context.getWorld().getBlockState(context.getPos());
|
BlockState state = context.getWorld().getBlockState(context.getPos());
|
||||||
if (state.getBlock() == SimpleMultipart.containerBlock) {
|
if (state.getBlock() == SimpleMultipart.containerBlock) {
|
||||||
return (MultipartContainerBlockEntity)context.getWorld().getBlockEntity(context.getPos());
|
return (MultipartContainer)context.getWorld().getBlockEntity(context.getPos());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MultipartContainerBlockEntity getOrCreateContainer(ItemUsageContext context) {
|
protected MultipartContainer getOrCreateContainer(ItemUsageContext context) {
|
||||||
MultipartContainerBlockEntity container = getContainer(context);
|
MultipartContainer container = getContainer(context);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
BlockState existing = context.getWorld().getBlockState(context.getPos());
|
BlockState existing = context.getWorld().getBlockState(context.getPos());
|
||||||
if (existing.isAir()) { // TODO: should check is replaceable (might not be mapped?)
|
if (existing.isAir()) { // TODO: should check is replaceable (might not be mapped?)
|
||||||
context.getWorld().setBlockState(context.getPos(), SimpleMultipart.containerBlock.getDefaultState());
|
context.getWorld().setBlockState(context.getPos(), SimpleMultipart.containerBlock.getDefaultState());
|
||||||
container = (MultipartContainerBlockEntity)context.getWorld().getBlockEntity(context.getPos());
|
container = (MultipartContainer)context.getWorld().getBlockEntity(context.getPos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return container;
|
return container;
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package net.shadowfacts.simplemultipart.multipart.entity;
|
package net.shadowfacts.simplemultipart.multipart.entity;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public abstract class MultipartEntity {
|
public abstract class MultipartEntity {
|
||||||
|
|
||||||
public MultipartContainerBlockEntity container;
|
public MultipartContainer container;
|
||||||
|
|
||||||
public MultipartEntity(MultipartContainerBlockEntity container) {
|
public MultipartEntity(MultipartContainer container) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void scheduleSave() {
|
protected void scheduleSave() {
|
||||||
container.markDirty(); // see yarn #360
|
container.schedulePartSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompoundTag toTag(CompoundTag tag) {
|
public CompoundTag toTag(CompoundTag tag) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.shadowfacts.simplemultipart.multipart.entity;
|
package net.shadowfacts.simplemultipart.multipart.entity;
|
||||||
|
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,6 @@ import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
public interface MultipartEntityProvider {
|
public interface MultipartEntityProvider {
|
||||||
|
|
||||||
/*@Nullable*/
|
/*@Nullable*/
|
||||||
MultipartEntity createMultipartEntity(MultipartState state, MultipartContainerBlockEntity container);
|
MultipartEntity createMultipartEntity(MultipartState state, MultipartContainer container);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@ package net.shadowfacts.simplemultipart.util;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.state.PropertyContainer;
|
import net.minecraft.state.PropertyContainer;
|
||||||
import net.minecraft.state.StateFactory;
|
import net.minecraft.state.StateFactory;
|
||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
|
@ -15,10 +13,9 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.loot.context.LootContext;
|
|
||||||
import net.minecraft.world.loot.context.Parameters;
|
|
||||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
|
import net.shadowfacts.simplemultipart.container.ContainerBlockEntity;
|
||||||
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
|
|
||||||
|
@ -29,7 +26,7 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class MultipartHelper {
|
public class MultipartHelper {
|
||||||
|
|
||||||
public static MultipartHitResult rayTrace(MultipartContainerBlockEntity container, World world, BlockPos pos, PlayerEntity player) {
|
public static MultipartHitResult rayTrace(MultipartContainer container, World world, BlockPos pos, PlayerEntity player) {
|
||||||
// copied from BoatItem::use
|
// copied from BoatItem::use
|
||||||
float var6 = MathHelper.lerp(1.0F, player.prevPitch, player.pitch);
|
float var6 = MathHelper.lerp(1.0F, player.prevPitch, player.pitch);
|
||||||
float var7 = MathHelper.lerp(1.0F, player.prevYaw, player.yaw);
|
float var7 = MathHelper.lerp(1.0F, player.prevYaw, player.yaw);
|
||||||
|
@ -49,7 +46,7 @@ public class MultipartHelper {
|
||||||
return rayTrace(container, world, pos, start, end);
|
return rayTrace(container, world, pos, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultipartHitResult rayTrace(MultipartContainerBlockEntity container, World world, BlockPos pos, Vec3d start, Vec3d end) {
|
public static MultipartHitResult rayTrace(MultipartContainer container, World world, BlockPos pos, Vec3d start, Vec3d end) {
|
||||||
return container.getParts().stream()
|
return container.getParts().stream()
|
||||||
.map(view -> {
|
.map(view -> {
|
||||||
VoxelShape shape = view.getState().getBoundingShape(view);
|
VoxelShape shape = view.getState().getBoundingShape(view);
|
||||||
|
|
|
@ -5,25 +5,25 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.item.ItemUsageContext;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.api.MultipartContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public class MultipartPlacementContext extends ItemUsageContext {
|
public class MultipartPlacementContext extends ItemUsageContext {
|
||||||
|
|
||||||
private final MultipartContainerBlockEntity container;
|
private final MultipartContainer container;
|
||||||
|
|
||||||
public MultipartPlacementContext(MultipartContainerBlockEntity container, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
|
public MultipartPlacementContext(MultipartContainer container, PlayerEntity player, ItemStack stack, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) {
|
||||||
super(player, stack, pos, side, hitX, hitY, hitZ);
|
super(player, stack, pos, side, hitX, hitY, hitZ);
|
||||||
this.container = container;
|
this.container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipartPlacementContext(MultipartContainerBlockEntity container, ItemUsageContext context) {
|
public MultipartPlacementContext(MultipartContainer container, ItemUsageContext context) {
|
||||||
this(container, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
this(container, context.getPlayer(), context.getItemStack(), context.getPos(), context.getFacing(), context.getHitX(), context.getHitY(), context.getHitZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipartContainerBlockEntity getContainer() {
|
public MultipartContainer getContainer() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.container.ContainerBlockEntity;
|
||||||
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
import net.shadowfacts.simplemultipart.multipart.Multipart;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
import net.shadowfacts.simplemultipart.multipart.entity.MultipartEntity;
|
||||||
|
@ -33,12 +33,12 @@ public class EntityTestPart extends Multipart implements MultipartEntityProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultipartEntity createMultipartEntity(MultipartState state, MultipartContainerBlockEntity container) {
|
public MultipartEntity createMultipartEntity(MultipartState state, ContainerBlockEntity container) {
|
||||||
return new Entity(container);
|
return new Entity(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Entity extends MultipartEntity {
|
public static class Entity extends MultipartEntity {
|
||||||
public Entity(MultipartContainerBlockEntity container) {
|
public Entity(ContainerBlockEntity container) {
|
||||||
super(container);
|
super(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue