Search in sources :

Example 1 with MultiArmorSettingsMessage

use of com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage in project Overloaded by CJ-MC-Mods.

the class CommonProxy method commonSetup.

public void commonSetup(FMLCommonSetupEvent event) {
    CapabilityHyperItem.register();
    CapabilityHyperEnergy.register();
    CapabilityHyperFluid.register();
    CapabilityGenericDataStorage.register();
    networkWrapper = newSimpleChannel(ResourceLocation.of("overloaded_network", '_'), () -> "1.0", v -> true, v -> true);
    int dis = 0;
    networkWrapper.registerMessage(dis++, LeftClickBlockMessage.class, LeftClickBlockMessage::toBytes, LeftClickBlockMessage::fromBytes, new PlayerMessageHandler<>(ItemMultiTool::leftClickOnBlockServer));
    networkWrapper.registerMessage(dis++, RightClickBlockMessage.class, RightClickBlockMessage::toBytes, RightClickBlockMessage::fromBytes, new PlayerMessageHandler<>(ModItems.multiTool::rightClickWithItem));
    networkWrapper.registerMessage(dis++, RayGunMessage.class, RayGunMessage::toBytes, RayGunMessage::fromBytes, new PlayerMessageHandler<>(ModItems.rayGun::handleMessage));
    networkWrapper.registerMessage(dis++, MultiArmorSettingsMessage.class, MultiArmorSettingsMessage::toBytes, MultiArmorSettingsMessage::fromBytes, new PlayerMessageHandler<>(ModItems.customHelmet::updateSettings));
    networkWrapper.registerMessage(dis++, RailGunFireMessage.class, RailGunFireMessage::toBytes, RailGunFireMessage::fromBytes, new PlayerMessageHandler<>(ModItems.railgun::handleFireMessage));
    networkWrapper.registerMessage(dis++, RailGunSettingsMessage.class, RailGunSettingsMessage::toBytes, RailGunSettingsMessage::fromBytes, new PlayerMessageHandler<>(ModItems.railgun::handleSettingsMessage));
    networkWrapper.registerMessage(dis++, KeyBindPressedMessage.class, KeyBindPressedMessage::toBytes, KeyBindPressedMessage::fromBytes, new KeyBindPressedHandler());
    networkWrapper.registerMessage(dis++, NoClipStatusMessage.class, NoClipStatusMessage::toBytes, NoClipStatusMessage::fromBytes, new NoClipUpdateHandler());
    networkWrapper.registerMessage(dis++, ContainerDataMessage.class, ContainerDataMessage::toBytes, ContainerDataMessage::fromBytes, new ContainerDataHandler());
    MinecraftForge.EVENT_BUS.register(new ArmorEventHandler());
}
Also used : Item(net.minecraft.item.Item) NoClipUpdateHandler(com.cjm721.overloaded.network.handler.NoClipUpdateHandler) KeyBindPressedHandler(com.cjm721.overloaded.network.handler.KeyBindPressedHandler) ContainerType(net.minecraft.inventory.container.ContainerType) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) ModBlocks(com.cjm721.overloaded.block.ModBlocks) FMLCommonSetupEvent(net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent) CapabilityGenericDataStorage(com.cjm721.overloaded.capabilities.CapabilityGenericDataStorage) ModContainers(com.cjm721.overloaded.network.container.ModContainers) Block(net.minecraft.block.Block) TileEntityType(net.minecraft.tileentity.TileEntityType) RegistryEvent(net.minecraftforge.event.RegistryEvent) CapabilityHyperFluid(com.cjm721.overloaded.capabilities.CapabilityHyperFluid) LinkedList(java.util.LinkedList) NetworkRegistry.newSimpleChannel(net.minecraftforge.fml.network.NetworkRegistry.newSimpleChannel) com.cjm721.overloaded.network.packets(com.cjm721.overloaded.network.packets) ModItems(com.cjm721.overloaded.item.ModItems) ModTiles(com.cjm721.overloaded.tile.ModTiles) CapabilityHyperItem(com.cjm721.overloaded.capabilities.CapabilityHyperItem) ModFluids(com.cjm721.overloaded.fluid.ModFluids) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) CapabilityHyperEnergy(com.cjm721.overloaded.capabilities.CapabilityHyperEnergy) ContainerDataHandler(com.cjm721.overloaded.network.handler.ContainerDataHandler) SimpleChannel(net.minecraftforge.fml.network.simple.SimpleChannel) PlayerMessageHandler(com.cjm721.overloaded.network.handler.PlayerMessageHandler) ResourceLocation(net.minecraft.util.ResourceLocation) ItemMultiTool(com.cjm721.overloaded.item.functional.ItemMultiTool) ArmorEventHandler(com.cjm721.overloaded.item.functional.armor.ArmorEventHandler) Fluid(net.minecraft.fluid.Fluid) NoClipUpdateHandler(com.cjm721.overloaded.network.handler.NoClipUpdateHandler) KeyBindPressedHandler(com.cjm721.overloaded.network.handler.KeyBindPressedHandler) ArmorEventHandler(com.cjm721.overloaded.item.functional.armor.ArmorEventHandler) ModItems(com.cjm721.overloaded.item.ModItems) ContainerDataHandler(com.cjm721.overloaded.network.handler.ContainerDataHandler)

Example 2 with MultiArmorSettingsMessage

use of com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage in project Overloaded by CJ-MC-Mods.

the class ItemMultiHelmet method updateSettings.

private void updateSettings(ItemStack itemStack, MultiArmorSettingsMessage message) {
    LazyOptional<IGenericDataStorage> opSettings = itemStack.getCapability(GENERIC_DATA_STORAGE);
    if (!opSettings.isPresent()) {
        Overloaded.logger.warn("MultiHelmet has no GenericData Capability? NBT: " + itemStack.getTag());
        return;
    }
    IGenericDataStorage settings = opSettings.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    settings.suggestUpdate();
    Map<String, Float> floats = settings.getFloatMap();
    floats.put(DataKeys.FLIGHT_SPEED, Floats.constrainToRange(message.flightSpeed, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxFlightSpeed));
    floats.put(DataKeys.GROUND_SPEED, Floats.constrainToRange(message.groundSpeed, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxGroundSpeed));
    Map<String, Boolean> booleans = settings.getBooleanMap();
    booleans.put(DataKeys.NOCLIP_FLIGHT_LOCK, message.noclipFlightLock);
    booleans.put(DataKeys.FLIGHT, message.flight);
    booleans.put(DataKeys.FEED, message.feed);
    booleans.put(DataKeys.HEAL, message.heal);
    booleans.put(DataKeys.REMOVE_HARMFUL, message.removeHarmful);
    booleans.put(DataKeys.GIVE_AIR, message.air);
    booleans.put(DataKeys.EXTINGUISH, message.extinguish);
    settings.suggestSave();
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage)

Example 3 with MultiArmorSettingsMessage

use of com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage in project Overloaded by CJ-MC-Mods.

the class MultiArmorGuiScreen method init.

@Override
protected void init() {
    super.init();
    LazyOptional<IGenericDataStorage> opData = getHelmetDataStorage(Minecraft.getInstance().player);
    if (!opData.isPresent()) {
        this.minecraft.setScreen(null);
        this.minecraft.player.displayClientMessage(new StringTextComponent("Multi-Helmet not equipped."), true);
        return;
    }
    IGenericDataStorage data = opData.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    Map<String, Float> floats = data.getFloatMap();
    Map<String, Boolean> booleans = data.getBooleanMap();
    addButton(new Button(this.width / 2, this.height / 4 + 100, 150, 20, new StringTextComponent("Save"), b -> {
        MultiArmorSettingsMessage message = new MultiArmorSettingsMessage((float) flightSpeed.getEffectiveValue(), (float) groundSpeed.getEffectiveValue(), noClipFlightLock.getBooleanState(), this.flightEnabled.getBooleanState(), this.feedEnabled.getBooleanState(), this.healEnabled.getBooleanState(), this.removeHarmfulEnabled.getBooleanState(), this.giveAirEnabled.getBooleanState(), this.extinguishEnabled.getBooleanState());
        Overloaded.proxy.networkWrapper.sendToServer(message);
        this.minecraft.setScreen(null);
    }));
    addButton(new Button(this.width / 2 - 150, this.height / 4 + 100, 150, 20, new StringTextComponent("Cancel"), b -> this.minecraft.setScreen(null)));
    float flightSpeedValue = floats.getOrDefault(DataKeys.FLIGHT_SPEED, Default.FLIGHT_SPEED);
    this.flightSpeed = addButton(new GenericSlider(this.width / 2 - 150, this.height / 4, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxFlightSpeed, flightSpeedValue, "Flight Speed:"));
    this.flightSpeedTextBox = addButton(new GuiPositiveFloatTextField(this.font, this.flightSpeed.x, this.flightSpeed.y, this.flightSpeed.getWidth(), this.flightSpeed.getHeight(), flightSpeedValue, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxFlightSpeed));
    this.flightSpeedTextBox.setVisible(false);
    this.flightEnabled = addButton(new ToggleButton(this.width / 2 - 150, this.height / 4 + 20, booleans.getOrDefault(DataKeys.FLIGHT, Default.FLIGHT), "Flight:"));
    float groundSpeedValue = floats.getOrDefault(DataKeys.GROUND_SPEED, Default.GROUND_SPEED);
    this.groundSpeed = addButton(new GenericSlider(this.width / 2, this.height / 4, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxGroundSpeed, groundSpeedValue, "Ground Speed:"));
    this.groundSpeedTextBox = addButton(new GuiPositiveFloatTextField(this.font, this.groundSpeed.x, this.groundSpeed.y, this.groundSpeed.getWidth(), this.groundSpeed.getHeight(), groundSpeedValue, 0, (float) OverloadedConfig.INSTANCE.multiArmorConfig.maxGroundSpeed));
    this.groundSpeedTextBox.setVisible(false);
    this.feedEnabled = addButton(new ToggleButton(this.width / 2, this.height / 4 + 20, booleans.getOrDefault(DataKeys.FEED, Default.FEED), "Feeder:"));
    this.healEnabled = addButton(new ToggleButton(this.width / 2 - 150, this.height / 4 + 40, booleans.getOrDefault(DataKeys.HEAL, Default.HEAL), "Healer:"));
    this.removeHarmfulEnabled = addButton(new ToggleButton(this.width / 2, this.height / 4 + 40, booleans.getOrDefault(DataKeys.REMOVE_HARMFUL, Default.REMOVE_HARMFUL), "Remove Harmful Potions:"));
    this.giveAirEnabled = addButton(new ToggleButton(this.width / 2 - 150, this.height / 4 + 60, booleans.getOrDefault(DataKeys.GIVE_AIR, Default.GIVE_AIR), "Airer:"));
    this.extinguishEnabled = addButton(new ToggleButton(this.width / 2, this.height / 4 + 60, booleans.getOrDefault(DataKeys.EXTINGUISH, Default.EXTINGUISH), "Extinguisher:"));
    this.noClipFlightLock = addButton(new ToggleButton(this.width / 2 - 75, this.height / 4 + 80, booleans.getOrDefault(DataKeys.NOCLIP_FLIGHT_LOCK, Default.NOCLIP_FLIGHT_LOCK), "No Clip Flight Lock:"));
}
Also used : Default(com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.Default) OverloadedConfig(com.cjm721.overloaded.config.OverloadedConfig) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) DataKeys(com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.DataKeys) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Overloaded(com.cjm721.overloaded.Overloaded) MultiArmorSettingsMessage(com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage) GenericSlider(com.cjm721.overloaded.client.gui.button.GenericSlider) ToggleButton(com.cjm721.overloaded.client.gui.button.ToggleButton) GENERIC_DATA_STORAGE(com.cjm721.overloaded.capabilities.CapabilityGenericDataStorage.GENERIC_DATA_STORAGE) Dist(net.minecraftforge.api.distmarker.Dist) LazyOptional(net.minecraftforge.common.util.LazyOptional) GuiPositiveFloatTextField(com.cjm721.overloaded.client.gui.button.GuiPositiveFloatTextField) ItemStack(net.minecraft.item.ItemStack) ItemMultiHelmet(com.cjm721.overloaded.item.functional.armor.ItemMultiHelmet) Screen(net.minecraft.client.gui.screen.Screen) Minecraft(net.minecraft.client.Minecraft) IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) Button(net.minecraft.client.gui.widget.button.Button) Map(java.util.Map) StringTextComponent(net.minecraft.util.text.StringTextComponent) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) ToggleButton(com.cjm721.overloaded.client.gui.button.ToggleButton) GuiPositiveFloatTextField(com.cjm721.overloaded.client.gui.button.GuiPositiveFloatTextField) IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) ToggleButton(com.cjm721.overloaded.client.gui.button.ToggleButton) Button(net.minecraft.client.gui.widget.button.Button) GenericSlider(com.cjm721.overloaded.client.gui.button.GenericSlider) StringTextComponent(net.minecraft.util.text.StringTextComponent) MultiArmorSettingsMessage(com.cjm721.overloaded.network.packets.MultiArmorSettingsMessage)

Aggregations

IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)2 Overloaded (com.cjm721.overloaded.Overloaded)1 ModBlocks (com.cjm721.overloaded.block.ModBlocks)1 CapabilityGenericDataStorage (com.cjm721.overloaded.capabilities.CapabilityGenericDataStorage)1 GENERIC_DATA_STORAGE (com.cjm721.overloaded.capabilities.CapabilityGenericDataStorage.GENERIC_DATA_STORAGE)1 CapabilityHyperEnergy (com.cjm721.overloaded.capabilities.CapabilityHyperEnergy)1 CapabilityHyperFluid (com.cjm721.overloaded.capabilities.CapabilityHyperFluid)1 CapabilityHyperItem (com.cjm721.overloaded.capabilities.CapabilityHyperItem)1 GenericSlider (com.cjm721.overloaded.client.gui.button.GenericSlider)1 GuiPositiveFloatTextField (com.cjm721.overloaded.client.gui.button.GuiPositiveFloatTextField)1 ToggleButton (com.cjm721.overloaded.client.gui.button.ToggleButton)1 OverloadedConfig (com.cjm721.overloaded.config.OverloadedConfig)1 ModFluids (com.cjm721.overloaded.fluid.ModFluids)1 ModItems (com.cjm721.overloaded.item.ModItems)1 ItemMultiTool (com.cjm721.overloaded.item.functional.ItemMultiTool)1 ArmorEventHandler (com.cjm721.overloaded.item.functional.armor.ArmorEventHandler)1 ItemMultiHelmet (com.cjm721.overloaded.item.functional.armor.ItemMultiHelmet)1 DataKeys (com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.DataKeys)1 Default (com.cjm721.overloaded.item.functional.armor.MultiArmorConstants.Default)1 ModContainers (com.cjm721.overloaded.network.container.ModContainers)1