use of com.cjm721.overloaded.network.packets.RailGunSettingsMessage in project Overloaded by CJ-MC-Mods.
the class ItemRailGun method onMouseEvent.
@SubscribeEvent
public void onMouseEvent(InputEvent.MouseScrollEvent event) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (event.getScrollDelta() != 0 && player != null && player.isShiftKeyDown()) {
ItemStack stack = player.getMainHandItem();
if (player.isShiftKeyDown() && !stack.isEmpty() && stack.getItem() == this) {
int powerDelta = Long.signum(Math.round(event.getScrollDelta())) * OverloadedConfig.INSTANCE.railGun.stepEnergy;
if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), ((ClientProxy) Overloaded.proxy).railGun100x.getKey().getValue())) {
powerDelta *= 100;
}
Overloaded.proxy.networkWrapper.sendToServer(new RailGunSettingsMessage(powerDelta));
event.setCanceled(true);
}
}
}
use of com.cjm721.overloaded.network.packets.RailGunSettingsMessage 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());
}
use of com.cjm721.overloaded.network.packets.RailGunSettingsMessage in project Overloaded by CJ-MC-Mods.
the class ItemRailGun method handleSettingsMessage.
public void handleSettingsMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunSettingsMessage message) {
ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
if (itemStack.getItem() != this) {
return;
}
LazyOptional<IGenericDataStorage> opCap = itemStack.getCapability(GENERIC_DATA_STORAGE);
if (!opCap.isPresent()) {
Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
return;
}
IGenericDataStorage cap = opCap.orElseThrow(() -> new RuntimeException("Impossible Condition"));
Map<String, Integer> integerMap = cap.getIntegerMap();
int power = integerMap.getOrDefault(RAILGUN_POWER_KEY, 0) + message.powerDelta;
power = Ints.constrainToRange(power, OverloadedConfig.INSTANCE.railGun.minEnergy, OverloadedConfig.INSTANCE.railGun.maxEnergy);
integerMap.put(RAILGUN_POWER_KEY, power);
cap.suggestSave();
player.displayClientMessage(new StringTextComponent("Power usage set to: " + NumberFormat.getInstance().format(power)), true);
}
Aggregations