I am creating a Minecraft server using minestom which is a server building library, it had so no code and you have to make everything yourself. So im trying to make it so players can place water but it doesnt work sometimes. If im falling and place it then it gets placed client side but not server side sometimes, when its placed server side it says "placed block" in the chat.
globalEventHandler.addListener(PlayerUseItemOnBlockEvent.class, event -> {
final Player player = event.getPlayer();
if (event.getItemStack().getMaterial() != Material.WATER_BUCKET) {
return;
}
if (player.getInstance().getBlock(new Vec(event.getPosition().x(),
event.getPosition().y(),
event.getPosition().z())) == Block.IRON_BLOCK
&& event.getBlockFace().normalY() == 1) {
Point placedPos = event.getPosition();
placedPos.withX(placedPos.x() + event.getBlockFace().normalX());
placedPos.withY(placedPos.y() + event.getBlockFace().normalY());
placedPos.withZ(placedPos.z() + event.getBlockFace().normalZ());
player.getInstance().setBlock(placedPos, Block.WATER);
player.sendMessage("placed water");
}
player.getInventory().update();
});
Video - Ignore the platform disappearing, bug that I know how to fix but havent just yet but that also only happens when the water is placed server side too
https://youtu.be/njH58gbXPlE
I believe on the look vector is the next tick’s look vector for placing water, but the server hasn’t gotten this new look vector so it uses the old one
Related
I'm having troubles with Gamepad Support.
try // to create the Controllers
{
Controllers.create();
}
catch(Exception exep)
{}
int allControllers=0;
allControllers=Controllers.getControllerCount(); //finding out how much
//of it do we have
It says that I have 3 Controllers.
But the Gamepad is the Controller number 0.
Because when I poll n1 or n2 Controller -- game just crashes.
Does anyone knows hot to automatically pick working gamepad from this list and evade the Crash?
Looks like nobody else can do it. I've been working on it for good, and there is only one solution so far. Here it is:
for(int co=0;co<allControllers;co++)
{
gamepad = Controllers.getController(co);
GamePadName=gamepad.getName();
if(GamePadName.charAt(0)!='H' && GamePadName.charAt(0)!='U')
Keys=checkGamepad(Keys);
}
There are two controllers that can't be polled. On some PC's they are called "HID something", on other they are called "USB Keybord", "USB Mouse". Maybe on other PC's they will be called in other way. So we are not polling these Controllers, and game is not crashing... seems to be a bad solution, but I see no better.
Both versions work but I am not sure which one to use and why to use that version? Do you need to dispose the TextureAtlas if you unload the assets already?
Version 1: Load the pack file (TexturePacker file with positions data) along with the png.
gameSpriteSheet = new TextureAtlas(Gdx.files.internal(DATA_DIR_PATH + "GameSpritesPack.txt"));
assetManager.load(DATA_DIR_PATH + "GameSpritesPack.txt");
assetManager.load(DATA_DIR_PATH + "GameSpritesPack.png");
// Call only if assetmanager's update method returns true
headerRegion = getTexture("MainMenuHeader", gameSpriteSheet);
To unload:
if (assetManager.isLoaded(DATA_DIR_PATH + "GameSpritesPack.txt")) {
assetManager.unload(DATA_DIR_PATH + "GameSpritesPack.txt");
}
if (assetManager.isLoaded(DATA_DIR_PATH + "GameSpritesPack.png")) {
assetManager.unload(DATA_DIR_PATH + "GameSpritesPack.png");
}
if(gameSpriteSheet != null) {
gameSpriteSheet.dispose();
}
Version 2: Load only the pack file (TexturePacker file with positions data).
assetManager.load(DATA_DIR_PATH + "GameSpritesPack.txt");
// Call only if assetmanager's update method returns true
gameSpriteSheet = assetManager.get(DATA_DIR_PATH + "GameSpritesPack.txt", TextureAtlas.class);
headerRegion = getTexture("MainMenuHeader", gameSpriteSheet);
To unload:
if (assetManager.isLoaded(DATA_DIR_PATH + "GameSpritesPack.txt")) {
assetManager.unload(DATA_DIR_PATH + "GameSpritesPack.txt");
}
if(gameSpriteSheet != null) {
gameSpriteSheet.dispose();
}
Note: I have read Mario's post on AssetManager and other blogs on that but I don't seem to get why the both versions above work fine.
The AssetManager is for loading assets "in the background". The first version you listed just loads the atlas synchronously in the current thread. Its not actually using the AssetManager at all. This is fine and will work, the downside is that if your atlas is large (or you have a lot of them that you're doing this for), your app will "hang" for a moment while:
gameSpriteSheet = new TextureAtlas(Gdx.files.internal(DATA_DIR_PATH + "GameSpritesPack.txt"));
runs. You could delete the two assetManager lines in your first example, as they're not doing anything (useful) in this case.
The second version is a "correct" usage of the AssetManager. Basically you're asking the asset manager to run the code you used in the first version ( ... new TextureAtlas(...)) on a background thread. You must wait until that background thread completes (i.e., update() returns true). The idea is that you can do other stuff on the render thread in the foreground (i.e., animate pretty patterns on the screen to distract the user while you load up game assets) while periodically checking if the loading is complete.
In my j2me application i have to play a small sound file each times user click on an item. But the issues is when i play sound file multiple times like after 10-14 times it gives me
out of memory exception. Although i release the player each time i play the file but still it
gives out of memory exception : Here is the code snippet,
public void playSound(String soundFile) {
try{
if (player!=null) {
try {
player.deallocate(); //deallocate the unnecessary memory.
} catch (Exception ex) {
player=null;
System.gc();
}
}
player = Manager.createPlayer(getClass().getResourceAsStream(musicFolder + soundFile), "audio/mpeg");
// player = Manager.createPlayer(is, "audio/mpeg");
player.realize();
// get volume control for player and set volume to max
VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(100);
}
player.prefetch();
player.start();
isException=false;
} catch (Exception e) {
isException=true;
}
}
Can someone tell me what is going wrong?
3 things to keep in mind
If you are going to play the same sound several times, you might want to keep one Player prefetched and simply start it multiple times.
When you want to properly cleanup a player, you should call Player.close()
You may want to use a media event listener to close and/or restart a player independently of user input.
I think you should also call
player.close()
right after after
player.deallocate();
According to documentation "When deallocate returns, the Player is in the UNREALIZED or REALIZED state." but close goes further... "When the method returns, the Player is in the CLOSED state and can no longer be used."
I'm not sure why the de-allocation isn't working. I guess it either takes longer to de-allocated than to create a new one, or the de-allocation fails for some reason. Is there a player.stop() to match the player.start()?
Another thing to try (if nothing else, for good form :) is not to create new player unless you need to/should. I.e. move the
if(player!=null){
So it also covers
player = Manager.createPlayer(getClass().getResourceAsStream(musicFolder + soundFile), "audio/mpeg");
HTH!
I have a piece of code that outputs the player's total experience.
The issue is that the XP value it outputs doesn't change if the actual XP does.
For example, at level 50,000 the XP was 2,147,483,647. When level dropped to 4, the XP value stayed the same.
if (cmd.getName().equalsIgnoreCase("checkxp")) {
// If person is null, it's not a player!
if (person == null) {
sender.sendMessage("This command can only be used by a player, sorry!");
return false;
} else {
int curxp;
Player player = (Player) sender;
curxp = player.getTotalExperience();
sender.sendMessage("You currently have: " + curxp + " XP!");
return true;
}
}
How do I get this value to reset after it was ran so it re-checks the XP and updates the variable with the new amount?
If you don't update your Player object which looks like it's coming from sender it will hold the old values, so I check that sender is coming in with new data.
Looking at ExpSkills, it seems that playing with experience instead of levels is the way to go.
So use setTotalExperience() and getTotalExperience() for now.
Once you get everything working, then try and add support for levels.
Maybe there's a converter somewhere to convert levels to experience and experience to levels?
If not, here are the conversion charts.
I have to make 2 applets which will run in a TOMCAT like server and when I access the webpage[HTML page] at a client side, I have 2 cameras attached to that client PC and I want to show the videos from both cameras on the 2 web pages at the client side at the same time.
I have tried using JMF. Out put is
It doesnt work simultaneously for both cameras in most machines. It works for one camera capture at a time
It works on some machines, but you have to select the cameras everytime you open the web pages. Select camera 1 for the first applet and camera 2 for the second applet.
Is there a way with/without JMF that I can open 2 webpages on one client PC with 2 applets for the same running on a remote server and show the videos from each USBCAM on each page?
I have used this while working with JMF.
private void StartStreaming()
{
String mediaFile = "vfw:Micrsoft WDM Image Capture (Win32):0";
try
{
MediaLocator mlr = new MediaLocator(mediaFile);
_player = Manager.createRealizedPlayer(mlr);
if (_player.getVisualComponent() != null)
{
setSize(480, 320);
jpnVideoStream.add("South", _player.getVisualComponent());
}
}
catch (Exception e)
{
System.err.println("Got exception " + e);
}
_player.start();
}
This is what is present in my both applets. But as I said, most of the times, it starts one CAM and then gives the device is in use and cannot capture message.
Please suggest any solution.
The Problem is that you are trying to use the same webcam in both the applets.
Instead use :
String mediaFile = "webcam 1" in applet 1
String mediaFile = "webcam 2" in applet 2
Your first webcam is : vfw:Micrsoft WDM Image Capture (Win32):0
You can check your second webcam by :using JMStudio.
select File->Preferences->Capture Devices and then click on Detect Capture devices.
This can also be done using code but the above one is simpler. Still I m listing the code :
Vector list = CaptureDeviceManager.getDeviceList(null);
int i;
CaptureDeviceInfo tempDevice;
// List all the devices ...
if( list!=null) {
if( list.size() == 0)
{
System.out.println("the device list is zero : ");
System.exit(1);
}
System.out.println("The devices are : ");
for( i=0;i< list.size() ;i++ ) {
tempDevice = (CaptureDeviceInfo) list.elementAt(i);
System.out.println(tempDevice.getName());
}
}
NOTE : Try Running the code as admin if it dosent work.
If I recall correctly then in your code (JMF implementation), there should be list/array of devices (resources) java is trying to read the data (webcam stream) from. My guess would be, that you need to change code in such a way that if resource one is busy, then try to read from resource two. Essentially you are going over entire list of resources trying to read whatever is available to you.
Hope that helps.
It may work with JavaCV http://code.google.com/p/javacv/