Skip to content

Commit

Permalink
Mod is pretty much fully functional and builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta2Force committed Jun 11, 2020
1 parent b2c089d commit 0be3222
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 60 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -19,11 +20,23 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


implementation files('lib/vboxjws.jar')
shadow files('lib/vboxjws.jar')
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}

shadowJar {
configurations = [project.configurations.shadow]
baseName = 'shadow'
}

remapJar{
input = file("build/libs/shadow-${project.mod_version}-all.jar")
}

tasks.remapJar.dependsOn shadowJar

processResources {
inputs.property "version", project.version

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx1G
# Mod Properties
mod_version = 1.0.0
maven_group = deltatwoforce
archives_base_name = mc-vmcomputers
archives_base_name = mcvmcomputers

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
Expand Down
Binary file added lib/vboxjws.jar
Binary file not shown.
24 changes: 16 additions & 8 deletions src/main/java/mcvmcomputers/entities/EntityDeliveryChest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package mcvmcomputers.entities;

import mcvmcomputers.MCVmComputersMod;
import mcvmcomputers.item.ItemPackage;
import mcvmcomputers.tablet.TabletOrder.OrderStatus;
import mcvmcomputers.utils.MVCUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
Expand All @@ -22,6 +24,7 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;

public class EntityDeliveryChest extends Entity{
Expand Down Expand Up @@ -117,23 +120,28 @@ public boolean interact(PlayerEntity player, Hand hand) {

if(is != null) {
if(is.getItem().equals(Items.IRON_INGOT)) {
if(is.getCount() >= MCVmComputersMod.currentOrder.price) {
MCVmComputersMod.currentOrder.price = 0;
MCVmComputersMod.currentOrder.currentStatus = OrderStatus.PAYMENT_CHEST_RECEIVING;
is.decrement(MCVmComputersMod.currentOrder.price);
}else {
MCVmComputersMod.currentOrder.price -= is.getCount();
is.decrement(is.getCount());
}
MCVmComputersMod.currentOrder.price -= is.getCount();
is.decrement(is.getCount());
flag = true;
}
}

if(!flag) {
player.sendMessage(new LiteralText("You need to click the chest with ingots in your hand!").formatted(Formatting.RED));
}else {
if(MCVmComputersMod.currentOrder.price < 0) {
is.increment(MCVmComputersMod.currentOrder.price * -1);
MCVmComputersMod.currentOrder.currentStatus = OrderStatus.PAYMENT_CHEST_RECEIVING;
}
}

return flag;
}else if(MCVmComputersMod.currentOrder.currentStatus == OrderStatus.ORDER_CHEST_ARRIVED) {
player.world.spawnEntity(new ItemEntity(player.world, this.getX(), this.getY()+1.5, this.getZ(), ItemPackage.createPackage(Registry.ITEM.getId(MCVmComputersMod.currentOrder.items.get(0)))));
MCVmComputersMod.currentOrder.items.remove(0);
if(MCVmComputersMod.currentOrder.items.size() == 0) {
MCVmComputersMod.currentOrder.currentStatus = OrderStatus.ORDER_CHEST_RECEIVED;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ public int getRepeatDelay() {
}
}else {
if(entity.rocketSound != null) {
System.out.println("stopped");
MinecraftClient.getInstance().getSoundManager().stop(entity.rocketSound);
entity.rocketSound = null;
}
}
if(currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_ARRIVED) {
if(currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_ARRIVED || currentOrder.currentStatus == OrderStatus.ORDER_CHEST_ARRIVED) {
EntityDeliveryChest serverEntity = null;
for(ServerWorld sw : MinecraftClient.getInstance().getServer().getWorlds()) {
if(sw.getEntityById(entity.getEntityId()) != null) {
Expand Down Expand Up @@ -167,7 +166,7 @@ public int getRepeatDelay() {
entity.updatePosition(entity.getTargetX(), entity.getTargetY(), entity.getTargetZ());
serverEntity.updatePosition(entity.getTargetX(), entity.getTargetY(), entity.getTargetZ());
}
}else if(currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_RECEIVING) {
}else if(currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_RECEIVING || currentOrder.currentStatus == OrderStatus.ORDER_CHEST_RECEIVED) {
EntityDeliveryChest serverEntity = null;
for(ServerWorld sw : MinecraftClient.getInstance().getServer().getWorlds()) {
if(sw.getEntityById(entity.getEntityId()) != null) {
Expand All @@ -194,6 +193,7 @@ public int getRepeatDelay() {
entity.rocketSound = null;
}
}
MCVmComputersMod.currentOrder.entitySpawned = false;
entity.kill();
}
}
Expand All @@ -202,6 +202,8 @@ public int getRepeatDelay() {
private void smokeParticle(World w, Vec3d pos, int amount) {
for(int i = 0;i<amount;i++) {
if(amount == 3) {
w.addParticle(ParticleTypes.SMOKE, pos.x, pos.y, pos.z, (DeliveryChestModel.TEX_RANDOM.nextFloat()*0.5f)-.25f, DeliveryChestModel.TEX_RANDOM.nextFloat()*-.3F, (DeliveryChestModel.TEX_RANDOM.nextFloat()*.5f)-.25f);
}else if(amount==6){
w.addParticle(ParticleTypes.CLOUD, pos.x, pos.y, pos.z, (DeliveryChestModel.TEX_RANDOM.nextFloat()*0.5f)-.25f, DeliveryChestModel.TEX_RANDOM.nextFloat()*-.3F, (DeliveryChestModel.TEX_RANDOM.nextFloat()*.5f)-.25f);
}else {
w.addParticle(ParticleTypes.CLOUD, pos.x, pos.y, pos.z, (DeliveryChestModel.TEX_RANDOM.nextFloat()*2f)-1f, DeliveryChestModel.TEX_RANDOM.nextFloat()*.3F, (DeliveryChestModel.TEX_RANDOM.nextFloat()*2f)-1f);
Expand All @@ -211,6 +213,7 @@ private void smokeParticle(World w, Vec3d pos, int amount) {

private void doParticlesForFire(EntityDeliveryChest entity) {
smokeParticle(entity.world, entity.getPosVector(), 3);
smokeParticle(entity.world, entity.getPosVector(), 6);

Vec3d ground = new Vec3d(entity.getX(), entity.world.getTopY(Type.MOTION_BLOCKING, entity.getBlockPos().getX(), entity.getBlockPos().getZ()), entity.getZ());
double dist = ground.distanceTo(entity.getPosVector());
Expand Down Expand Up @@ -261,13 +264,24 @@ public void render(EntityDeliveryChest entity, float yaw, float tickDelta, Matri
matrices.translate(-15.63, -15.63, 6.22);
matrices.push();
matrices.scale(0.4f, 0.4f, 0.4f);
matrices.translate(0, -5, 0);
this.getFontRenderer().draw("Please insert", 6, 25, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
String s = ""+currentOrder.price;
this.getFontRenderer().draw(s, (39) - this.getFontRenderer().getStringWidth(s)/2, 33, new Color(0.4f,0.4f,1f,1f).getRGB(), false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("Iron Ingots", 10, 41, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("by clicking", 13, 50, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("this chest", 14, 59, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
if(currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_ARRIVED || currentOrder.currentStatus == OrderStatus.PAYMENT_CHEST_RECEIVING) {
matrices.translate(0, -5, 0);
this.getFontRenderer().draw("Please insert", 6, 25, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
String s = ""+currentOrder.price;
this.getFontRenderer().draw(s, (39) - this.getFontRenderer().getStringWidth(s)/2, 33, new Color(0.4f,0.4f,1f,1f).getRGB(), false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("Iron Ingots", 10, 41, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("by clicking", 13, 50, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("this chest", 14, 59, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
}else if(currentOrder.currentStatus == OrderStatus.ORDER_CHEST_ARRIVED || currentOrder.currentStatus == OrderStatus.ORDER_CHEST_RECEIVED) {
String s = currentOrder.items.size() + " items";
this.getFontRenderer().draw(s, (39) - this.getFontRenderer().getStringWidth(s)/2, 20, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,1f,0.2f).getRGB(), light);
matrices.push();
matrices.translate(0.5, 0, 0);
this.getFontRenderer().draw("in chest", 19, 30, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
matrices.pop();
this.getFontRenderer().draw("Collect by", 14, 44, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
this.getFontRenderer().draw("clicking", 21, 52, -1, false, matrices.peek().getModel(), vertexConsumers, false, new Color(0f,0f,0f,0f).getRGB(), light);
}
matrices.pop();
matrices.pop();
matrices.pop();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/mcvmcomputers/gui/GuiSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void run() {
} catch (InterruptedException e) {
e.printStackTrace();
}
status = COLOR_CHAR + "cFailed! Error will be printed to log.\n" + COLOR_CHAR + "cMaybe vboxwebsrv is already running? In that case,\n" + COLOR_CHAR + "cclose it using your Task Manager.\n\n"+"Settings menu in " + i + " seconds.";
status = COLOR_CHAR + "cFailed! Error will be printed to log.\n" + COLOR_CHAR + "cMaybe vboxwebsrv is already running? In that case,\n" + COLOR_CHAR + "cclose it using your Task Manager. If it's a VirtualBox" + COLOR_CHAR + "cproblem, start it and look at the error.\n\n"+"Settings menu in " + i + " seconds.";
}
onlyStatusMessage = false;
init();
Expand Down Expand Up @@ -177,6 +177,10 @@ public void render(int mouseX, int mouseY, float delta) {
this.font.draw(str, this.width/2 - this.font.getStringWidth(str)/2, this.height/2 - 60, -1);
String stri = "or your package manager. If you need to restart, do it and come back.";
this.font.draw(stri, this.width/2 - this.font.getStringWidth(stri)/2, this.height/2 - 50, -1);
String strin = "WARNING! This might cause VirtualBox to stop working, resulting in you having";
this.font.draw(strin, this.width/2 - this.font.getStringWidth(strin)/2, this.height/2 - 36, -1);
String string = "to reset your preferences. (If that happens, just google how to reset)";
this.font.draw(string, this.width/2 - this.font.getStringWidth(string)/2, this.height/2 - 26, -1);
this.font.draw("Maximum RAM used by VM:", this.width/2 - 160, this.height/2-10, -1);
this.font.draw("VM Video Memory:", this.width/2 + 10, this.height/2-10, -1);
String s = "Set these values in " + COLOR_CHAR + "lmegabytes." + COLOR_CHAR + "r 1 GB = 1024 MB. NaN = Not a Number.";
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/mcvmcomputers/item/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

public class ItemList {
public static final ItemGroup MOD_ITEM_GROUP_PARTS = FabricItemGroupBuilder.build(new Identifier("mcvmcomputers", "parts"), () -> new ItemStack(Blocks.WHITE_STAINED_GLASS));
public static final ItemGroup MOD_ITEM_GROUP_SCREENS = FabricItemGroupBuilder.build(new Identifier("mcvmcomputers", "screens"), () -> new ItemStack(Blocks.WHITE_STAINED_GLASS));
public static final ItemGroup MOD_ITEM_GROUP_PERIPHERALS = FabricItemGroupBuilder.build(new Identifier("mcvmcomputers", "peripherals"), () -> new ItemStack(Blocks.WHITE_STAINED_GLASS));
public static final ItemGroup MOD_ITEM_GROUP_OTHERS = FabricItemGroupBuilder.build(new Identifier("mcvmcomputers", "others"), () -> new ItemStack(Blocks.WHITE_STAINED_GLASS));
public static final OrderableItem PC_CASE_SIDEPANEL = new ItemPCCaseSidepanel(new Settings().group(MOD_ITEM_GROUP_PARTS));
public static final OrderableItem ITEM_MOTHERBOARD = new OrderableItem(new Settings().group(MOD_ITEM_GROUP_PARTS), 4);
public static final OrderableItem ITEM_MOTHERBOARD64 = new OrderableItem(new Settings().group(MOD_ITEM_GROUP_PARTS), 8);
public static final OrderableItem ITEM_FLATSCREEN = new ItemFlatScreen(new Settings().group(MOD_ITEM_GROUP_SCREENS));
public static final OrderableItem ITEM_CRTSCREEN = new ItemCRTScreen(new Settings().group(MOD_ITEM_GROUP_SCREENS));
public static final OrderableItem ITEM_FLATSCREEN = new ItemFlatScreen(new Settings().group(MOD_ITEM_GROUP_PERIPHERALS));
public static final OrderableItem ITEM_CRTSCREEN = new ItemCRTScreen(new Settings().group(MOD_ITEM_GROUP_PERIPHERALS));
public static final OrderableItem ITEM_NEW_HARDDRIVE = new ItemNewHarddrive(new Settings().group(MOD_ITEM_GROUP_PARTS));
public static final Item ITEM_HARDDRIVE = new ItemHarddrive(new Settings().rarity(Rarity.EPIC));
public static final OrderableItem ITEM_KEYBOARD = new ItemKeyboard(new Settings().group(MOD_ITEM_GROUP_PERIPHERALS));
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/mcvmcomputers/item/ItemPackage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package mcvmcomputers.item;

import java.util.List;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -44,6 +47,11 @@ public Text getName(ItemStack stack) {
return new LiteralText("Invalid package, dispose").formatted(Formatting.RED);
}

@Override
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
tooltip.add(new LiteralText("Open package using right click").formatted(Formatting.GRAY));
}

public static ItemStack createPackage(Identifier id) {
ItemStack is = new ItemStack(ItemList.ITEM_PACKAGE);
CompoundTag ct = is.getOrCreateTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ClientPlayNetworkMixin {
@Shadow
private MinecraftClient client;

@Inject(at = @At("TAIL"), method = "onEntitySpawn()V")
@Inject(at = @At("TAIL"), method = "onEntitySpawn")
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo ci) {
EntityType<?> entityType = packet.getEntityTypeId();
double d = packet.getX();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mcvmcomputers/mixins/GameloopMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class GameloopMixin {
@Shadow
private RenderTickCounter renderTickCounter;

@Inject(at = @At("HEAD"), method = "run()V")
@Inject(at = @At("HEAD"), method = "run")
private void run(CallbackInfo info) {
MinecraftClient mcc = MinecraftClient.getInstance();
mcc.openScreen(new GuiSetup());
Expand All @@ -90,7 +90,7 @@ private void run(CallbackInfo info) {
}
}

@Inject(at = @At("HEAD"), method = "render()V")
@Inject(at = @At("HEAD"), method = "render")
private void render(CallbackInfo info) {
if(lastDeltaTimeTime == 0) {
lastDeltaTimeTime = System.currentTimeMillis();
Expand Down Expand Up @@ -229,7 +229,7 @@ public void run() {
}
}

@Inject(at = @At("HEAD"), method = "close()V")
@Inject(at = @At("HEAD"), method = "close")
private void close(CallbackInfo info) {
System.out.println("Stopping VM Computers Mod...");
if(vmTextureNativeImage != null) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mcvmcomputers/mixins/HeldItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class HeldItemMixin {
@Shadow
private void renderArm(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, Arm arm) {}

@Inject(at = @At("HEAD"), method = "renderFirstPersonItem()V")
@Inject(at = @At("HEAD"), method = "renderFirstPersonItem")
private void renderItemHead(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if(!item.isEmpty()) {
if(item.getItem() instanceof ItemOrderingTablet) {
Expand All @@ -55,7 +55,7 @@ private void renderItemHead(AbstractClientPlayerEntity player, float tickDelta,
matrices.push();
}

@Inject(at = @At("TAIL"), method = "renderFirstPersonItem()V")
@Inject(at = @At("TAIL"), method = "renderFirstPersonItem")
private void renderItemTail(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
matrices.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mcvmcomputers/mixins/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Mixin(Keyboard.class)
public class KeyboardMixin {
@Inject(at = @At("HEAD"), method = "onKey()V")
@Inject(at = @At("HEAD"), method = "onKey")
public void onKey(long window, int key, int scancode, int i, int j, CallbackInfo ci) {
MinecraftClient mcc = MinecraftClient.getInstance();
if (window == mcc.getWindow().getHandle() && MCVmComputersMod.vmTurnedOn) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mcvmcomputers/mixins/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class MouseMixin {
@Shadow
private boolean rightButtonClicked;

@Inject(at = @At("TAIL"), method = "onMouseScroll()V")
@Inject(at = @At("TAIL"), method = "onMouseScroll")
private void onMouseScroll(CallbackInfo ci) {
MCVmComputersMod.mouseDeltaScroll = (int) this.eventDeltaWheel;
}

@Inject(at = @At("TAIL"), method = "onMouseButton()V")
@Inject(at = @At("TAIL"), method = "onMouseButton")
private void onMouseButton(CallbackInfo ci) {
MCVmComputersMod.leftMouseButton = leftButtonClicked;
MCVmComputersMod.middleMouseButton = middleButtonClicked;
Expand Down
Loading

0 comments on commit 0be3222

Please sign in to comment.