Skip to content

Commit

Permalink
Merge pull request #305 from H0Imes/1.18.x
Browse files Browse the repository at this point in the history
Server Configuration and Gameplay Update
  • Loading branch information
0xE69 authored Oct 25, 2024
2 parents 81e3af0 + 50fc17a commit 70b8e34
Show file tree
Hide file tree
Showing 19 changed files with 508 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public class ServerConfig {
public final ForgeConfigSpec.EnumValue<HitMarker.Mode> hitMarkerMode;
public final ForgeConfigSpec.BooleanValue killSoundEnabled;

// ================================================================================
// Game-Settings Values
// ================================================================================

public final ForgeConfigSpec.BooleanValue overrideMinecraftInventory;
public final ForgeConfigSpec.BooleanValue overrideMinecraftHotbar;
public final ForgeConfigSpec.BooleanValue allowOffhandSwap;
public final ForgeConfigSpec.BooleanValue allowTogglePerspective;
public final ForgeConfigSpec.DoubleValue handcuffDamageChance;

// ================================================================================
// Burst-fire Values
// ================================================================================
Expand Down Expand Up @@ -157,6 +167,34 @@ private ServerConfig(ForgeConfigSpec.Builder builder) {
.translation("options.craftingdead.server.kill_sound_enabled")
.define("killSoundEnabled", true);

// Game-Settings configuration
builder
.comment("General Game-Settings")
.push("game-settings");
{
this.overrideMinecraftInventory = builder
.translation("options.craftingdead.server.override_minecraft_inventory")
.comment("If true overrides the default Minecraft inventory with the Crafting Dead inventory (Opens with \"E\")")
.define("overrideWithCraftingDeadInventory", false);
this.overrideMinecraftHotbar = builder
.translation("options.craftingdead.server.override_minecraft_hotbar")
.comment("If true overrides the default Minecraft hotbar")
.define("overrideMinecraftHotbar", false);
this.allowOffhandSwap = builder
.translation("options.craftingdead.server.allow_offhand_swap")
.comment("If true players are allowed to swap items to the offhand")
.define("allowOffhandSwap", true);
this.allowTogglePerspective = builder
.translation("options.craftingdead.server.allow_toggle_perspective")
.comment("If true players are allowed to toggle their perspective")
.define("allowTogglePerspective", true);
this.handcuffDamageChance = builder
.translation("options.craftingdead.server.handcuff_damage_chance")
.comment("The Chance that the player damages the handcuff")
.defineInRange("handcuffDamageChance", 0.4F, 0.1F, 1.0F);
}
builder.pop();

// Burst-fire configuration
builder
.comment("Some guns allow 'burstfire', where it can fire multiple shots at the same time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

package com.craftingdead.core.client;

import com.craftingdead.core.network.message.play.DamageHandcuffsMessage;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.Optional;
import java.util.Set;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import com.craftingdead.core.CraftingDead;
Expand Down Expand Up @@ -251,7 +259,7 @@ public ItemRenderDispatcher getItemRendererManager() {
* (contains both client and server code) don't access fields directly from {@link Minecraft} as
* it will cause class loading problems. To safely access {@link ClientPlayerEntity} in a
* multi-sided environment, use {@link #getPlayerExtension()}.
*
*
* @return {@link Minecraft}
*/
public Minecraft getMinecraft() {
Expand Down Expand Up @@ -500,9 +508,11 @@ public void handleClientTick(TickEvent.ClientTickEvent event) {

// Update tutorial
while (OPEN_EQUIPMENT_MENU.consumeClick()) {
NetworkChannel.PLAY.getSimpleChannel().sendToServer(new OpenEquipmentMenuMessage());
if (this.minecraft.getTutorial().instance instanceof ModTutorialStepInstance) {
((ModTutorialStepInstance) this.minecraft.getTutorial().instance).openEquipmentMenu();
if (!player.isHandcuffed()) {
NetworkChannel.PLAY.getSimpleChannel().sendToServer(new OpenEquipmentMenuMessage());
if (this.minecraft.getTutorial().instance instanceof ModTutorialStepInstance) {
((ModTutorialStepInstance) this.minecraft.getTutorial().instance).openEquipmentMenu();
}
}
}
TutorialSteps currentTutorialStep = this.minecraft.options.tutorialStep;
Expand Down Expand Up @@ -597,6 +607,14 @@ public void handleRenderGameOverlayPreLayer(RenderGameOverlayEvent.PreLayer even
|| overlay == ForgeIngameGui.AIR_LEVEL_ELEMENT
|| overlay == ForgeIngameGui.ARMOR_LEVEL_ELEMENT) {
event.setCanceled(player.isCombatModeEnabled());

if (overlay == ForgeIngameGui.HOTBAR_ELEMENT
&& ServerConfig.instance.overrideMinecraftHotbar.get()
&& !player.isCombatModeEnabled()) {
event.setCanceled(true);
this.renderHotbar(event.getMatrixStack(), event.getWindow());
}

} else if (overlay == ForgeIngameGui.CROSSHAIR_ELEMENT) {
var aiming = player.mainHandItem().getCapability(Scope.CAPABILITY)
.map(scope -> scope.isScoping(player))
Expand Down Expand Up @@ -635,7 +653,8 @@ public void handleRenderGameOverlayPre(RenderGameOverlayEvent.Pre event) {
event.getWindow().getGuiScaledWidth(), event.getWindow().getGuiScaledHeight(),
event.getPartialTicks());
}
default -> {}
default -> {
}
}
}

Expand Down Expand Up @@ -731,19 +750,47 @@ private void updateAdrenalineShader(float partialTicks) {

@SubscribeEvent
public void handleScreenOpen(ScreenOpenEvent event) {
// Prevents current screen being closed before new one opens.
if (this.minecraft == null || this.minecraft.player == null) {
return;
}

final var player = this.minecraft.player;
var playerExtension = PlayerExtension.get(player);

// Prevents current screen from being closed before new one opens.
if (this.minecraft.screen instanceof EquipmentScreen screen
&& event.getScreen() == null
&& screen.isTransitioning()) {
event.setCanceled(true);
}

// Prevents the player from opening the inventory if handcuffed
if (playerExtension != null && playerExtension.isHandcuffed()) {
if (event.getScreen() instanceof InventoryScreen && isSurvivalMode()) {
event.setCanceled(true);
return;
}
}

// Allows overriding the default inventory with the crafting dead inventory
if (event.getScreen() instanceof InventoryScreen && isSurvivalMode()
&& ServerConfig.instance.overrideMinecraftInventory.get()) {
event.setCanceled(true);
NetworkChannel.PLAY.getSimpleChannel().sendToServer(new OpenEquipmentMenuMessage());
}
}

@SubscribeEvent
public void handleRenderHand(RenderHandEvent event) {
final var player = this.getCameraPlayer();
if (player != null) {
event.setCanceled(player.isHandcuffed());
final var player = this.minecraft.player;
final var cameraPlayer = this.getCameraPlayer();

if (cameraPlayer != null) {
event.setCanceled(cameraPlayer.isHandcuffed());
}

if (player != null && player.hasEffect(ModMobEffects.PARACHUTE.get())) {
renderParachute(event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight());
}
}

Expand All @@ -755,6 +802,26 @@ public void handleClickInput(InputEvent.ClickInputEvent event) {
}
}

@SubscribeEvent
public void onMouseInput(InputEvent.MouseInputEvent event) {
if (this.minecraft.options.keyUse.matchesMouse(event.getButton())
&& event.getAction() == GLFW.GLFW_PRESS) {
if (this.minecraft.player != null && this.minecraft.screen == null) {
NetworkChannel.PLAY.getSimpleChannel().sendToServer(new DamageHandcuffsMessage());
}
}
}

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (this.minecraft.options.keyUse.matches(event.getKey(), event.getScanCode())
&& event.getAction() == GLFW.GLFW_PRESS) {
if (this.minecraft.player != null && this.minecraft.screen == null) {
NetworkChannel.PLAY.getSimpleChannel().sendToServer(new DamageHandcuffsMessage());
}
}
}

// ================================================================================
// Client-only helper methods
// ================================================================================
Expand Down Expand Up @@ -811,4 +878,73 @@ public static void renderArmWithClothing(PlayerRenderer renderer, PoseStack pose
OverlayTexture.NO_OVERLAY);
}
}

private void renderParachute(PoseStack poseStack, MultiBufferSource bufferSource,
int packedLight) {
poseStack.pushPose();
poseStack.translate(0.0D, -1.08D, -1.0D);
poseStack.mulPose(Vector3f.XP.rotationDegrees(180.0F));

var vertexConsumer = ItemRenderer.getArmorFoilBuffer(
bufferSource,
RenderType.armorCutoutNoCull(
new ResourceLocation(CraftingDead.ID, "textures/entity/parachute.png")
),
false,
false
);

EntityModelSet entityModelSet = Minecraft.getInstance().getEntityModels();
ModelPart parachuteModel = entityModelSet.bakeLayer(ModModelLayers.PARACHUTE);
parachuteModel.render(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
poseStack.popPose();
}

private void renderHotbar(PoseStack poseStack, Window window) {
var player = this.getPlayerExtension().orElse(null);

assert player != null;
if (player.isCombatModeEnabled()) {
return;
}

int screenWidth = window.getGuiScaledWidth();
int screenHeight = window.getGuiScaledHeight();

int xPos = (screenWidth / 2) - 91;
int yPos = screenHeight - 22;

this.minecraft.getProfiler().push("hotbar");
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0,
new ResourceLocation(CraftingDead.ID, "textures/gui/container/widgets.png"));
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();

this.minecraft.gui.blit(poseStack, xPos, yPos, 0, 0, 182, 22);

int selectedSlot = player.entity().getInventory().selected;
int selectedXPos = xPos + selectedSlot * 20 - 1;

this.minecraft.gui.blit(poseStack, selectedXPos, yPos - 1, 0, 22, 24, 24);

var itemRenderer = this.minecraft.getItemRenderer();

for (int i = 0; i < 9; ++i) {
int slotXPos = xPos + i * 20 + 3;
int slotYPos = yPos + 3;
ItemStack itemStack = player.entity().getInventory().getItem(i);

itemRenderer.renderAndDecorateItem(itemStack, slotXPos, slotYPos);
itemRenderer.renderGuiItemDecorations(this.minecraft.font, itemStack, slotXPos, slotYPos);
}

RenderSystem.disableBlend();
this.minecraft.getProfiler().pop();
}

private boolean isSurvivalMode() {
return this.minecraft.player != null && !this.minecraft.player.getAbilities().instabuild
&& !this.minecraft.player.isSpectator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;

public class ParachuteLayer<T extends LivingEntity, M extends EntityModel<T>>
extends RenderLayer<T, M> {
Expand All @@ -52,7 +53,7 @@ public ParachuteLayer(RenderLayerParent<T, M> entityRenderer, EntityModelSet ent
}

@Override
public void render(PoseStack poseStack, MultiBufferSource renderTypeBuffer, int packedLight,
public void render(@NotNull PoseStack poseStack, @NotNull MultiBufferSource renderTypeBuffer, int packedLight,
T livingEntity, float limbSwing, float limbSwingAmount, float partialTicks, float ageTicks,
float headYaw, float headPitch) {
if (livingEntity.hasEffect(ModMobEffects.PARACHUTE.get())) {
Expand Down Expand Up @@ -90,40 +91,46 @@ public static LayerDefinition createParachuteBodyLayer() {
PartPose.offsetAndRotation(-30.9324F, -50.5458F, 0.0F, 0.0F, 0.0F, -0.3491F));

anchor.addOrReplaceChild("cube_r3",
CubeListBuilder.create()
.texOffs(0, 0)
.addBox(-8.0F, -1.0F, -8.0F, 16.0F, 1.0F, 16.0F),
PartPose.offsetAndRotation(15.7048F, -54.626F, 0.0F, 0.0F, 0.0F, 0.1745F));

anchor.addOrReplaceChild("cube_r4",
CubeListBuilder.create()
.texOffs(0, 17)
.addBox(-8.0F, -1.0F, -8.0F, 16.0F, 1.0F, 16.0F),
PartPose.offsetAndRotation(30.9324F, -50.5458F, 0.0F, 0.0F, 0.0F, 0.3491F));

anchor.addOrReplaceChild("cube_r5",
CubeListBuilder.create()
.texOffs(0, 51)
.addBox(-0.4226F, -0.1075F, -0.1574F, 1.0F, 43.0F, 1.0F),
PartPose.offsetAndRotation(-37.0F, -48.5F, -7.0F, 0.1309F, 0.0F, -0.8727F));

anchor.addOrReplaceChild("cube_r4",
anchor.addOrReplaceChild("cube_r6",
CubeListBuilder.create()
.texOffs(4, 51)
.addBox(-0.4226F, -0.1075F, -0.8426F, 1.0F, 43.0F, 1.0F),
PartPose.offsetAndRotation(-37.0F, -48.5F, 7.0F, -0.1309F, 0.0F, -0.8727F));

anchor.addOrReplaceChild("cube_r5",
anchor.addOrReplaceChild("cube_r7",
CubeListBuilder.create()
.texOffs(8, 51)
.addBox(-0.5774F, -0.1075F, -0.8426F, 1.0F, 43.0F, 1.0F),
PartPose.offsetAndRotation(37.0F, -48.5F, 7.0F, -0.1309F, 0.0F, 0.8727F));

anchor.addOrReplaceChild("cube_r6",
CubeListBuilder.create()
.texOffs(0, 34)
.addBox(-8.0F, -1.0F, -8.0F, 16.0F, 1.0F, 16.0F),
PartPose.offsetAndRotation(15.7048F, -54.626F, 0.0F, 0.0F, 0.0F, 0.1745F));

anchor.addOrReplaceChild("cube_r7",
anchor.addOrReplaceChild("cube_r8",
CubeListBuilder.create()
.texOffs(12, 51)
.addBox(-0.5774F, -0.1075F, -0.1574F, 1.0F, 43.0F, 1.0F),
.texOffs(0, 51)
.addBox(-0.4226F, -0.1075F, -0.1574F, 1.0F, 43.0F, 1.0F),
PartPose.offsetAndRotation(37.0F, -48.5F, -7.0F, 0.1309F, 0.0F, 0.8727F));

anchor.addOrReplaceChild("cube_r8",
anchor.addOrReplaceChild("cube_r9",
CubeListBuilder.create()
.texOffs(48, 48)
.addBox(-8.0F, -1.0F, -8.0F, 16.0F, 1.0F, 16.0F),
PartPose.offsetAndRotation(30.9324F, -50.5458F, 0.0F, 0.0F, 0.0F, 0.3491F));
.texOffs(4, 51)
.addBox(-0.4226F, -0.1075F, -0.8426F, 1.0F, 43.0F, 1.0F),
PartPose.offsetAndRotation(37.0F, -48.5F, 7.0F, -0.1309F, 0.0F, 0.8727F));

return LayerDefinition.create(mesh, 128, 128);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Crafting Dead
* Copyright (C) 2022 NexusNode LTD
*
* This Non-Commercial Software License Agreement (the "Agreement") is made between
* you (the "Licensee") and NEXUSNODE (BRAD HUNTER). (the "Licensor").
* By installing or otherwise using Crafting Dead (the "Software"), you agree to be
* bound by the terms and conditions of this Agreement as may be revised from time
* to time at Licensor's sole discretion.
*
* If you do not agree to the terms and conditions of this Agreement do not download,
* copy, reproduce or otherwise use any of the source code available online at any time.
*
* https://github.com/nexusnode/crafting-dead/blob/1.18.x/LICENSE.txt
*
* https://craftingdead.net/terms.php
*/

package com.craftingdead.core.mixin;

import com.craftingdead.core.world.entity.extension.PlayerExtension;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemEntity.class)
public class ItemEntityMixin {

@Inject(method = "playerTouch", at = @At("HEAD"), cancellable = true)
public void onPlayerTouch(Player player, CallbackInfo ci) {
if (PlayerExtension.getOrThrow(player).isHandcuffed()) {
ci.cancel();
}
}
}
Loading

0 comments on commit 70b8e34

Please sign in to comment.