use of com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule in project minecolonies by ldtteam.
the class ToggleRecipeMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
module.toggle(recipeLocation);
}
use of com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule in project minecolonies by Minecolonies.
the class OpenCraftingGUIMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final ServerPlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
if (module.canLearnFurnaceRecipes()) {
NetworkHooks.openGui(player, new INamedContainerProvider() {
@NotNull
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Furnace Crafting GUI");
}
@NotNull
@Override
public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
return new ContainerCraftingFurnace(id, inv, building.getID(), module.getId());
}
}, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
} else {
NetworkHooks.openGui(player, new INamedContainerProvider() {
@NotNull
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Crafting GUI");
}
@NotNull
@Override
public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
return new ContainerCrafting(id, inv, module.canLearnLargeRecipes(), building.getID(), module.getId());
}
}, buffer -> new PacketBuffer(buffer.writeBoolean(module.canLearnLargeRecipes())).writeBlockPos(building.getID()).writeUtf(module.getId()));
}
}
use of com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule in project minecolonies by Minecolonies.
the class AddRemoveRecipeMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
if (remove) {
module.removeRecipe(storage.getToken());
SoundUtils.playSuccessSound(player, player.blockPosition());
} else {
final IToken<?> token = IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(storage);
if (!module.addRecipe(token)) {
SoundUtils.playErrorSound(player, player.blockPosition());
LanguageHandler.sendPlayerMessage(player, UNABLE_TO_ADD_RECIPE_MESSAGE, building.getCustomBuildingName());
} else {
SoundUtils.playSuccessSound(player, player.blockPosition());
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, playerMP -> AdvancementTriggers.BUILDING_ADD_RECIPE.trigger(playerMP, this.storage));
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.recipe.done");
}
}
building.markDirty();
}
use of com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule in project minecolonies by ldtteam.
the class OpenCraftingGUIMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final ServerPlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
if (module.canLearnFurnaceRecipes()) {
NetworkHooks.openGui(player, new INamedContainerProvider() {
@NotNull
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Furnace Crafting GUI");
}
@NotNull
@Override
public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
return new ContainerCraftingFurnace(id, inv, building.getID(), module.getId());
}
}, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
} else {
NetworkHooks.openGui(player, new INamedContainerProvider() {
@NotNull
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Crafting GUI");
}
@NotNull
@Override
public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
return new ContainerCrafting(id, inv, module.canLearnLargeRecipes(), building.getID(), module.getId());
}
}, buffer -> new PacketBuffer(buffer.writeBoolean(module.canLearnLargeRecipes())).writeBlockPos(building.getID()).writeUtf(module.getId()));
}
}
use of com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule in project minecolonies by ldtteam.
the class AddRemoveRecipeMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
if (remove) {
module.removeRecipe(storage.getToken());
SoundUtils.playSuccessSound(player, player.blockPosition());
} else {
final IToken<?> token = IColonyManager.getInstance().getRecipeManager().checkOrAddRecipe(storage);
if (!module.addRecipe(token)) {
SoundUtils.playErrorSound(player, player.blockPosition());
LanguageHandler.sendPlayerMessage(player, UNABLE_TO_ADD_RECIPE_MESSAGE, building.getCustomBuildingName());
} else {
SoundUtils.playSuccessSound(player, player.blockPosition());
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, playerMP -> AdvancementTriggers.BUILDING_ADD_RECIPE.trigger(playerMP, this.storage));
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.recipe.done");
}
}
building.markDirty();
}
Aggregations