Skip to content

Commit

Permalink
fix custom armor effect crash
Browse files Browse the repository at this point in the history
the crash occurred while wearing a mob head and 3 custom armor pieces.
bug fix: catch exception when this event happens and return false
  • Loading branch information
aleganza committed Mar 26, 2023
1 parent 7aea42d commit fe37382
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ private boolean hasFullSuitOfArmorOn(PlayerEntity player) {
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
private boolean doesArmorHaveMaterial(ArmorMaterial material, PlayerEntity player) {
for (int i=0; i<4; i++) {
try{
((ArmorItem)player.getInventory().getArmorStack(i).getItem()).getMaterial();
}catch(Exception e){
return false;
}
}

// elytra bug fix
try{
((ArmorItem)player.getInventory().getArmorStack(2).getItem()).getMaterial();
}catch(Exception e){
return true;
}

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
if (!doesArmorHaveMaterial(material, player)) {
return false;
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmorStack(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmorStack(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmorStack(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmorStack(3).getItem());

Expand Down
Loading

0 comments on commit fe37382

Please sign in to comment.