Monday, March 10, 2025

Self hosted Minecraft Bedrock Server in TrueNAS Scale

 We will host a docker container in TrueNAS Scale that runs the minecraft bedrock dedicated server. I apologize for the gap below; I wanted to preserve the original resolution of the pictures to display the text clearly.


First go to the TrueNAS Scale UI, typically located at http://truenas.local/ and click Apps then click "Discover Apps". 

Click "Custom App"


Enter the following in the fields.

For "Node Port", choose the port you want people to use when they connect to your server. For "Host Path", create a folder and choose that as the location to store your database files.

Leave the rest of the fields as default, and click the "Install" button at the bottom. With the above screenshotted configurations, we now have a Minecraft Bedrock server hosted at port 12345. If your truenas scale server's local IP is 192.168.0.5 for example, then you would use 192.168.0.5:12345 as your server address to connect to in Minecraft. You can use port forwarding to expose this to the internet with your public IP instead. If you want to get really fancy, you can buy a domain and have its A record point to your home IP address, that way you can have people connect through myserver.com:12345 instead.





Tuesday, October 26, 2021

How to capture the legendary beasts (Gold/Silver/Crystal)

Recently I started playing Crystal again (a favorite childhood game) and found that no correct guide existed for this, so I decided to write this.

Instructions:

  1. First you need to discover each legendary beast to reveal its location in the pokedex map
    1. Put a level 30 pokemon (such as the shiny Gyarados you might have caught) as your first pokemon.
    2. Fly to Ecruteak City and go down to Route 37.
    3. Use Max Repel and travel in the grass for 5 seconds. To maximize repel, you can change your character's direction without moving by tapping in a new direction. This will trigger wild pokemon discovery without using any repel steps.
    4. Next, go down to Route 36 and travel in the grass for another 5 seconds.
    5. Next, go down to Route 35 and travel in the grass for another 5 seconds.
    6. If no legendary pokemon are found, repeat steps 2 through 6. It's important that you use fly to fully reset their position.
  2. Once you have discovered Raikou/Suicune/Entei, you can take advantage of its movement patterns to find it faster. 
    1. First, prepare a level 55 Jynx with the moves Mean Look and Lovely Kiss as your first pokemon. You also need a high level pokemon with False Swipe, such as Scyther or Marowak.
    2. Fly back to Ecrutek City and go down to Route 37. Check your pokedex for the legendary pokemon's location, if it's in Route 37 go ahead and try to encounter it in the grass, otherwise go to step 3. Do not use repel otherwise you will not see it since Jynx is a higher level. After every 5 encounters, double check the pokedex location, as they will sometimes change location after a random number of battles.
    3. If the pokemon is not located in Route 37, check if it's located in Route 36, 35, 32, or 31, or 33. If the pokemon is in that direction, head towards that route using your bike. Do not fly or you'll reset their position. As you're heading towards the pokemon, be sure to check your pokedex map whenever you enter a new route.
    4. If they are no longer in Router 37/36/35/33/32/31, fly back to Ecrutek City to reset their position, then repeat steps 2 through 4.
    5. Once you encounter the legendary pokemon, use Lovely Kiss to put them to sleep, then use Mean Look. Switch to your False Swipe pokemon and get the enemy down to 1 health before switching back to Jynx. From there just ensure the pokemon is put to sleep whenever it wakes, otherwise throw pokeballs (such as Ultra ball) at it.
Explanations (optional information):
  • Flying is the only way to guarantee randomly resetting their position, entering a building/gatehouse doesn't guarantee this.
  • The legendary beasts follow a pattern. They have a higher chance of moving around a specific area but also a small chance of randomly resetting their position. We try to take advantage of this pattern, which is why we try to discover them quickly with a level 30 pokemon. If you just do the Route 38 trick of leaving and entering the gatehouse repeatedly it will take much longer to trigger their random position reset.
  • Jynx has Lovely Kiss because it has a 75% chance to sleep. She has Mean Look because, while it doesn't guarantee that they don't use Roar, it forces them to use a random move instead of fleeing when they wake. They will sometimes use Roar, sometimes use another move. You need Jynx at around level 55 because she needs to be faster than the beasts (especially Raikou) to get off the Lovely Kiss before the pokemon flees/roars.
  • Be ready to throw 30-50 ultra balls to catch each one. I highly recommend using a master ball on the last beast when you first discover it. Crystal makes this much easier by having Suicune be a regular encounter.

Wednesday, June 3, 2020

How can a fuse have a constant current rating regardless of the voltage of the circuit?

I came across a simple question recently that bugged me because Google didn't seem to have any answers. The best I could come across is people saying "resistance is near 0" and other wrong/irrelevant answers.

The answer is actually quite simple, it's because you can assume the power a fuse fails at is constant and that a fuse has a constant resistance. This is because a fuse is usually just a wire that will melt at a certain temperature. Below is the math to prove it.
  • ConstantPower = Voltage x Current
  • ConstantPower = (Resistance x Current) x Current (using Ohm's law)
  • ConstantPower = Resistance x Current^2
  • ConstantPower = ConstantResistance x Current^2
  • squareroot(ConstantPower/ConstantResistance) = Current
  • Constant = Current
As a reminder, this is true even if the fuse had a very high resistance, as long as the resistance is constant.

Friday, September 28, 2018

The simple purpose of C# 's async & await

Async/Await has one single goal, to write asynchronous callbacks in a way that looks like normal everyday easy to read code.

Here is an example of retrieving a string response asynchronously using callbacks,

using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace async_with_callbacks
{
class Program
{
static void Main(string[] args)
{
var httpClient = new HttpClient();
httpClient.GetStringAsync("http://google.com").ContinueWith(getStringTask =>
{
Console.WriteLine($"Google response: {getStringTask.Result}");
}).Wait();
Console.ReadLine();
}
}
}
Compare this with the awaited version,

using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace async_with_callbacks
{
class Program
{
static async Task Main(string[] args)
{
var httpClient = new HttpClient();
var getStringTaskResult = await httpClient.GetStringAsync("http://google.com");
Console.WriteLine($"Google response: {getStringTaskResult}");
Console.ReadLine();
}
}
}
While the callback version is reasonably simple, if you continue to add more and more asynchronous calls nested inside each callback, you reach a point called "callback hell" where the code is very hard to track. Let's try where we want to do 3 asynchronous calls, in order, to retrieve 3 website's content.

using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace async_with_multiple_callbacks
{
class Program
{
static void Main(string[] args)
{
var httpClient = new HttpClient();
httpClient.GetStringAsync("http://google.com").ContinueWith(getStringTaskGoogle =>
{
httpClient.GetStringAsync("http://yahoo.com").ContinueWith(getStringTaskYahoo =>
{
httpClient.GetStringAsync("http://bing.com").ContinueWith(getStringTaskBing =>
{
Console.WriteLine($"Google response: {getStringTaskGoogle.Result}");
Console.WriteLine($"Yahoo response: {getStringTaskYahoo.Result}");
Console.WriteLine($"Bing response: {getStringTaskBing.Result}");
}, TaskContinuationOptions.AttachedToParent);
}, TaskContinuationOptions.AttachedToParent);
}).Wait();
Console.ReadLine();
}
}
}
Now compare this to the awaited version,

using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace async_with_multiple_awaits
{
class Program
{
static async Task Main(string[] args)
{
var httpClient = new HttpClient();
var getStringTaskGoogleResult = await httpClient.GetStringAsync("http://google.com");
var getStringTaskYahooResult = await httpClient.GetStringAsync("http://yahoo.com");
var getStringTaskBingResult = await httpClient.GetStringAsync("http://bing.com");
Console.WriteLine($"Google response: {getStringTaskGoogleResult}");
Console.WriteLine($"Yahoo response: {getStringTaskYahooResult}");
Console.WriteLine($"Bing response: {getStringTaskBingResult}");
Console.ReadLine();
}
}
}
Very quickly we see why await can be so much easier for humans to read and understand; it looks like normal sequential code with no callbacks required. There isn't much more to it than this, and for the majority of developers this is all you need to know to get started.

Saturday, November 25, 2017

Government backed blockchain for currency

Bitcoin, and blockchains in general, threaten a government's ability to enact monetary policy. This creates a rift between bitcoin and governments that will likely prevent its universal adoption in its current form. However, we can take the advantages of a blockchain and modify them in a way to create a government sanctioned and controlled blockchain that is still, to a degree, distributed and takes advantage of the efficiency of a digital and secure currency.

A government sanctioned blockchain based currency would need to have the government act as a central authority. What this means is that the government entity would be able to modify the rules of the blockchain to allow it to control the money supply, invalidate/reverse transactions, assign addresses to users, and possibly other ways.

A central authority would have access to private keys that would assert its identity. Using these keys, it could sign certain actions (special transactions) that would be recorded in the blockchain. For example, a government signed transaction could generate coins with no proof of work required (unlike how it is traditionally created through mining blocks). This would allow the government to "print money". Additionally, transactions signed by this authority could remove coins from an address, effectively erasing coins. Also, it could use its authority to possibly grant each citizen an address(es) that it approves of, tying that citizen to an address for tax purposes or other reasons.

Another powerful tool would be the ability to reverse transactions. Addresses of known criminals, or those who owe money to the government, could have their coins forcefully removed/garnished from their addresses. An advantage of this is that if someone was ordered to pay an amount, they could simply send the agreed amount to the recipient's address, proving publicly they paid the debt owed. This would also allow the government the ability to track transactions, monitor fraud/laundering, etc.

Several technical challenges exist with this setup. A single private key owned by the government would be susceptible to a rogue employee effectively destroying the economy if he had access to the key (as it could print money and take money from anyone). Actions signed by the central authority would have to be distributed across multiple agencies, where all agencies would be required to sign the action/transaction before it would be acknowledged and added to the blockchain. Additionally, the government entity would need to be able to revoke and grant keys. Perhaps only require a majority signed for a transaction (to avoid the issue of one lost key preventing the government from being able operate the blockchain).

The government entity would need to provide a significant amount of the mining power for the blockchain. It would need to in order to prevent attacks by foreign governments, and to assert the reliability and secureness of its digital currency. To encourage mining by the public, the government entity could arbitrarily control both the transaction fees and reward for mining a block. Since the govnerment entity provides a large portion of the mining power for the blockchain, it could pick up slack when temporarily lowering block rewards and fees it would accept. The large amount of mining power provided would also allow the government to prioritize government signed transactions. As an alernative, the government entity could require that all blocks mined are securely sent to a government controlled service that inspects the node, signs it, which allows it to be added to the blockchain. This would prevent the 51% attack unless the attacker also had access to the private keys required to sign off in this manner.

An additional advantage of a central authority running a blockchain is that it would adapt very quickly to technical challenges. Things like controlling how often a block is created (to increase verification speed), how large a block is (to control the number of transactions verified in a given time span), control the block reward to control inflation, and even adopting new standards to modify how the blockchain fundamentally operates.

Blockchain based currency is still in its infancy stages and still needs time and heavy research to determine how to be utilized in a way beneficial to a government and its peoples, but the above are possible solutions to this problem that will allow a government to adopt a digital currency in a secure yet controlled manner.

Saturday, November 11, 2017

Bitcoin can't compete with fiat currency

Bitcoin's most important achievement is that it solves the double-spending problem. This allows, on a distributed and decentralized platform with no single authority, for digital credits to be spent in a verifiable and reliable manner. This means that if a transaction occurs using Bitcoin, you can verify that the credits spent only went to the address you specified.

The ability to avoid double-spending without a central authority means that trust is no longer needed to make transactions and assert identity. This allows you to do things such as sending digital credits to someone on the other side of the world without any concern over multiple banks communicating to transfer from one bank account to another and making sure it all occurs successfully. Additionally, blockchains inherently enforce identity by requiring a near impossible-to-break private key that only the owner of the credits has. This key allows the owner to publish transactions on behalf of the address they represent, asserting that they are who they say they are. This means that fraud cannot occur as long as your private key is secure.

While a powerful tool, blockchains suffers drawbacks that prevent it from being used as a mainstream currency. First and most importantly, is that it completely nullifies a country's ability to use monetary policy. This is dangerous as it prevents a government from working to prevent an economy from entering a recession or from overheating. To add to this, bitcoin is deflationary. The supply of Bitcoin is limited and by 2036, 99% of bitcoins that will ever exist will have already been mined. This results in hoarding (and less spending), real debt increasing over time, and a possible deflationary spiral.

Another vulnerability to bitcoin is that it is susceptible to a panic. All it takes is one time, and if bitcoin's price were to ever sharply dip (due to other reasons like adoption of other coins, government sanctions,  etc), it could create a panic where people start to sell en masse to avoid losses until the price went back up. This feedback loop would cause even more to sell until bitcoin were to eventually lose all value. If an economy relied on bitcoin for everyday business, this would cause an economic crisis.

Finally, Bitcoin has the problem of early adopters having a disproportionate amount of bitcoins. The original adopters were earning as much as 50 bitcoins every 10 minutes (worth roughly $360,000 now @ $7200/bitcoin). Large amounts of these bitcoins are tied up in addresses and have not been touched in years, causing uncertainty over the true money supply of bitcoins. The uncertainty of hundreds of thousands of bitcoins possibly flooding the market at any time could create a large disruption in the economy. The founder of bitcoin alone is estimated to have access to roughly 1 million bitcoins, or 5% of the entire bitcoin supply.

While bitcoin has value in being used as a currency, its inflexibility and inability to be controlled by governments will likely prevent it from ever reaching a scale that can compete with fiat currencies. In the same way that gold was banned from ownership and money moved to fiat in the 30s, so too will governments ban blockchains that threaten fiat currency and the government's ability to control the money supply. It is possible however, that governments will adopt a form of blockchain that uses a central authority (similar to IOTA for example) to both allow for a more efficient form of currency while still retaining control over it. Additionally, blockchains will continue to have value outside of monetary uses.

Saturday, February 20, 2016

PokeSynch - Original Pokemon Red/Blue/Yellow with multiplayer features

In my free time the past month I've been working on a modification to my GameBoy emulator specific to the original Pokemon games. The basic idea is to create a multiplayer feature for the games, which includes seeing other players walking around in the game, NPCs positions matching across games, and being able to trade also. These features are all enabled over the network, including online, and all run on the original Pokemon ROMs (this is not a new game that looks like the originals). Below is an example of what I have so far,

Two players in a game, where the NPCs are synchronized in their position.
Requesting a battle with the other player
Battle accepted, game on!
When the battle starts, a trainer battle is started.
The trainer is loaded up with your opponent's pokemon.
How it works is that, upon accepting a battle, a trainer battle is initiated on both player's games by changing a few memory values. When this occurs, the trainer's pokemon party is overridden with the remote player's pokemon party. At this point I now need to synchronize battle moves so that each player can make his move. 

For synchronizing remote players, unfortunately the game does not allow more than 16 sprites, so these remote players are "simulated" and drawn over the game's screen each frame. Additionally, if the player tries to walk into the remote player, the emulator will automatically override the memory value for collision detection to make the game think another unit is there.

For synchronizing NPCs, the NPCs are forced to not walk until the host player's NPC walks, then all clients have their NPCs scripted to follow the position of where the host player's NPC walked to. This is done by overriding memory in the game that tells it to keep walking and in which direction to walk.

I still have a ways to go, but at this point you can walk around and see other players and initiate battles.