added player_collides_with_entity event

This commit is contained in:
gnembon committed 2020-09-17 21:29:35 -03:00
1 parent 755f3a7840
commit c0707fe544
6 files changed
+38 -6

No files matched your search

+6 -6
View File
@@ -496,13 +496,13 @@ structures and features. List of available options and names that you can use de
with minecraft 1.16.1 and below or 1.16.2 and above since in 1.16.2 Mojang has added JSON support for worldgen features
meaning that since 1.16.2 - they have official names that can be used by datapacks and scarpet
### Previous Structure Names, including variants (MC 1.16.1 and below)
### Previous Structure Names, including variants (as of MC 1.16.3)
* `'monument'`: Ocean Monument. Generates at fixed Y coordinate, surrounds itself with water.
* `'fortress'`: Nether Fortress. Altitude varies, but its bounded by the code.
* `'mansion'`: Woodland Mansion
* `'jungle_temple'`: Jungle Temple
* `'desert_temple'`: Desert Temple. Generates at fixed Y altitude.
* `'end_city'`: End City with Shulkers
* `'endcity'`: End City with Shulkers (in 1.16.1- as `'end_city`)
* `'igloo'`: Igloo
* `'shipwreck'`: Shipwreck
* `'shipwreck2'`: Shipwreck, beached
@@ -526,7 +526,7 @@ meaning that since 1.16.2 - they have official names that can be used by datapac
* `'bastion_remnant_treasure'`: Treasure room version of a piglin bastion (1.16)
* `'bastion_remnant_bridge'` : Bridge version of a piglin bastion (1.16)
### Feature Names (mc1.16.1-)
### Feature Names (as of mc1.16.1)
* `'oak'`
* `'oak_beehive'`: oak with a hive (1.15+).
@@ -590,13 +590,13 @@ meaning that since 1.16.2 - they have official names that can be used by datapac
* `'twisting_vines'` (1.16)
* `'basalt_pillar'` (1.16)
### Standard Structures (1.16.2+)
### Standard Structures (as of 1.16.2+)
`'bastion_remnant'`, `'buried_treasure'`, `'desert_pyramid'`, `'endcity'`, `'fortress'`, `'igloo'`,
`'jungle_pyramid'`, `'mansion'`, `'mineshaft'`, `'monument'`, `'nether_fossil'`, `'ocean_ruin'`,
`'pillager_outpost'`, `'ruined_portal'`, `'shipwreck'`, `'stronghold'`, `'swamp_hut'`, `'village'`
### Structure Variants (1.16.2+)
### Structure Variants (as of 1.16.2+)
`'bastion_remnant'`, `'buried_treasure'`, `'desert_pyramid'`, `'end_city'`, `'fortress'`, `'igloo'`,
`'jungle_pyramid'`, `'mansion'`, `'mineshaft'`, `'mineshaft_mesa'`, `'monument'`, `'nether_fossil'`,
@@ -605,7 +605,7 @@ meaning that since 1.16.2 - they have official names that can be used by datapac
`'ruined_portal_swamp'`, `'shipwreck'`, `'shipwreck_beached'`, `'stronghold'`, `'swamp_hut'`,
`'village_desert'`, `'village_plains'`, `'village_savanna'`, `'village_snovy'`, `'village_taiga'`
### World Generation Features (1.16.2+)
### World Generation Features (as of 1.16.2+)
`'acacia'`, `'bamboo'`, `'bamboo_light'`, `'bamboo_vegetation'`, `'basalt_blobs'`, `'basalt_pillar'`,
`'birch'`, `'birch_bees_0002'`, `'birch_bees_002'`, `'birch_bees_005'`, `'birch_other'`, `'birch_tall'`,
+1
View File
@@ -32,6 +32,7 @@ __on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) /
__on_player_interacts_with_block(player, hand, block, face, hitvec) //right click on a block resulted in activation of said block
__on_player_places_block(player, item_tuple, hand, block) // player have just placed the block.
__on_player_interacts_with_entity(player, entity, hand)
__on_player_collides_with_entity(player, entity)
__on_player_chooses_recipe(player, recipe, full_stack)
__on_player_switches_slot(player, from, to)
__on_player_swaps_hands(player)
@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
@@ -16,6 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_COLLIDES_WITH_ENTITY;
@Mixin(PlayerEntity.class)
public abstract class PlayerEntity_scarpetEventsMixin extends LivingEntity
@@ -42,4 +44,13 @@ public abstract class PlayerEntity_scarpetEventsMixin extends LivingEntity
PLAYER_DEALS_DAMAGE.onDamage(this, amount, source);
}
}
@Inject(method = "collideWithEntity", at = @At("HEAD"))
private void onEntityCollision(Entity entity, CallbackInfo ci)
{
if (PLAYER_COLLIDES_WITH_ENTITY.isNeeded() && !world.isClient)
{
PLAYER_COLLIDES_WITH_ENTITY.onEntityAction((ServerPlayerEntity)(Object)this, entity, null);
}
}
}
@@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(WorldChunk.class)
public class WorldChunk_fillUpdatesMixin
{
// todo onStateReplaced needs a bit more love since it removes be which is needed
@Redirect(method = "setBlockState", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;onBlockAdded(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V"
@@ -416,6 +416,7 @@ public class CarpetEventServer
), player::getCommandSource);
}
};
// todo PlayerInventory.insertStack... for definite item inventory pickup, when result protocol has be set
public static final Event PLAYER_ATTACKS_ENTITY = new Event("player_attacks_entity", 2, false)
{
@Override
@@ -578,6 +579,17 @@ public class CarpetEventServer
}, () -> source.getAttacker().getCommandSource());
}
};
public static final Event PLAYER_COLLIDES_WITH_ENTITY = new Event("player_collides_with_entity", 2, false)
{
@Override
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) {
handler.call( () -> Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> new EntityValue(entity))
), player::getCommandSource);
}
};
public static final Event PLAYER_DIES = new Event("player_dies", 1, false)
{
@Override
@@ -270,3 +270,10 @@ __on_player_swaps_hands(player) -> (
print('__on_player_swaps_hands(player)');
print(' Player '+player+' swaps hands.')
);
__on_player_collides_with_entity(player, entity) ->
(
print('');
print('__on_player_collides_with_entity(player, entity)');
print(' Player '+player+' collides with '+entity);
)