Fix blocks being placed in adventure mode. Closes #6085

Add early error for setting invalid world directory. Closes #6084
Fix PlayerTickEvent not firing when dead, even if player isn't removed from world yet. Closes #6074
Fix PlayerDestroyItemEvent not firing for some cases. Closes #6067
This commit is contained in:
LexManos 2019-08-28 10:45:08 -07:00
parent 1ab40e0b3f
commit 7deb479676
5 changed files with 57 additions and 46 deletions

View File

@ -375,15 +375,19 @@
this.func_184602_cy();
}
@@ -2532,6 +2580,7 @@
@@ -2532,7 +2580,11 @@
public void func_184597_cx() {
if (!this.field_184627_bm.func_190926_b()) {
+ if (!net.minecraftforge.event.ForgeEventFactory.onUseItemStop(this, field_184627_bm, this.func_184605_cv()))
+ if (!net.minecraftforge.event.ForgeEventFactory.onUseItemStop(this, field_184627_bm, this.func_184605_cv())) {
+ ItemStack copy = this instanceof PlayerEntity ? field_184627_bm.func_77946_l() : null;
this.field_184627_bm.func_77974_b(this.field_70170_p, this, this.func_184605_cv());
+ if (copy != null && field_184627_bm.func_190926_b()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity)this, copy, func_184600_cs());
+ }
if (this.field_184627_bm.func_222122_m()) {
this.func_184608_ct();
@@ -2687,16 +2736,16 @@
}
@@ -2687,16 +2739,16 @@
private boolean func_213359_p() {
return this.func_213374_dv().map((p_213347_1_) -> {
@ -404,7 +408,7 @@
BlockPos blockpos = p_213368_1_.func_177984_a();
return new Vec3d((double)blockpos.func_177958_n() + 0.5D, (double)blockpos.func_177956_o() + 0.1D, (double)blockpos.func_177952_p() + 0.5D);
});
@@ -2711,8 +2760,13 @@
@@ -2711,8 +2763,13 @@
@Nullable
@OnlyIn(Dist.CLIENT)
public Direction func_213376_dz() {
@ -419,7 +423,7 @@
}
public boolean func_70094_T() {
@@ -2779,4 +2833,58 @@
@@ -2779,4 +2836,58 @@
public void func_213334_d(Hand p_213334_1_) {
this.func_213361_c(p_213334_1_ == Hand.MAIN_HAND ? EquipmentSlotType.MAINHAND : EquipmentSlotType.OFFHAND);
}

View File

@ -173,24 +173,21 @@
this.func_190777_m(true);
}
@@ -820,13 +867,15 @@
@@ -820,11 +867,12 @@
}
protected void func_184590_k(float p_184590_1_) {
- if (p_184590_1_ >= 3.0F && this.field_184627_bm.func_77973_b() == Items.field_185159_cQ) {
+ if (p_184590_1_ >= 3.0F && this.field_184627_bm.isShield(this)) {
+ ItemStack copy = this.field_184627_bm.func_77946_l();
int i = 1 + MathHelper.func_76141_d(p_184590_1_);
Hand hand = this.func_184600_cs();
this.field_184627_bm.func_222118_a(i, this, (p_213833_1_) -> {
p_213833_1_.func_213334_d(hand);
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, this.field_184627_bm, hand);
});
if (this.field_184627_bm.func_190926_b()) {
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, copy, hand);
if (hand == Hand.MAIN_HAND) {
this.func_184201_a(EquipmentSlotType.MAINHAND, ItemStack.field_190927_a);
} else {
@@ -842,11 +891,14 @@
@@ -842,11 +890,14 @@
protected void func_70665_d(DamageSource p_70665_1_, float p_70665_2_) {
if (!this.func_180431_b(p_70665_1_)) {
@ -205,7 +202,7 @@
float f1 = f - p_70665_2_;
if (f1 > 0.0F && f1 < 3.4028235E37F) {
this.func_195067_a(Stats.field_212738_J, Math.round(f1 * 10.0F));
@@ -901,6 +953,8 @@
@@ -901,6 +952,8 @@
return ActionResultType.PASS;
} else {
@ -214,7 +211,7 @@
ItemStack itemstack = this.func_184586_b(p_190775_2_);
ItemStack itemstack1 = itemstack.func_190926_b() ? ItemStack.field_190927_a : itemstack.func_77946_l();
if (p_190775_1_.func_184230_a(this, p_190775_2_)) {
@@ -908,6 +962,9 @@
@@ -908,6 +961,9 @@
itemstack.func_190920_e(itemstack1.func_190916_E());
}
@ -224,7 +221,7 @@
return ActionResultType.SUCCESS;
} else {
if (!itemstack.func_190926_b() && p_190775_1_ instanceof LivingEntity) {
@@ -917,6 +974,7 @@
@@ -917,6 +973,7 @@
if (itemstack.func_111282_a(this, (LivingEntity)p_190775_1_, p_190775_2_)) {
if (itemstack.func_190926_b() && !this.field_71075_bZ.field_75098_d) {
@ -232,7 +229,7 @@
this.func_184611_a(p_190775_2_, ItemStack.field_190927_a);
}
@@ -943,6 +1001,7 @@
@@ -943,6 +1000,7 @@
}
public void func_71059_n(Entity p_71059_1_) {
@ -240,7 +237,7 @@
if (p_71059_1_.func_70075_an()) {
if (!p_71059_1_.func_85031_j(this)) {
float f = (float)this.func_110148_a(SharedMonsterAttributes.field_111264_e).func_111126_e();
@@ -970,8 +1029,10 @@
@@ -970,8 +1028,10 @@
boolean flag2 = flag && this.field_70143_R > 0.0F && !this.field_70122_E && !this.func_70617_f_() && !this.func_70090_H() && !this.func_70644_a(Effects.field_76440_q) && !this.func_184218_aH() && p_71059_1_ instanceof LivingEntity;
flag2 = flag2 && !this.func_70051_ag();
@ -252,7 +249,7 @@
}
f = f + f1;
@@ -1059,8 +1120,10 @@
@@ -1059,8 +1119,10 @@
}
if (!this.field_70170_p.field_72995_K && !itemstack1.func_190926_b() && entity instanceof LivingEntity) {
@ -263,7 +260,7 @@
this.func_184611_a(Hand.MAIN_HAND, ItemStack.field_190927_a);
}
}
@@ -1102,7 +1165,7 @@
@@ -1102,7 +1164,7 @@
}
if (this.field_70146_Z.nextFloat() < f) {
@ -272,7 +269,7 @@
this.func_184602_cy();
this.field_70170_p.func_72960_a(this, (byte)30);
}
@@ -1128,8 +1191,9 @@
@@ -1128,8 +1190,9 @@
public void func_71004_bE() {
}
@ -284,7 +281,7 @@
this.field_71069_bz.func_75134_a(this);
if (this.field_71070_bA != null) {
this.field_71070_bA.func_75134_a(this);
@@ -1146,6 +1210,9 @@
@@ -1146,6 +1209,9 @@
}
public Either<PlayerEntity.SleepResult, Unit> func_213819_a(BlockPos p_213819_1_) {
@ -294,7 +291,7 @@
Direction direction = this.field_70170_p.func_180495_p(p_213819_1_).func_177229_b(HorizontalBlock.field_185512_D);
if (!this.field_70170_p.field_72995_K) {
if (this.func_70608_bn() || !this.func_70089_S()) {
@@ -1156,7 +1223,7 @@
@@ -1156,7 +1222,7 @@
return Either.left(PlayerEntity.SleepResult.NOT_POSSIBLE_HERE);
}
@ -303,7 +300,7 @@
return Either.left(PlayerEntity.SleepResult.NOT_POSSIBLE_NOW);
}
@@ -1197,6 +1264,8 @@
@@ -1197,6 +1263,8 @@
private boolean func_190774_a(BlockPos p_190774_1_, Direction p_190774_2_) {
if (Math.abs(this.field_70165_t - (double)p_190774_1_.func_177958_n()) <= 3.0D && Math.abs(this.field_70163_u - (double)p_190774_1_.func_177956_o()) <= 2.0D && Math.abs(this.field_70161_v - (double)p_190774_1_.func_177952_p()) <= 3.0D) {
return true;
@ -312,7 +309,7 @@
} else {
BlockPos blockpos = p_190774_1_.func_177972_a(p_190774_2_.func_176734_d());
return Math.abs(this.field_70165_t - (double)blockpos.func_177958_n()) <= 3.0D && Math.abs(this.field_70163_u - (double)blockpos.func_177956_o()) <= 2.0D && Math.abs(this.field_70161_v - (double)blockpos.func_177952_p()) <= 3.0D;
@@ -1209,6 +1278,7 @@
@@ -1209,6 +1277,7 @@
}
public void func_70999_a(boolean p_70999_1_, boolean p_70999_2_, boolean p_70999_3_) {
@ -320,7 +317,7 @@
Optional<BlockPos> optional = this.func_213374_dv();
super.func_213366_dy();
if (this.field_70170_p instanceof ServerWorld && p_70999_2_) {
@@ -1229,17 +1299,17 @@
@@ -1229,17 +1298,17 @@
}
public static Optional<Vec3d> func_213822_a(IWorldReader p_213822_0_, BlockPos p_213822_1_, boolean p_213822_2_) {
@ -342,7 +339,7 @@
}
}
@@ -1254,23 +1324,67 @@
@@ -1254,23 +1323,67 @@
public void func_146105_b(ITextComponent p_146105_1_, boolean p_146105_2_) {
}
@ -419,7 +416,7 @@
}
public void func_195066_a(ResourceLocation p_195066_1_) {
@@ -1436,6 +1550,8 @@
@@ -1436,6 +1549,8 @@
}
super.func_180430_e(p_180430_1_, p_180430_2_);
@ -428,7 +425,7 @@
}
}
@@ -1703,7 +1819,10 @@
@@ -1703,7 +1818,10 @@
}
public ITextComponent func_145748_c_() {
@ -440,7 +437,7 @@
return this.func_208016_c(itextcomponent);
}
@@ -1939,4 +2058,44 @@
@@ -1939,4 +2057,44 @@
return this.field_221260_g;
}
}

View File

@ -1,14 +1,6 @@
--- a/net/minecraft/network/play/ServerPlayNetHandler.java
+++ b/net/minecraft/network/play/ServerPlayNetHandler.java
@@ -180,6 +180,7 @@
public void func_73660_a() {
this.func_184342_d();
+ if (this.field_147369_b.func_70089_S()) //Don't tick players while they are dead/respawning.
this.field_147369_b.func_71127_g();
this.field_147369_b.func_70080_a(this.field_184349_l, this.field_184350_m, this.field_184351_n, this.field_147369_b.field_70177_z, this.field_147369_b.field_70125_A);
++this.field_147368_e;
@@ -337,9 +338,11 @@
@@ -337,9 +337,11 @@
}
entity.func_70080_a(d3, d4, d5, f, f1);
@ -20,7 +12,7 @@
this.field_147371_a.func_179290_a(new SMoveVehiclePacket(entity));
return;
}
@@ -839,7 +842,9 @@
@@ -839,7 +841,9 @@
Direction direction = blockraytraceresult.func_216354_b();
this.field_147369_b.func_143004_u();
if (blockpos.func_177956_o() < this.field_147367_d.func_71207_Z() - 1 || direction != Direction.UP && blockpos.func_177956_o() < this.field_147367_d.func_71207_Z()) {
@ -31,7 +23,7 @@
this.field_147369_b.field_71134_c.func_219441_a(this.field_147369_b, serverworld, itemstack, hand, blockraytraceresult);
}
} else {
@@ -959,7 +964,9 @@
@@ -959,7 +963,9 @@
if (s.startsWith("/")) {
this.func_147361_d(s);
} else {
@ -42,7 +34,7 @@
this.field_147367_d.func_184103_al().func_148544_a(itextcomponent, false);
}
@@ -1057,6 +1064,7 @@
@@ -1057,6 +1063,7 @@
this.field_147369_b.func_190775_a(entity, hand);
} else if (p_147340_1_.func_149565_c() == CUseEntityPacket.Action.INTERACT_AT) {
Hand hand1 = p_147340_1_.func_186994_b();
@ -50,7 +42,7 @@
entity.func_184199_a(this.field_147369_b, p_147340_1_.func_179712_b(), hand1);
} else if (p_147340_1_.func_149565_c() == CUseEntityPacket.Action.ATTACK) {
if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || entity == this.field_147369_b) {
@@ -1087,7 +1095,7 @@
@@ -1087,7 +1094,7 @@
return;
}
@ -59,7 +51,7 @@
if (this.field_147367_d.func_71199_h()) {
this.field_147369_b.func_71033_a(GameType.SPECTATOR);
this.field_147369_b.func_71121_q().func_82736_K().func_223585_a(GameRules.field_223613_p).func_223570_a(false, this.field_147367_d);
@@ -1264,6 +1272,8 @@
@@ -1264,6 +1271,8 @@
}
public void func_147349_a(CCustomPayloadPacket p_147349_1_) {

View File

@ -156,7 +156,18 @@
try {
OptionSet optionset = optionparser.parse(p_main_0_);
@@ -948,7 +971,7 @@
@@ -887,6 +910,10 @@
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
PlayerProfileCache playerprofilecache = new PlayerProfileCache(gameprofilerepository, new File(s, field_152367_a.getName()));
String s1 = Optional.ofNullable(optionset.valueOf(optionspec9)).orElse(serverpropertiesprovider.func_219034_a().field_219021_o);
+ if (s1 == null || s1.isEmpty() || new File(s, s1).getAbsolutePath().equals(new File(s).getAbsolutePath())) {
+ field_147145_h.error("Invalid world directory specified, must not be null, empty or the same directory as your universe! " + s1);
+ return;
+ }
final DedicatedServer dedicatedserver = new DedicatedServer(new File(s), serverpropertiesprovider, DataFixesManager.func_210901_a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, playerprofilecache, LoggingChunkStatusListener::new, s1);
dedicatedserver.func_71224_l(optionset.valueOf(optionspec7));
dedicatedserver.func_71208_b(optionset.valueOf(optionspec10));
@@ -948,7 +975,7 @@
}
public ServerWorld func_71218_a(DimensionType p_71218_1_) {
@ -165,7 +176,7 @@
}
public Iterable<ServerWorld> func_212370_w() {
@@ -987,7 +1010,7 @@
@@ -987,7 +1014,7 @@
}
public String getServerModName() {
@ -174,7 +185,7 @@
}
public CrashReport func_71230_b(CrashReport p_71230_1_) {
@@ -1529,6 +1552,31 @@
@@ -1529,6 +1556,31 @@
public abstract boolean func_213199_b(GameProfile p_213199_1_);

View File

@ -583,6 +583,10 @@ public class ForgeHooks
ItemStack itemstack = context.getItem();
World world = context.getWorld();
PlayerEntity player = context.getPlayer();
if (player != null && !player.abilities.allowEdit && !itemstack.canPlaceOn(world.getTags(), new CachedBlockInfo(world, context.getPos(), false)))
return ActionResultType.PASS;
// handle all placement events here
int size = itemstack.getCount();
CompoundNBT nbt = null;
@ -596,7 +600,11 @@ public class ForgeHooks
world.captureBlockSnapshots = true;
}
ItemStack copy = itemstack.isDamageable() ? itemstack.copy() : null;
ActionResultType ret = itemstack.getItem().onItemUse(context);
if (itemstack.isEmpty())
ForgeEventFactory.onPlayerDestroyItem(player, copy, context.getHand());
world.captureBlockSnapshots = false;
if (ret == ActionResultType.SUCCESS)
@ -616,7 +624,6 @@ public class ForgeHooks
itemstack.setCount(size);
itemstack.setTag(nbt);
PlayerEntity player = context.getPlayer();
Direction side = context.getFace();
boolean eventResult = false;