Giter Site home page Giter Site logo

visible_wielditem's Introduction

Visible Wielditem

Shows wielded items in-world.

Features

Modern alternative to wield3d:

  • Relies less on deprecated engine APIs, doesn't aim to support older MT versions
  • Supports colored items. Works well with epidermis.
  • Supports glow (for environmental lighting use a wielded light mod)
  • Indicates size of stacks
  • Provides a proper API for mods to use
  • Rotates the model instead of the texture

License

Code written by appgurueu and licensed under the MIT license.

The screenshot (screenshot.png) uses Hugues Ross' RPG16 texture pack, which is licensed under CC-BY-SA-4.0, and is therefore licensed under CC-BY-SA-4.0 as well.

Links

  • GitHub - sources, issue tracking, contributing
  • Discord - discussion, chatting
  • Minetest Forum - (more organized) discussion
  • ContentDB - releases (downloading from GitHub is recommended)

API

All within the visible_wielditem global variable.

get_attachment(modelname, itemname)

Returns a table with fields bonename, position (unit: metric/nodes), rotation (unit: degrees) and scale (number, unit: metric/nodes) based on model attachments and item tweaks.

model_attachments

Table. Keys are model media (file) names, values are tables with field bonename, position, rotation and scale. The special field default is used for default attachment settings based on character.b3d if no model attachments are specified for a player model or if the specified attachment settings are incomplete.

item_tweaks

Table of tweaks applied based on the item. Subtable entries have strings as keys and tweak tables with fields position, rotation and scale as values. positions are added up, rotations are properly composed, scale is multiplied.

types

Applies tweaks based on item type. Possible keys are unknown, node, tool and craftitem.

groups

Tweaks for a key are applied if the item has an item group with that name.

names

Tweaks for a single item, by full item name.

visible_wielditem's People

Contributors

appgurueu avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

visible_wielditem's Issues

bug: the server crashed after all players leaves.

WARNING[Server]: LuaEntitySAO::step() id=24 is attached to nonexistent parent. This is a bug.
ACTION[Main]: Server: Shutting down
terminate called after throwing an instance of 'LuaError'
  what():  Runtime error from mod 'visible_wielditem' in callback luaentity_Deactivate(): Invalid vector (expected table got nil).
stack traceback:
	[C]: in function 'add_entity'
	...mods/visible_wielditem/init.lua:6: in function 'create_entity'
	...mods/visible_wielditem/init.lua:132: in function <...g-2430d59f5-linux/bin/../mods/visible_wielditem/init.lua:131>

Why create the entity on deactivate?

visible_wielditem/init.lua

Lines 131 to 133 in 2a8051a

on_deactivate = function(self)
create_entity(self._player)
end,

Crash when entering first after world creation.

Only happens when entering first after world creation. It's ok after the word db created.

2023-07-03 15:10:21: ERROR[Server]: Server::ActiveObjectMgr::addActiveObjectRaw(): no free id available
2023-07-03 15:10:21: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'visible_wielditem' in callback luaentity_Deactivate(): ...u-5f498a2f5-linux/bin/../mods/visible_wielditem/init.lua:10: attempt to index a nil value
2023-07-03 15:10:21: ERROR[Main]: stack traceback:
2023-07-03 15:10:21: ERROR[Main]: 	[C]: in function '__index'
2023-07-03 15:10:21: ERROR[Main]: 	...u-5f498a2f5-linux/bin/../mods/visible_wielditem/init.lua:10: in function 'create_entity'
2023-07-03 15:10:21: ERROR[Main]: 	...u-5f498a2f5-linux/bin/../mods/visible_wielditem/init.lua:133: in function <...u-5f498a2f5-linux/bin/../mods/visible_wielditem/init.lua:132>

Open verbose mode, found it create huge luaentities:

...
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65530 name="visible_wielditem:visible_wielditem"
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65531 name="visible_wielditem:visible_wielditem"
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65532 name="visible_wielditem:visible_wielditem"
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65533 name="visible_wielditem:visible_wielditem"
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65534 name="visible_wielditem:visible_wielditem"
2023-07-03 14:32:58: VERBOSE[Server]: scriptapi_luaentity_add: id=65535 name="visible_wielditem:visible_wielditem"
...

Workaround:

local function create_entity(player)
	minetest.after(0, function()
		local pos = player and player:get_pos()
		if not pos then return end -- HACK deal with player object being invalidated before on_leaveplayer has been called
		minetest.add_entity(pos, entity_name):get_luaentity():_set_player(player)
	end)
end

modlib.minetest.register_on_wielditem_change(function(player, _, _, item)
	local entity = entities[player:get_player_name()]
	if entity == nil then return end   -- <-- add too
	if entity.object:get_pos() then
		entity:_set_item(item)
	else -- recreate entity if necessary
		create_entity(player)
	end
end)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.