use of net.minecraft.item.NameTagItem in project minecolonies by Minecolonies.
the class EntityCitizen method checkAndHandleImportantInteractions.
/**
* Called when a player tries to interact with a citizen.
*
* @param player which interacts with the citizen.
* @return If citizen should interact or not.
*/
@NotNull
@Override
public ActionResultType checkAndHandleImportantInteractions(final PlayerEntity player, @NotNull final Hand hand) {
final IColonyView iColonyView = IColonyManager.getInstance().getColonyView(citizenColonyHandler.getColonyId(), player.level.dimension());
if (iColonyView != null && !iColonyView.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
return ActionResultType.FAIL;
}
if (!ItemStackUtils.isEmpty(player.getItemInHand(hand)) && player.getItemInHand(hand).getItem() instanceof NameTagItem) {
return super.checkAndHandleImportantInteractions(player, hand);
}
final ActionResultType result = directPlayerInteraction(player, hand);
if (result != null) {
return result;
}
if (CompatibilityUtils.getWorldFromCitizen(this).isClientSide && iColonyView != null) {
if (player.isShiftKeyDown() && !isInvisible()) {
Network.getNetwork().sendToServer(new OpenInventoryMessage(iColonyView, this.getName().getString(), this.getId()));
} else {
final ICitizenDataView citizenDataView = getCitizenDataView();
if (citizenDataView != null && !isInvisible()) {
MineColonies.proxy.showCitizenWindow(citizenDataView);
}
}
}
return ActionResultType.SUCCESS;
}
use of net.minecraft.item.NameTagItem in project minecolonies by Minecolonies.
the class VisitorCitizen method checkAndHandleImportantInteractions.
/**
* Called when a player tries to interact with a citizen.
*
* @param player which interacts with the citizen.
* @return If citizen should interact or not.
*/
@Override
public ActionResultType checkAndHandleImportantInteractions(final PlayerEntity player, @NotNull final Hand hand) {
final IColonyView iColonyView = IColonyManager.getInstance().getColonyView(citizenColonyHandler.getColonyId(), player.level.dimension());
if (iColonyView != null && !iColonyView.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
return ActionResultType.FAIL;
}
if (!ItemStackUtils.isEmpty(player.getItemInHand(hand)) && player.getItemInHand(hand).getItem() instanceof NameTagItem) {
return super.checkAndHandleImportantInteractions(player, hand);
}
final ActionResultType result = directPlayerInteraction(player, hand);
if (result != null) {
return result;
}
if (CompatibilityUtils.getWorldFromCitizen(this).isClientSide) {
if (player.isShiftKeyDown()) {
Network.getNetwork().sendToServer(new OpenInventoryMessage(iColonyView, this.getName().getString(), this.getId()));
} else {
final ICitizenDataView citizenDataView = getCitizenDataView();
if (citizenDataView != null) {
MineColonies.proxy.showCitizenWindow(citizenDataView);
}
}
}
return ActionResultType.SUCCESS;
}
use of net.minecraft.item.NameTagItem in project ChocolateQuestRepoured by TeamChocoQuest.
the class AbstractEntityCQR method mobInteract.
@Override
protected ActionResultType mobInteract(PlayerEntity player, Hand hand) {
if (player.getItemInHand(hand).getItem() instanceof NameTagItem) {
return super.mobInteract(player, hand);
}
boolean flag = false;
if (player instanceof ServerPlayerEntity) {
ServerPlayerEntity spe = (ServerPlayerEntity) player;
if (!player.isCrouching()) {
if (player.isCreative() || this.getLeader() == player) {
if (!this.level.isClientSide) {
// player.openGui(CQRMain.INSTANCE, GuiHandler.CQR_ENTITY_GUI_ID, this.level, this.getId(), 0, 0);
NetworkHooks.openGui(spe, new INamedContainerProvider() {
@Override
public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
PacketBuffer buf = new PacketBuffer(Unpooled.buffer(32));
buf.writeInt(AbstractEntityCQR.this.getId());
return CQRContainerTypes.CQR_ENTITY_EDITOR.get().create(windowId, invPlayer, buf);
}
@Override
public ITextComponent getDisplayName() {
return AbstractEntityCQR.this.getDisplayName();
}
});
}
flag = true;
} else if (!this.getFaction().isEnemy(player) && this.hasTrades()) {
if (!this.level.isClientSide) {
// player.openGui(CQRMain.INSTANCE, GuiHandler.MERCHANT_GUI_ID, this.level, this.getId(), 0, 0);
NetworkHooks.openGui(spe, new INamedContainerProvider() {
@Override
public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
return CQRContainerTypes.MERCHANT.get().create(windowId, invPlayer);
}
@Override
public ITextComponent getDisplayName() {
return AbstractEntityCQR.this.getDisplayName();
}
});
}
flag = true;
}
} else if (player.isCreative() || (!this.getFaction().isEnemy(player) && this.hasTrades())) {
if (!this.level.isClientSide) {
// player.openGui(CQRMain.INSTANCE, GuiHandler.MERCHANT_GUI_ID, this.level, this.getId(), 0, 0);
NetworkHooks.openGui(spe, new INamedContainerProvider() {
@Override
public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
return CQRContainerTypes.MERCHANT.get().create(windowId, invPlayer);
}
@Override
public ITextComponent getDisplayName() {
return AbstractEntityCQR.this.getDisplayName();
}
});
}
flag = true;
}
}
if (flag && !this.getLookControl().isHasWanted() && !this.isPathFinding()) {
double x1 = player.position().x() - this.position().x();
double z1 = player.position().z() - this.position().z();
float yaw = (float) Math.toDegrees(Math.atan2(-x1, z1));
this.yBodyRot = yaw;
this.yHeadRot = yaw;
// Old 1.12.2
// this.renderYawOffset = yaw;
this.rotOffs = yaw;
}
return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
Aggregations