Add hit side to Multipart::activate

This commit is contained in:
Shadowfacts 2018-12-29 18:45:36 -05:00
parent 7c465d01f4
commit f0e150664d
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 13 additions and 9 deletions

View File

@ -39,7 +39,7 @@ public abstract class AbstractContainerBlock extends Block implements BlockEntit
return false; return false;
} }
return hit.view.getState().activate(hit.view, player, hand); return hit.view.getState().activate(hit.view, hit.side, player, hand);
} }
@Override @Override

View File

@ -16,7 +16,6 @@ import net.shadowfacts.simplemultipart.SimpleMultipart;
import net.shadowfacts.simplemultipart.util.MultipartPlacementContext; import net.shadowfacts.simplemultipart.util.MultipartPlacementContext;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* The base class for a multipart object. * The base class for a multipart object.
@ -134,12 +133,13 @@ public abstract class Multipart {
* Can be overridden, should only be called via {@link MultipartState#activate} * Can be overridden, should only be called via {@link MultipartState#activate}
* *
* @param view The view of this part. * @param view The view of this part.
* @param side The side of the part that was hit.
* @param player The player that activated this part. * @param player The player that activated this part.
* @param hand The hand with which they performed the action. * @param hand The hand with which they performed the action.
* @return If the activation was successful. {@code true} will trigger the hand-swinging animation. * @return If the activation was successful. {@code true} will trigger the hand-swinging animation.
*/ */
@Deprecated @Deprecated
public boolean activate(MultipartView view, PlayerEntity player, Hand hand) { public boolean activate(MultipartView view, Direction side, PlayerEntity player, Hand hand) {
return false; return false;
} }

View File

@ -6,6 +6,7 @@ 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.Hand;
import net.minecraft.util.math.Direction;
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;
@ -49,11 +50,11 @@ public class MultipartState extends AbstractPropertyContainer<Multipart, Multipa
} }
/** /**
* @see Multipart#activate(MultipartView, PlayerEntity, Hand) * @see Multipart#activate(MultipartView, Direction, PlayerEntity, Hand)
*/ */
public boolean activate(MultipartView view, PlayerEntity player, Hand hand) { public boolean activate(MultipartView view, Direction side, PlayerEntity player, Hand hand) {
//noinspection deprecated //noinspection deprecated
return owner.activate(view, player, hand); return owner.activate(view, side, player, hand);
} }
} }

View File

@ -4,6 +4,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.StringTextComponent; import net.minecraft.text.StringTextComponent;
import net.minecraft.util.Hand; 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.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.MultipartContainer; import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -27,7 +28,7 @@ public class EntityTestPart extends Multipart implements MultipartEntityProvider
@Override @Override
@Deprecated @Deprecated
public boolean activate(MultipartView view, PlayerEntity player, Hand hand) { public boolean activate(MultipartView view, Direction side, PlayerEntity player, Hand hand) {
BlockPos pos = ((Entity)view.getEntity()).getPos(); BlockPos pos = ((Entity)view.getEntity()).getPos();
player.addChatMessage(new StringTextComponent("Clicked: " + pos), false); player.addChatMessage(new StringTextComponent("Clicked: " + pos), false);
return true; return true;

View File

@ -56,7 +56,7 @@ public class TestMultipart extends Multipart {
@Override @Override
@Deprecated @Deprecated
public boolean activate(MultipartView view, PlayerEntity player, Hand hand) { public boolean activate(MultipartView view, Direction side, PlayerEntity player, Hand hand) {
System.out.println(view.getContainer().getPart(Direction.UP)); System.out.println(view.getContainer().getPart(Direction.UP));
return true; return true;
} }

View File

@ -4,6 +4,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.StringTextComponent; import net.minecraft.text.StringTextComponent;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tickable; import net.minecraft.util.Tickable;
import net.minecraft.util.math.Direction;
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.MultipartContainer; import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -26,9 +27,10 @@ public class TickableEntityTestPart extends Multipart implements MultipartEntity
@Override @Override
@Deprecated @Deprecated
public boolean activate(MultipartView view, PlayerEntity player, Hand hand) { public boolean activate(MultipartView view, Direction side, PlayerEntity player, Hand hand) {
int timer = ((Entity)view.getEntity()).timer; int timer = ((Entity)view.getEntity()).timer;
player.addChatMessage(new StringTextComponent("Timer: " + timer), false); player.addChatMessage(new StringTextComponent("Timer: " + timer), false);
System.out.println("hit side: " + side);
return true; return true;
} }