use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.
the class OpenIFFScreenPacket method openIFFScreen.
@Environment(EnvType.CLIENT)
private static void openIFFScreen(int id, CompoundTag tag, PlayerEntity player) {
Entity entity = player.world.getEntityById(id);
if (!(entity instanceof HasIFF)) {
return;
}
ListTag list = tag.getList("IFFs", 10);
List<IFF> iffs = list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
MinecraftClient.getInstance().openScreen(new IFFScreen(entity, iffs));
}
use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.
the class SyncIFFPacket method applyIFFServer.
private static void applyIFFServer(int id, CompoundTag tag, PlayerEntity player) {
Entity entity = player.world.getEntityById(id);
if (!(entity instanceof HasIFF)) {
return;
}
if (entity instanceof TameableEntity && !player.getUuid().equals(((TameableEntity) entity).getOwnerUuid())) {
return;
}
ListTag list = tag.getList("IFFs", 10);
List<IFF> iffs = list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
((HasIFF) entity).setIFFs(iffs);
}
use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.
the class IFFScreen method renderAllMobs.
public void renderAllMobs(MatrixStack matrices, int mouseX, int mouseY) {
int count = -1;
int x = width / 2 - width / 4 + layerSize;
int y = scrollAmount;
for (IFF iff : iffs) {
count++;
if (y++ < 0)
continue;
if (height < y * layerSize)
break;
iff.getIFFType().render(matrices, x, y * layerSize, -mouseX + x, -mouseY + y * layerSize);
if (count == selectLine)
fill(matrices, width / 4, y * layerSize, width - width / 4, (y - 1) * layerSize, 0x40FFFFFF);
int color;
switch(iff.getIFFTag()) {
case FRIEND:
color = 0x40FF40;
break;
case ENEMY:
color = 0xFF4040;
break;
default:
color = 0xFFFF40;
}
drawStringWithShadow(matrices, textRenderer, iff.getIFFTag().getName(), x + layerSize * 2, y * layerSize - layerSize / 2, color);
}
}
use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.
the class IFFScreen method mouseClicked.
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
Optional<Float> optional = scrollBar.click(mouseX, mouseY);
if (optional.isPresent()) {
scrollAmount = (int) ((-iffs.size() + 2) * optional.get());
return false;
}
if (width / 4F < mouseX && mouseX < width - width / 4F) {
this.selectLine = -scrollAmount + (int) (mouseY / layerSize);
if (this.selectLine < 0 || iffs.size() <= selectLine) {
return false;
}
if (Util.getMeasuringTimeMs() - this.time < 250L) {
IFF iff = iffs.get(selectLine);
IFFTag tag = iff.getIFFTag();
switch(tag) {
case FRIEND:
iff.setTag(IFFTag.ENEMY);
break;
case ENEMY:
iff.setTag(IFFTag.UNKNOWN);
break;
default:
iff.setTag(IFFTag.FRIEND);
}
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
return true;
}
}
this.time = Util.getMeasuringTimeMs();
return super.mouseClicked(mouseX, mouseY, button);
}
Aggregations