use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by Minecolonies.
the class AbstractTeachingGuiHandler method getTargets.
@NotNull
@Override
public <I> List<Target<I>> getTargets(@NotNull final W gui, @NotNull final I ingredient, final boolean doStart) {
final List<Target<I>> targets = new ArrayList<>();
if (ingredient instanceof ItemStack) {
for (final Slot slot : gui.getMenu().slots) {
if (!slot.isActive() || !isSupportedSlot(slot))
continue;
final Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, 17, 17);
targets.add(new Target<I>() {
@NotNull
@Override
public Rectangle2d getArea() {
return bounds;
}
@Override
public void accept(@NotNull I ingredient) {
slot.set((ItemStack) ingredient);
updateServer(gui);
}
});
}
}
return targets;
}
use of net.minecraft.client.renderer.Rectangle2d in project Mekanism by mekanism.
the class GhostIngredientHandler method addVisibleAreas.
private static void addVisibleAreas(List<Rectangle2d> visible, Rectangle2d area, List<Rectangle2d> coveredArea) {
boolean intersected = false;
int x = area.getX();
int x2 = x + area.getWidth();
int y = area.getY();
int y2 = y + area.getHeight();
int size = coveredArea.size();
for (int i = 0; i < size; i++) {
Rectangle2d covered = coveredArea.get(i);
int cx = covered.getX();
int cx2 = cx + covered.getWidth();
int cy = covered.getY();
int cy2 = cy + covered.getHeight();
// Check if the covered area intersects the area we are checking against
if (x < cx2 && x2 > cx && y < cy2 && y2 > cy) {
intersected = true;
if (x < cx || y < cy || x2 > cx2 || y2 > cy2) {
// If the area is not fully covered then get the parts of it that are not covered
List<Rectangle2d> uncoveredArea = getVisibleArea(area, covered);
if (i + 1 == size) {
// If there are no more elements left, just add all the remaining visible parts
visible.addAll(uncoveredArea);
} else {
// Otherwise, grab the remaining unchecked elements from the covering layer
List<Rectangle2d> coveredAreas = coveredArea.subList(i + 1, size);
// And check each of our sub visible areas
for (Rectangle2d visibleArea : uncoveredArea) {
addVisibleAreas(visible, visibleArea, coveredAreas);
}
}
}
// If it is covered at all exit, we either added the uncovered parts or it is fully covered
break;
}
}
if (!intersected) {
// If we didn't intersect it at all, just add the area itself
visible.add(area);
}
}
use of net.minecraft.client.renderer.Rectangle2d in project SophisticatedBackpacks by P3pp3rF1y.
the class SBPPlugin method registerGuiHandlers.
@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGuiContainerHandler(BackpackScreen.class, new IGuiContainerHandler<BackpackScreen>() {
@Override
public List<Rectangle2d> getGuiExtraAreas(BackpackScreen gui) {
List<Rectangle2d> ret = new ArrayList<>();
gui.getUpgradeSlotsRectangle().ifPresent(ret::add);
ret.addAll(gui.getUpgradeSettingsControl().getTabRectangles());
gui.getSortButtonsRectangle().ifPresent(ret::add);
return ret;
}
});
registration.addGuiContainerHandler(SettingsScreen.class, new IGuiContainerHandler<SettingsScreen>() {
@Override
public List<Rectangle2d> getGuiExtraAreas(SettingsScreen gui) {
return new ArrayList<>(gui.getSettingsTabControl().getTabRectangles());
}
});
registration.addGhostIngredientHandler(BackpackScreen.class, new IGhostIngredientHandler<BackpackScreen>() {
@Override
public <I> List<Target<I>> getTargets(BackpackScreen screen, I i, boolean b) {
List<Target<I>> targets = new ArrayList<>();
if (!(i instanceof ItemStack)) {
return targets;
}
ItemStack ghostStack = (ItemStack) i;
BackpackContainer container = screen.getMenu();
container.getOpenContainer().ifPresent(c -> c.getSlots().forEach(s -> {
if (s instanceof IFilterSlot && s.mayPlace(ghostStack)) {
targets.add(new Target<I>() {
@Override
public Rectangle2d getArea() {
return new Rectangle2d(screen.getGuiLeft() + s.x, screen.getGuiTop() + s.y, 17, 17);
}
@Override
public void accept(I i) {
PacketHandler.sendToServer(new SetGhostSlotMessage(ghostStack, s.index));
}
});
}
}));
return targets;
}
@Override
public void onComplete() {
// noop
}
});
}
use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by ldtteam.
the class JobBasedRecipeCategory method calculateInfoBlocks.
@NotNull
private List<InfoBlock> calculateInfoBlocks(@NotNull T recipe) {
final List<ITextComponent> lines = generateInfoBlocks(recipe);
final Minecraft mc = Minecraft.getInstance();
final List<InfoBlock> result = new ArrayList<>();
int y = CITIZEN_Y;
for (final ITextComponent line : lines) {
final String text = line.getString();
final int width = (int) mc.font.getSplitter().stringWidth(text);
final int height = mc.font.lineHeight;
final int x = WIDTH - width;
String tip = null;
if (line instanceof TranslationTextComponent) {
final String key = ((TranslationTextComponent) line).getKey() + ".tip";
if (I18n.exists(key)) {
tip = (new TranslationTextComponent(key, ((TranslationTextComponent) line).getArgs())).getString();
}
}
result.add(new InfoBlock(text, tip, new Rectangle2d(x, y, width, height)));
y += height + 2;
}
return result;
}
use of net.minecraft.client.renderer.Rectangle2d in project minecolonies by ldtteam.
the class AbstractTeachingGuiHandler method getTargets.
@NotNull
@Override
public <I> List<Target<I>> getTargets(@NotNull final W gui, @NotNull final I ingredient, final boolean doStart) {
final List<Target<I>> targets = new ArrayList<>();
if (ingredient instanceof ItemStack) {
for (final Slot slot : gui.getMenu().slots) {
if (!slot.isActive() || !isSupportedSlot(slot))
continue;
final Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, 17, 17);
targets.add(new Target<I>() {
@NotNull
@Override
public Rectangle2d getArea() {
return bounds;
}
@Override
public void accept(@NotNull I ingredient) {
slot.set((ItemStack) ingredient);
updateServer(gui);
}
});
}
}
return targets;
}
Aggregations