You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my Mod i wanted to make an 'AdvisorEntity extends PassiveEntity implements Ownable', which should tell the Player what he can do with the Mod. The idea was, that the Player has to find this Advisor in the World and Hire him, so the Advisor need a Screen with a Button where he can be Hired
So I used the interactMob Method to open the Screen, where he should be Hireable through a Button:
@Override
protected ActionResult interactMob(PlayerEntity player, Hand hand) {
if (owner== null) { // owner is a 'private PlayerEntity', which should save the Player, which hired him
LOGGER.info("Advisor interaction");
MinecraftClient.getInstance().setScreen(new HireScreen(MinecraftClient.getInstance().currentScreen));
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
Because the Advisor doesnt need an Inventory I tried it with a normal Screen:
@Environment(EnvType.CLIENT)
public class HireScreen extends Screen {
private static final Identifier TEXTURE = new Identifier(MOD_ID, "textures/gui/container/hire.png");
private AdvisorEntity advisor; private final Screen parent;
public HireScreen(MinecraftClient client, Screen parent, AdvisorEntity advisor) {
super(Text.of("Advisor")); this.client = client;
this.advisor = advisor; this.parent = parent;
}
public ButtonWidget hireButton = ButtonWidget.builder(Text.of("Hire"), button -> {
System.out.println("You hired this Advisor!");
advisor.getsHiredBy(client.player);
})
.dimensions(width / 2 - 205, 20, 200, 20)
.tooltip(Tooltip.of(Text.literal("Tooltip of button1")))
.build();
@Override
protected void init() { addDrawableChild(hireButton); }
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
int imageWidth = 512; int imageHeight = 256;
int x = ((width - imageWidth) / 2); int y = ((height - imageHeight) / 2);
context.drawTexture(TEXTURE,x,y,0,0,imageWidth,imageHeight,imageWidth,imageHeight);
super.render(context, mouseX, mouseY, delta);
}
@Override
public void close() { client.setScreen(parent); }
}
The problem with this is, that the Game crashes with the error, that this Screen isnt correctly initialized and that i called setScreen on the worng Thread.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description
For my Mod i wanted to make an 'AdvisorEntity extends PassiveEntity implements Ownable', which should tell the Player what he can do with the Mod. The idea was, that the Player has to find this Advisor in the World and Hire him, so the Advisor need a Screen with a Button where he can be Hired
So I used the interactMob Method to open the Screen, where he should be Hireable through a Button:
Because the Advisor doesnt need an Inventory I tried it with a normal Screen:
The problem with this is, that the Game crashes with the error, that this Screen isnt correctly initialized and that i called setScreen on the worng Thread.
Beta Was this translation helpful? Give feedback.
All reactions