Add part activation

This commit is contained in:
Shadowfacts 2018-12-19 20:44:53 -05:00
parent 72fa61fe87
commit f03001699b
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 54 additions and 6 deletions

View File

@ -14,6 +14,8 @@ import net.minecraft.world.World;
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
import net.shadowfacts.simplemultipart.multipart.MultipartSlot;
import net.shadowfacts.simplemultipart.multipart.MultipartState;
import net.shadowfacts.simplemultipart.util.MultipartHelper;
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
import java.util.Map;
@ -27,19 +29,36 @@ public class MultipartContainerBlock extends Block implements BlockEntityProvide
}
@Override
public boolean activate(BlockState var1, World world, BlockPos pos, PlayerEntity player, Hand var5, Direction var6, float var7, float var8, float var9) {
if (player.isSneaking()) {
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
System.out.println(container.getParts());
return true;
} else {
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
// if (player.isSneaking()) {
// MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
// System.out.println(container.getParts());
// return true;
// } else {
// return false;
// }
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
if (container == null) {
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
public BlockState getStateForRendering(BlockState state, BlockPos pos, ExtendedBlockView world) {
MultipartContainerBlockEntity container = (MultipartContainerBlockEntity)world.getBlockEntity(pos);
if (container == null) {
return state;
}
Map<MultipartSlot, MultipartState> parts = container.getParts();
return new MultipartContainerBlockState(state, parts);
}

View File

@ -1,10 +1,13 @@
package net.shadowfacts.simplemultipart.multipart;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateFactory;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.loot.LootSupplier;
import net.minecraft.world.loot.LootTables;
@ -75,6 +78,9 @@ public abstract class Multipart {
return dropTableId;
}
/**
* Can be overridden, should only be called via {@link MultipartState#getDroppedStacks)}
*/
@Deprecated
public List<ItemStack> getDroppedStacks(MultipartState state, LootContext.Builder builder) {
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;
}
}

View File

@ -1,9 +1,11 @@
package net.shadowfacts.simplemultipart.multipart;
import com.google.common.collect.ImmutableMap;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.AbstractPropertyContainer;
import net.minecraft.state.property.Property;
import net.minecraft.util.Hand;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.loot.context.LootContext;
import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity;
@ -38,4 +40,9 @@ public class MultipartState extends AbstractPropertyContainer<Multipart, Multipa
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);
}
}

View File

@ -1,5 +1,7 @@
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.VoxelShapes;
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);
}
@Override
@Deprecated
public boolean activate(MultipartState state, MultipartSlot slot, MultipartContainerBlockEntity container, PlayerEntity player, Hand hand) {
System.out.println("part activated");
return true;
}
}