Search in sources :

Example 1 with AbstractCraftingBuildingModule

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);
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule)

Example 2 with AbstractCraftingBuildingModule

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()));
    }
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NotNull(org.jetbrains.annotations.NotNull) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 3 with AbstractCraftingBuildingModule

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();
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with AbstractCraftingBuildingModule

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()));
    }
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NotNull(org.jetbrains.annotations.NotNull) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 5 with AbstractCraftingBuildingModule

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();
}
Also used : AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AbstractCraftingBuildingModule (com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 ContainerCrafting (com.minecolonies.api.inventory.container.ContainerCrafting)2 ContainerCraftingFurnace (com.minecolonies.api.inventory.container.ContainerCraftingFurnace)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Container (net.minecraft.inventory.container.Container)2 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 NotNull (org.jetbrains.annotations.NotNull)2