Improve Code
All checks were successful
Twine/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-06-16 12:50:42 -04:00
parent 9e0fc49f6b
commit c41c42c5cc
3 changed files with 15 additions and 11 deletions

View File

@ -80,7 +80,7 @@ public class MixinBoatEntity implements BoatUtil {
setChestItem(newStack);
newMode.interact((ServerPlayerEntity) player);
newMode.triggerAdvancement((ServerPlayerEntity) player);
}
info.setReturnValue(ActionResult.SUCCESS);
} else if (player.isSneaking()) {

View File

@ -60,18 +60,18 @@ public class BoatChestMode {
private final BoatScreenHandlerFactory screenHandlerFactory;
private final Function<ItemStack, Text> screenHandlerNameFactory;
private final Consumer<ServerPlayerEntity> onInteract;
private final Consumer<ServerPlayerEntity> advancementTrigger;
private final int id;
private final SoundEvent openSound;
private final SoundEvent closeSound;
private BoatChestMode(Block block, boolean hasItems, boolean containsItems, int size, BoatScreenHandlerFactory screenHandlerFactory, Function<ItemStack, Text> screenHandlerNameFactory, Consumer<ServerPlayerEntity> onInteract, SoundEvent openSound, SoundEvent closeSound) {
private BoatChestMode(Block block, boolean hasItems, boolean containsItems, int size, BoatScreenHandlerFactory screenHandlerFactory, Function<ItemStack, Text> screenHandlerNameFactory, Consumer<ServerPlayerEntity> advancementTrigger, SoundEvent openSound, SoundEvent closeSound) {
this.screenHandlerFactory = screenHandlerFactory;
this.size = size;
this.screenHandlerNameFactory = screenHandlerNameFactory;
this.onInteract = onInteract;
this.advancementTrigger = advancementTrigger;
this.openSound = openSound;
this.closeSound = closeSound;
this.id = values.size();
@ -81,8 +81,8 @@ public class BoatChestMode {
values.add(this);
}
private BoatChestMode(Block block, BoatScreenHandlerFactory screenHandlerFactory, Function<ItemStack, Text> screenHandlerNameFactory, Consumer<ServerPlayerEntity> onInteract) {
this(block,false, false, 0, screenHandlerFactory, screenHandlerNameFactory, onInteract, null, null);
private BoatChestMode(Block block, BoatScreenHandlerFactory screenHandlerFactory, Function<ItemStack, Text> screenHandlerNameFactory, Consumer<ServerPlayerEntity> advancementTrigger) {
this(block,false, false, 0, screenHandlerFactory, screenHandlerNameFactory, advancementTrigger, null, null);
}
public int getSize() {
@ -97,9 +97,9 @@ public class BoatChestMode {
return screenHandlerNameFactory.apply(stack);
}
public void interact(ServerPlayerEntity player) {
if (onInteract != null) {
onInteract.accept(player);
public void triggerAdvancement(ServerPlayerEntity player) {
if (advancementTrigger != null) {
advancementTrigger.accept(player);
}
}

View File

@ -25,11 +25,15 @@ public class BoatInventory extends ItemInventory {
@Override
public void onOpen(PlayerEntity player) {
if (openSound != null) {
BoatUtil.playSound(entity, openSound);
}
}
@Override
public void onClose(PlayerEntity player) {
if (closeSound != null) {
BoatUtil.playSound(entity, closeSound);
}
}
}