Add part activation
This commit is contained in:
parent
72fa61fe87
commit
f03001699b
|
@ -14,6 +14,8 @@ import net.minecraft.world.World;
|
||||||
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartSlot;
|
import net.shadowfacts.simplemultipart.multipart.MultipartSlot;
|
||||||
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
import net.shadowfacts.simplemultipart.multipart.MultipartState;
|
||||||
|
import net.shadowfacts.simplemultipart.util.MultipartHelper;
|
||||||
|
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -27,19 +29,36 @@ public class MultipartContainerBlock extends Block implements BlockEntityProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(BlockState var1, World world, BlockPos pos, PlayerEntity player, Hand var5, Direction var6, float var7, float var8, float var9) {
|
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
|
||||||
if (player.isSneaking()) {
|
// if (player.isSneaking()) {
|
||||||
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
// MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
||||||
System.out.println(container.getParts());
|
// System.out.println(container.getParts());
|
||||||
return true;
|
// return true;
|
||||||
} else {
|
// } else {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
||||||
|
if (container == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MultipartHitResult hit = MultipartHelper.rayTrace(container, world, pos, player);
|
||||||
|
if (hit == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MultipartState partState = container.get(hit.partSlot);
|
||||||
|
return partState.activate(hit.partSlot, container, player, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
|
||||||
|
if (container == null) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
Map<MultipartSlot, MultipartState> parts = container.getParts();
|
Map<MultipartSlot, MultipartState> parts = container.getParts();
|
||||||
return new MultipartContainerBlockState(state, parts);
|
return new MultipartContainerBlockState(state, parts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package net.shadowfacts.simplemultipart.multipart;
|
package net.shadowfacts.simplemultipart.multipart;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.state.StateFactory;
|
import net.minecraft.state.StateFactory;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.loot.LootSupplier;
|
import net.minecraft.world.loot.LootSupplier;
|
||||||
import net.minecraft.world.loot.LootTables;
|
import net.minecraft.world.loot.LootTables;
|
||||||
|
@ -75,6 +78,9 @@ public abstract class Multipart {
|
||||||
return dropTableId;
|
return dropTableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be overridden, should only be called via {@link MultipartState#getDroppedStacks)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public List<ItemStack> getDroppedStacks(MultipartState state, LootContext.Builder builder) {
|
public List<ItemStack> getDroppedStacks(MultipartState state, LootContext.Builder builder) {
|
||||||
Identifier dropTableId = getDropTableId();
|
Identifier dropTableId = getDropTableId();
|
||||||
|
@ -88,4 +94,12 @@ public abstract class Multipart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be overridden, should only be called via {@link MultipartState#activate}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public boolean activate(MultipartState state, MultipartSlot slot, MultipartContainerBlockEntity container, PlayerEntity player, Hand hand) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package net.shadowfacts.simplemultipart.multipart;
|
package net.shadowfacts.simplemultipart.multipart;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.AbstractPropertyContainer;
|
import net.minecraft.state.AbstractPropertyContainer;
|
||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.loot.context.LootContext;
|
import net.minecraft.world.loot.context.LootContext;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
|
||||||
|
@ -38,4 +40,9 @@ public class MultipartState extends AbstractPropertyContainer<Multipart, Multipa
|
||||||
return owner.getDroppedStacks(this, builder);
|
return owner.getDroppedStacks(this, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean activate(MultipartSlot slot, MultipartContainerBlockEntity container, PlayerEntity player, Hand hand) {
|
||||||
|
//noinspection deprecated
|
||||||
|
return owner.activate(this, slot, container, player, hand);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.shadowfacts.simplemultipart.test;
|
package net.shadowfacts.simplemultipart.test;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
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.MultipartContainerBlockEntity;
|
||||||
|
@ -23,4 +25,10 @@ public class GreenMultipart extends Multipart {
|
||||||
return VoxelShapes.cube(0, 0, 0, 1, 1, 1/16f);
|
return VoxelShapes.cube(0, 0, 0, 1, 1, 1/16f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean activate(MultipartState state, MultipartSlot slot, MultipartContainerBlockEntity container, PlayerEntity player, Hand hand) {
|
||||||
|
System.out.println("part activated");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue